:root {
  --bg-1: #fff9f1;
  --bg-2: #ffecc7;
  --bg-3: #d8f7ef;
  --ink: #1e2830;
  --muted: #5e6d78;
  --line: rgba(29, 40, 48, 0.14);
  --card: rgba(255, 255, 255, 0.76);
  --card-strong: rgba(255, 255, 255, 0.9);
  --prime: #0fbfa9;
  --prime-2: #10d1b9;
  --warn: #ff8e3d;
  --warn-2: #ff6d5f;
  --shadow: 0 18px 44px rgba(32, 50, 55, 0.18);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Manrope", "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 500px at -8% -10%, rgba(255, 143, 58, 0.22), transparent 70%),
    radial-gradient(1000px 620px at 108% 2%, rgba(15, 191, 169, 0.24), transparent 68%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2) 45%, var(--bg-3));
  background-attachment: fixed;
}

body.party-mode {
  animation: party-bg 8s ease-in-out infinite alternate;
}

.v2-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.4) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.4) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at 50% 35%, #000 35%, transparent 82%);
}

a {
  color: inherit;
  text-decoration: none;
}

h1, h2, h3 {
  margin: 0;
  font-family: "Archivo", "Trebuchet MS", sans-serif;
  letter-spacing: 0.01em;
}

