:root {
  --bg1:#7dd3fc;
  --bg2:#c4b5fd;
  --card:rgba(255,255,255,.95);
  --txt:#1f2937;
  --primary:#ff7b54;
  --secondary:#22c55e;
  --warning:#f59e0b;
  --danger:#ef4444;
  --accent:#7c3aed;
  --shadow:0 12px 30px rgba(0,0,0,.12);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Comic Sans MS","Trebuchet MS",system-ui,sans-serif;
  color: var(--txt);
  background:
    radial-gradient(circle at top left, rgba(255,255,255,.45), transparent 30%),
    radial-gradient(circle at bottom right, rgba(255,255,255,.35), transparent 25%),
    linear-gradient(135deg, var(--bg1), var(--bg2));
}

.app {
  height: 100dvh;
  padding: 10px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  max-width: 1366px;
  margin: 0 auto;
}

.topbar, .scorebar, .bottombar, .panel-wrap, .modal .content {
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.topbar {
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.header-shell {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.titlebox {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title {
  font-size: clamp(1.4rem, 2.2vw, 2rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,.12);
}

.subtitle {
  font-size: .98rem;
  color: #ffffffd9;
  font-weight: 800;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 16px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 900;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(0,0,0,.1);
}

.btn:active {
  transform: translateY(1px);
}

.primary { background: var(--primary); color: #fff; }
.secondary { background: var(--secondary); color: #fff; }
.warning { background: var(--warning); color: #fff; }
.ghost { background: #fff; color: #374151; }

.scorebar {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 10px;
  padding: 10px;
}

.pill {
  background: #fff;
  border-radius: 18px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 900;
  min-height: 64px;
  text-align: center;
}

.player.active {
  outline: 4px solid #93c5fd;
  background: #eff6ff;
}

.player small {
  display: block;
  color: #6b7280;
  font-size: .8rem;
}

.player .tag {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #ede9fe;
  color: #6d28d9;
  font-size: .72rem;
  font-weight: 900;
}

.panel-wrap {
  position: relative;
  padding: 18px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.panel-area {
  width: 100%;
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
}

.category {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--accent);
  background: #f3e8ff;
  padding: 8px 16px;
  border-radius: 999px;
}

.board {
  display: grid;
  gap: 12px;
  justify-items: center;
  width: min(1100px, 98%);
}

.board-line {
  display: flex;
  justify-content: center;
  gap: 10px 12px;
  width: 100%;
  flex-wrap: nowrap;
}

.tile {
  width: clamp(44px, 4.8vw, 64px);
  height: clamp(58px, 6.4vw, 82px);
  border-radius: 14px;
  background: linear-gradient(180deg,#fff7ed,#ffedd5);
  border-bottom: 5px solid #fdba74;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.9rem, 3vw, 3rem);
  font-weight: 900;
  color: #1f2937;
  text-transform: uppercase;
}

.tile.space {
  visibility: hidden;
  width: 18px;
  background: transparent;
  border: 0;
}

.hintline {
  font-size: 1rem;
  color: #6b7280;
  font-weight: 800;
}

.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}

.turninfo {
  font-weight: 900;
  font-size: 1.1rem;
}

.bank {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.bank .pill {
  min-height: auto;
  padding: 10px 14px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}

.modal.open {
  display: flex;
}

.modal .content {
  width: min(960px, 96vw);
  max-height: 92dvh;
  overflow: auto;
  padding: 18px;
}

.modal h2 {
  margin: 0 0 10px;
  font-size: 1.5rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2,1fr);
  gap: 14px;
}

.panel {
  background: #fff;
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 8px 18px rgba(0,0,0,.06);
}

.panel h3 {
  margin: 0 0 10px;
}

input, select, textarea {
  width: 100%;
  border: 3px solid #dbeafe;
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  font-family: inherit;
}

textarea {
  min-height: 150px;
  resize: vertical;
}

.listnote {
  color: #6b7280;
  font-weight: 700;
  font-size: .95rem;
}

.section-label {
  margin-top: 10px;
}

.top-gap {
  margin-top: 10px;
  display: inline-block;
}

.player-names-wrap {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.actions.center {
  justify-content: center;
}

.wheel-wrap {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 18px;
  align-items: center;
}

.wheel-box {
  display: grid;
  place-items: center;
}

#wheelCanvas {
  width: min(72vw, 620px);
  height: min(72vw, 620px);
  max-width: 620px;
  max-height: 620px;
  touch-action: none;
  filter: drop-shadow(0 18px 22px rgba(0,0,0,.18));
}

.pointer {
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 34px solid #ef4444;
  margin: 0 auto 8px;
}

.spin-help {
  text-align: center;
  font-weight: 800;
  color: #6b7280;
}

.wheel-side {
  display: grid;
  gap: 12px;
}

.result-box {
  background: #f8fafc;
  border-radius: 18px;
  padding: 14px;
  text-align: center;
}

.result-label {
  font-weight: 900;
  color: #6b7280;
}

.result-value {
  font-size: 2rem;
  font-weight: 900;
  color: var(--accent);
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: 10px;
  margin-top: 12px;
}

.letter-panel-preview {
  display: grid;
  gap: 10px;
  justify-items: center;
  margin: 8px 0 14px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 18px;
  border: 2px dashed #cbd5e1;
  min-height: 74px;
}

.letter-preview-tile {
  width: 42px;
  height: 56px;
  border-radius: 12px;
  background: linear-gradient(180deg,#fff7ed,#ffedd5);
  border-bottom: 4px solid #fdba74;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  text-transform: uppercase;
  color: #1f2937;
}

.letter-preview-tile.space {
  visibility: hidden;
  width: 16px;
  background: transparent;
  border: 0;
}

.key {
  height: 64px;
  border: none;
  border-radius: 16px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 1.5rem;
  font-weight: 900;
  font-family: inherit;
  cursor: pointer;
}

.key.used {
  background: #e5e7eb;
  color: #9ca3af;
}

.key.vowel {
  background: #fde68a;
  color: #92400e;
}

.solved-content,
.final-content {
  max-width: 760px;
  text-align: center;
}

.solved-box,
.winner-box {
  background: #f8fafc;
  border-radius: 20px;
  padding: 18px;
  margin-top: 12px;
}

.solved-small,
.winner-small {
  font-size: 1.05rem;
  color: #6b7280;
  font-weight: 800;
}

.solved-text {
  font-size: 2rem;
  font-weight: 900;
  color: #7c3aed;
  margin-top: 10px;
  line-height: 1.2;
}

.solved-by {
  font-size: 1.1rem;
  font-weight: 900;
  margin-top: 12px;
}

.winner-name {
  font-size: 2.1rem;
  font-weight: 900;
  color: #7c3aed;
  margin-top: 8px;
}

.winner-score {
  font-size: 1.3rem;
  font-weight: 900;
  margin-top: 6px;
}

.ranking-box {
  margin-top: 16px;
  text-align: left;
}

.turn-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,23,42,.22);
  backdrop-filter: blur(2px);
  z-index: 120;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.turn-overlay.show {
  opacity: 1;
}

.turn-overlay-card {
  background: linear-gradient(180deg,#fff1f2,#ffe4e6);
  border: 6px solid #fb7185;
  color: #9f1239;
  border-radius: 30px;
  padding: 28px 34px;
  box-shadow: 0 20px 40px rgba(0,0,0,.18);
  text-align: center;
  transform: scale(.82) rotate(-4deg);
  animation: turnPop .9s ease forwards;
}

.turn-overlay-title {
  font-size: clamp(2rem, 4vw, 3.4rem);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.turn-overlay-sub {
  margin-top: 10px;
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 900;
}

@keyframes turnPop {
  0% { transform: scale(.7) rotate(-6deg) }
  20% { transform: scale(1.08) rotate(2deg) }
  45% { transform: scale(.98) rotate(-1deg) }
  100% { transform: scale(1) rotate(0deg) }
}

.player.turn-lost {
  animation: shakeTurn .55s ease;
}

@keyframes shakeTurn {
  0%,100% { transform: translateX(0) }
  20% { transform: translateX(-8px) }
  40% { transform: translateX(8px) }
  60% { transform: translateX(-6px) }
  80% { transform: translateX(6px) }
}

@media (max-width:1024px) {
  .app {
    padding: 8px;
    gap: 8px;
  }

  .scorebar {
    grid-template-columns: repeat(2,1fr);
  }

  .wheel-wrap {
    grid-template-columns: 1fr;
  }
}

@media (max-width:820px) {
  .setup-grid {
    grid-template-columns: 1fr;
  }

  .keyboard {
    grid-template-columns: repeat(5,1fr);
  }

  .bottombar {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width:820px) {
  html, body {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app {
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto auto auto auto;
    padding: 6px;
    gap: 6px;
  }

  .header-shell {
    flex-direction: column;
    align-items: stretch;
  }

  .titlebox {
    text-align: center;
  }

  .title {
    font-size: 1.35rem;
  }

  .subtitle {
    font-size: .9rem;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(2,1fr);
    gap: 8px;
  }

  .btn {
    width: 100%;
    padding: 10px 12px;
    font-size: .95rem;
  }

  .scorebar {
    grid-template-columns: repeat(2,1fr);
    gap: 8px;
    padding: 8px;
  }

  .pill {
    min-height: 52px;
    padding: 8px 10px;
    font-size: .9rem;
  }

  .player small {
    font-size: .72rem;
  }

  .panel-wrap {
    padding: 10px 6px;
    overflow: visible;
  }

  .panel-area {
    gap: 10px;
  }

  .category,
  .hintline,
  .turninfo {
    font-size: .9rem;
    text-align: center;
  }

  .board {
    width: 100%;
    gap: 8px;
  }

  .board-line {
    gap: 4px;
  }

  .tile {
    width: clamp(22px, 6.2vw, 34px);
    height: clamp(32px, 8vw, 46px);
    border-radius: 8px;
    border-bottom-width: 3px;
    font-size: clamp(1rem, 4.8vw, 1.5rem);
  }

  .tile.space {
    width: 8px;
  }

  .bottombar {
    padding: 8px 10px;
  }

  .bank {
    justify-content: center;
  }

  .keyboard {
    grid-template-columns: repeat(4,1fr);
    gap: 8px;
  }

  .key {
    height: 52px;
    font-size: 1.2rem;
    border-radius: 12px;
  }

  .wheel-wrap {
    gap: 12px;
  }

  #wheelCanvas {
    width: min(88vw, 420px);
    height: min(88vw, 420px);
  }

  .pointer {
    border-left: 14px solid transparent;
    border-right: 14px solid transparent;
    border-top: 24px solid #ef4444;
  }

  .result-value {
    font-size: 1.5rem;
  }

  .modal {
    padding: 10px;
  }

  .modal .content {
    width: 100%;
    max-height: 95dvh;
    padding: 14px;
  }

  .solved-text {
    font-size: 1.4rem;
  }

  .winner-name {
    font-size: 1.6rem;
  }

  .winner-score {
    font-size: 1.1rem;
  }
}

.mobile-info-btn {
  display: none;
}

@media (max-width: 820px) {
  html, body {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app {
    min-height: 100dvh;
    height: auto;
    padding: 6px;
    gap: 6px;
    grid-template-rows: auto auto 1fr auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .header-shell {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: stretch;
  }

  .titlebox {
    text-align: center;
  }

  .title {
    font-size: 1.2rem;
  }

  .subtitle {
    display: none;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }

  .btn {
    min-width: 0;
    width: 100%;
    padding: 10px 6px;
    font-size: 1.1rem;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
  }

  .btn .btn-label {
    display: none;
  }

  .mobile-info-btn {
    display: flex;
  }

  .scorebar {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px;
  }

  .scorebar.open {
    display: grid;
  }

  .pill {
    min-height: 48px;
    padding: 8px 10px;
    font-size: .88rem;
  }

  .panel-wrap {
    overflow: visible;
    padding: 8px 4px;
    min-height: 34dvh;
  }

  .panel-area {
    gap: 8px;
  }

  .category {
    font-size: .9rem;
    padding: 6px 12px;
  }

  .board {
    width: 100%;
    gap: 6px;
  }

  .board-line {
    gap: 3px;
  }

  .tile {
    width: clamp(20px, 5.8vw, 30px);
    height: clamp(30px, 8.2vw, 40px);
    font-size: clamp(.9rem, 4.2vw, 1.25rem);
    border-radius: 8px;
    border-bottom-width: 3px;
  }

  .tile.space {
    width: 6px;
  }

  .hintline {
    font-size: .85rem;
    text-align: center;
  }

  .bottombar {
    padding: 8px;
    gap: 8px;
    flex-direction: column;
    align-items: stretch;
  }

  .turninfo {
    text-align: center;
    font-size: .95rem;
  }

  .bank {
    justify-content: center;
    gap: 8px;
  }

  .player {
    width: 100%;
  }

  .player small {
    font-size: .72rem;
  }

  .player .tag {
    font-size: .68rem;
  }

  .keyboard {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .key {
    height: 52px;
    font-size: 1.15rem;
    border-radius: 12px;
  }

  #wheelCanvas {
    width: min(86vw, 360px);
    height: min(86vw, 360px);
  }
}