:root {
  --bg: #0c101f;
  --top-a: #642b73;
  --top-b: #44235c;
  --bottom-a: #1f6575;
  --bottom-b: #114c56;
  --divider: #0c1120;
  --text: #f4f7ff;
  --muted: #d3def5;
  --cell-bg: rgba(255, 255, 255, 0.93);
  --cell-fg: #1f2937;
  --p1: #f97316;
  --p2: #3b82f6;
  --blocked: #96a3b8;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 20% 0%, #27386f, var(--bg) 60%);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
}

.panel {
  position: relative;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.14), transparent 58%);
}

.panel-top {
  background: linear-gradient(145deg, var(--top-a), var(--top-b));
}

.panel-bottom {
  background: linear-gradient(220deg, var(--bottom-a), var(--bottom-b));
}

.panel.is-active {
  box-shadow: inset 0 0 0 2px rgba(250, 204, 21, 0.5);
}

.panel-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}

.rotated {
  transform: rotate(180deg);
  transform-origin: center;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.score {
  font-size: clamp(0.9rem, 2.8vw, 1.1rem);
  font-weight: 900;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.32);
}

.board-wrap {
  position: relative;
  min-height: 0;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  margin: 0 auto;
  container-type: inline-size;
}

.letter-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.cell {
  border: 1px solid rgba(30, 41, 59, 0.18);
  border-radius: 10px;
  background: var(--cell-bg);
  color: var(--cell-fg);
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  line-height: 1;
  font-size: clamp(0.62rem, 2.2vw, 1.45rem);
  font-size: clamp(0.55rem, 12cqw, 1.45rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  box-shadow: 0 3px 8px rgba(2, 6, 23, 0.16);
}

.cell.is-traced {
  background: #fef3c7;
}

.line-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.word-line {
  position: absolute;
  left: 0;
  top: 0;
  height: 8px;
  border-radius: 999px;
  transform-origin: 0 50%;
  opacity: 0.76;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.32);
}

.word-line.p1 {
  background: linear-gradient(90deg, #fb923c, #f97316);
}

.word-line.p2 {
  background: linear-gradient(90deg, #60a5fa, #2563eb);
}

.word-line.blocked {
  background: linear-gradient(90deg, #9ca3af, #6b7280);
  opacity: 0.62;
}

.word-line.trace {
  opacity: 0.86;
}

.word-line.trace.p1 {
  background: rgba(251, 146, 60, 0.8);
}

.word-line.trace.p2 {
  background: rgba(96, 165, 250, 0.8);
}

.word-line.trace.invalid {
  background: rgba(248, 113, 113, 0.74);
}

.words-wrap {
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.3);
  padding: 6px;
}

.words-title {
  margin: 0 0 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
  color: #c7d6f8;
}

.words-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.word-chip {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.42);
  background: rgba(15, 23, 42, 0.58);
  color: #e2e8f0;
  padding: 2px 8px;
  font-size: clamp(0.63rem, 2.4vw, 0.8rem);
  font-weight: 800;
}

.word-chip.claimed-p1 {
  border-color: rgba(249, 115, 22, 0.8);
  color: #ffedd5;
  background: rgba(194, 65, 12, 0.58);
}

.word-chip.claimed-p2 {
  border-color: rgba(59, 130, 246, 0.8);
  color: #dbeafe;
  background: rgba(30, 64, 175, 0.58);
}

.word-chip.claimed-opponent {
  border-color: rgba(156, 163, 175, 0.7);
  color: #e5e7eb;
  background: rgba(75, 85, 99, 0.56);
}

.divider {
  border-top: 1px solid rgba(148, 163, 184, 0.35);
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  background: var(--divider);
  padding: 8px 12px;
  display: grid;
  gap: 6px;
}

.divider-main {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.game-title {
  margin: 0;
  padding: 0 8px 0 0;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.88rem;
}

.control-link,
.control-btn {
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.42);
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 0.74rem;
  padding: 5px 10px;
}

.control-btn {
  cursor: pointer;
}

.status-text {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  min-height: 1.1em;
  font-weight: 700;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 20;
}

.overlay-card {
  width: min(88vw, 360px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 16px;
  background: linear-gradient(170deg, #0f172a, #1e293b);
  text-align: center;
  padding: 18px 16px;
}

.overlay-card h2 {
  margin-top: 0;
  margin-bottom: 10px;
}

.overlay-card p {
  margin-top: 0;
  margin-bottom: 16px;
  color: var(--muted);
}

.overlay-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.play-again {
  border: 0;
  border-radius: 12px;
  background: linear-gradient(120deg, #f59e0b, #f97316);
  color: white;
  min-height: 44px;
  min-width: 160px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

.overlay-home {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  text-decoration: none;
  min-height: 44px;
  min-width: 110px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
}

.hidden {
  display: none;
}

@media (max-height: 760px) {
  .word-line {
    height: 6px;
  }

  .panel-inner {
    gap: 6px;
  }

  .words-wrap {
    padding: 4px;
  }
}