.kicker {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.subtitle {
  margin: 10px 0 0;
  color: #3b4a55;
  font-size: 17px;
}

.v2-topbar {
  width: min(1280px, 94vw);
  margin: 18px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.title-wrap,
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.v2-chip {
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
}

.v2-chip.ghost {
  background: rgba(255, 255, 255, 0.58);
}

.v2-home-shell {
  width: min(1280px, 94vw);
  margin: 12px auto 36px;
  display: grid;
  gap: 12px;
}

.v2-layout {
  width: min(1280px, 94vw);
  margin: 12px auto 36px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.random-center-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.random-center-btn {
  min-width: min(440px, 86vw);
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(140deg, var(--card), var(--card-strong));
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  padding: 14px;
  animation: fade-rise 0.45s ease both;
}

.v2-hero {
  padding: clamp(16px, 2.8vw, 30px);
}

.v2-hero h1 {
  margin-top: 6px;
  font-size: clamp(38px, 7vw, 78px);
  line-height: 0.95;
}

.create-row {
  margin-top: 18px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1.4fr 1fr auto;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.section-head h2 {
  font-size: clamp(20px, 3vw, 30px);
}

.cards-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.inline-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.inline-controls label {
  color: var(--muted);
  font-size: 12px;
}

.theme-hint {
  margin: 8px 0 0;
  color: #35505f;
  font-size: 13px;
  line-height: 1.35;
}

.muted-line {
  margin: 8px 0 0;
  color: #5f6f79;
  font-size: 12px;
}

.theme-cloud {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  color: #2a3942;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.2s ease;
}

.theme-chip:hover {
  transform: translateY(-1px);
}

.theme-chip.active {
  background: linear-gradient(130deg, rgba(15, 191, 169, 0.22), rgba(16, 209, 185, 0.38));
  border-color: rgba(15, 191, 169, 0.45);
}

.grid-2 {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-2 h3,
.grid-3 h3 {
  margin-bottom: 6px;
}

.grid-3 {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.save-row {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.save-row input {
  flex: 1;
}

input[type="text"],
input[type="number"],
select,
textarea {
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.88);
  padding: 10px 12px;
  font-family: inherit;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
}

.editor {
  font-size: 18px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(15, 191, 169, 0.65);
  box-shadow: 0 0 0 4px rgba(15, 191, 169, 0.16);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 14px;
  font-family: "Archivo", "Trebuchet MS", sans-serif;
  font-weight: 700;
  transition: transform 0.14s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn.prime {
  color: #04231f;
  background: linear-gradient(130deg, var(--prime), var(--prime-2));
  box-shadow: 0 10px 20px rgba(15, 191, 169, 0.25);
}

.btn.warn {
  color: #3a1703;
  background: linear-gradient(130deg, var(--warn), var(--warn-2));
  box-shadow: 0 10px 20px rgba(255, 142, 61, 0.28);
}

.btn.joker {
  color: #11202a;
  background: linear-gradient(130deg, #9ad4ff, #75b7f0);
  box-shadow: 0 10px 20px rgba(80, 130, 196, 0.25);
}

.btn.soft {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  border-color: var(--line);
}

.btn.block {
  width: 100%;
}

.wheel-panel {
  display: grid;
  gap: 10px;
  align-content: start;
}

.wheel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wheel-head h2 {
  font-size: clamp(22px, 2.6vw, 30px);
}

.wheel-frame {
  position: relative;
  border-radius: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.9));
}

.wheel-frame.good {
  background: linear-gradient(160deg, rgba(16, 209, 185, 0.16), rgba(255, 255, 255, 0.92));
}

.wheel-frame.challenge {
  background: linear-gradient(160deg, rgba(255, 142, 61, 0.18), rgba(255, 255, 255, 0.92));
}

.wheel-frame.joker {
  background: linear-gradient(160deg, rgba(117, 183, 240, 0.18), rgba(255, 255, 255, 0.92));
}

.wheel-frame canvas {
  width: min(100%, 520px);
  aspect-ratio: 1 / 1;
  display: block;
  margin: 0 auto;
}

.pointer {
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 24px solid #15232c;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.2));
  z-index: 3;
}

.result-panel h2 {
  font-size: clamp(22px, 2.8vw, 30px);
}

.result-box {
  min-height: 110px;
  border-radius: 14px;
  border: 1px dashed rgba(29, 40, 48, 0.25);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.56), rgba(255, 255, 255, 0.88));
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(19px, 2.3vw, 26px);
  padding: 12px;
}

.result-explain {
  margin-top: 8px;
  border-radius: 12px;
  border: 1px solid rgba(29, 40, 48, 0.12);
  background: rgba(255, 255, 255, 0.74);
  color: #304550;
  font-size: clamp(13px, 1.5vw, 15px);
  line-height: 1.35;
  padding: 9px 10px;
}

.stats-board {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  border: 1px solid rgba(29, 40, 48, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  padding: 7px 8px;
  display: grid;
  gap: 4px;
}

.stat span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat strong {
  font-size: 19px;
  font-family: "Archivo", "Trebuchet MS", sans-serif;
  line-height: 1;
}

.combo-wrap {
  margin-top: 10px;
  display: grid;
  gap: 5px;
}

.combo-wrap span {
  font-size: 12px;
  color: #3f515d;
}

.combo-bar {
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(29, 40, 48, 0.14);
  background: rgba(255, 255, 255, 0.76);
  overflow: hidden;
}

#comboFill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(130deg, #ffd05f, #ff9648, #ff5d68);
  transition: width 0.28s ease;
}

.history {
  margin-top: 10px;
  max-height: 470px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.history-row {
  padding: 8px 9px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(29, 40, 48, 0.1);
  font-size: 13px;
}

.history-row strong {
  font-family: "Archivo", "Trebuchet MS", sans-serif;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 14px;
  top: -18px;
  border-radius: 2px;
  opacity: 0.94;
  animation: confetti-fall linear forwards;
}

.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(29, 40, 48, 0.16);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  color: #24333d;
  font-size: 13px;
  animation: toast-in 0.26s ease both;
}

.toast.good {
  background: rgba(220, 255, 247, 0.96);
}

.toast.challenges {
  background: rgba(255, 236, 214, 0.96);
}

.toast.joker {
  background: rgba(226, 241, 255, 0.96);
}

.hidden {
  display: none !important;
}

dialog {
  border: none;
  background: none;
}

dialog::backdrop {
  background: rgba(36, 51, 57, 0.42);
  backdrop-filter: blur(2px);
}

.dialog-form {
  width: min(980px, 94vw);
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 14px;
  box-shadow: var(--shadow);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.95));
}

.dialog-form h3 {
  font-size: clamp(21px, 2.4vw, 28px);
  margin-bottom: 10px;
}

.dialog-form label {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.dialog-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.js-error {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  color: #fff;
  background: rgba(22, 28, 32, 0.86);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

@keyframes fade-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes confetti-fall {
  from {
    transform: translateY(0) rotate(0deg);
  }
  to {
    transform: translateY(112vh) rotate(900deg);
    opacity: 0.86;
  }
}

@keyframes party-bg {
  0% {
    filter: hue-rotate(0deg) saturate(1);
  }
  100% {
    filter: hue-rotate(22deg) saturate(1.08);
  }
}

@media (max-width: 1180px) {
  .v2-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .create-row {
    grid-template-columns: 1fr;
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }

  .stats-board {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .v2-home-shell,
  .v2-layout,
  .v2-topbar {
    width: 96vw;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar select,
  .toolbar .btn {
    width: 100%;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }

  .save-row {
    flex-direction: column;
  }

  .v2-layout {
    grid-template-columns: 1fr;
  }

  .stats-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast-stack {
    top: auto;
    bottom: 14px;
    right: 10px;
    left: 10px;
  }
}
