/* T3 — styles follow the Tenomtu look shared with Gelongsor Puzzle: starry
   navy in dark mode, airy blue in light mode, bold type, one accent colour.
   X takes the accent blue and O a warm peach so the two marks never mix up. */

:root {
  --font-scale: 1;
  --color-card: #10263a;
  --color-input: #091c2c;
  --color-text: #f7f9fc;
  --color-muted: #c3d0dc;
  --color-soft: #91a7bb;
  --color-line: #ffffff29;
  --color-accent: #65cef5;
  --color-accent-text: #061521;
  --color-board: #061321;
  --color-cell: #10263a;
  --color-x: #65cef5;
  --color-o: #ff9f6b;
  --color-warning: #ffb08a;
  font-family: Arial, 'Segoe UI', sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color-scheme: dark;
}

html[data-theme='light'] {
  --color-card: #ffffff;
  --color-input: #f7fafc;
  --color-text: #10283b;
  --color-muted: #425a6e;
  --color-soft: #627a8d;
  --color-line: #18374d30;
  --color-accent: #0679a8;
  --color-accent-text: #ffffff;
  --color-board: #d3e1eb;
  --color-cell: #ffffff;
  --color-x: #0679a8;
  --color-o: #c4511d;
  --color-warning: #b35327;
  color-scheme: light;
}

html[data-font-size='large'] {
  --font-scale: 1.1;
}

html[data-font-size='larger'] {
  --font-scale: 1.2;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background-color: #07111f;
  background-image:
    radial-gradient(circle at 8% 17%, #ffffffb8 0 1px, transparent 1.7px),
    radial-gradient(circle at 17% 61%, #bde8ffad 0 1px, transparent 1.8px),
    radial-gradient(circle at 29% 33%, #ffffff9c 0 1px, transparent 1.7px),
    radial-gradient(circle at 43% 12%, #d7edffad 0 1px, transparent 1.8px),
    radial-gradient(circle at 57% 47%, #ffffffa6 0 1px, transparent 1.8px),
    radial-gradient(circle at 69% 22%, #bde8ffad 0 1px, transparent 1.8px),
    radial-gradient(circle at 82% 66%, #ffffffa6 0 1px, transparent 1.8px),
    radial-gradient(circle at 94% 31%, #d7edffad 0 1px, transparent 1.8px),
    radial-gradient(ellipse at 14% 0%, #24558a80, transparent 45%),
    radial-gradient(ellipse at 92% 38%, #38387870, transparent 42%),
    linear-gradient(155deg, #081526 0%, #101b38 52%, #071522 100%);
  background-attachment: fixed;
  color: var(--color-text);
}

html[data-theme='light'] body {
  background-color: #e9f5fc;
  background-image:
    radial-gradient(ellipse at 88% 4%, #ffe6a9c9 0%, #ffe6a960 12%, transparent 32%),
    radial-gradient(ellipse at 4% 48%, #b5e5e9a1, transparent 42%),
    radial-gradient(ellipse at 92% 78%, #cbdcf9a6, transparent 40%),
    linear-gradient(145deg, #f8fbff 0%, #e8f4fa 48%, #eaf1fb 100%);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

::selection {
  color: #061423;
  background: #41c5f5;
}

/* ------------------------------------------------------------ chrome */

.page-shell {
  display: flex;
  width: min(100% - 40px, 1120px);
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  margin: 0 auto;
}

.topbar {
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--color-line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-text);
  font-size: calc(24px * var(--font-scale));
  font-weight: 800;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.brand img {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 9px;
}

.topbar-actions,
.language-toggle,
.font-size-control {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 14px;
}

.font-size-control {
  gap: 2px;
}

.font-size-control button,
.language-toggle button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  font-weight: 800;
}

.font-size-control button {
  min-width: 32px;
  padding: 5px;
}

.font-size-option--small {
  font-size: 10px;
}

.font-size-option--medium {
  font-size: 13px;
}

.font-size-option--large {
  font-size: 16px;
}

.language-toggle {
  gap: 5px;
}

.language-toggle button {
  min-width: 46px;
  padding: 8px;
  font-size: calc(14px * var(--font-scale));
}

.theme-toggle {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--color-line);
  border-radius: 50%;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
}

.theme-toggle svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

html[data-theme='dark'] .icon-moon,
html[data-theme='light'] .icon-sun {
  display: none;
}

.theme-toggle:hover,
.font-size-control button:hover,
.font-size-control button[aria-pressed='true'],
.language-toggle button:hover,
.language-toggle button[aria-pressed='true'] {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.page-footer {
  display: flex;
  min-height: 64px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 0;
  border-top: 1px solid var(--color-line);
  color: var(--color-muted);
  font-size: calc(15px * var(--font-scale));
  font-weight: 600;
  text-align: center;
}

.page-footer a {
  color: var(--color-accent);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* -------------------------------------------------------------- card */

.play-layout {
  display: grid;
  flex: 1;
  justify-items: center;
  align-content: start;
  padding: 22px 0 32px;
}

.game-card {
  width: min(100%, 560px);
  padding: clamp(18px, 4vw, 34px);
  border: 1px solid var(--color-line);
  border-radius: 12px;
  background: var(--color-card);
}

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

.mode-toggle button {
  display: flex;
  min-width: 0;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  border: 2px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-input);
  color: var(--color-muted);
  cursor: pointer;
  font-size: calc(17px * var(--font-scale));
  font-weight: 900;
}

.mode-toggle svg {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.mode-toggle button:hover {
  border-color: var(--color-accent);
}

.mode-toggle button[aria-pressed='true'] {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-accent-text);
}

.setting {
  min-height: 84px;
  margin-top: 14px;
}

.level-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.field-label {
  margin: 0;
  color: var(--color-text);
  font-size: calc(15px * var(--font-scale));
  font-weight: 900;
}

.select-wrap select {
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  border: 2px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-input);
  color: var(--color-text);
  cursor: pointer;
  font-size: calc(17px * var(--font-scale));
  font-weight: 700;
}

.select-wrap select:focus {
  border-color: var(--color-accent);
  outline: 3px solid color-mix(in srgb, var(--color-accent) 30%, transparent);
  outline-offset: 2px;
}

.select-wrap option {
  background: var(--color-card);
  color: var(--color-text);
}

.setting-note {
  margin: 8px 0 0;
  color: var(--color-muted);
  font-size: calc(15px * var(--font-scale));
  font-weight: 600;
  line-height: 1.4;
}

.setting-note--solo {
  display: flex;
  min-height: 76px;
  align-items: center;
  margin: 0;
  padding: 0 4px;
}

/* ------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 4px 0 16px;
  border-top: 1px solid var(--color-line);
  border-bottom: 1px solid var(--color-line);
}

.stat {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 6px 10px;
  text-align: center;
  transition: box-shadow 0.2s;
}

.stat + .stat {
  border-left: 1px solid var(--color-line);
}

.stat-label {
  display: flex;
  max-width: 100%;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  color: var(--color-soft);
  font-size: calc(13px * var(--font-scale));
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.stat-label > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.mark-icon svg {
  display: block;
  width: 15px;
  height: 15px;
}

.stat-value {
  color: var(--color-text);
  font-family: Consolas, 'Courier New', monospace;
  font-size: calc(26px * var(--font-scale));
  font-weight: 900;
  line-height: 1.15;
}

.stat--x.is-turn {
  box-shadow: inset 0 -4px 0 var(--color-x);
}

.stat--o.is-turn {
  box-shadow: inset 0 -4px 0 var(--color-o);
}

.stat.is-winner .stat-value {
  animation: bump 0.6s ease;
}

/* ------------------------------------------------------------- board */

.board {
  position: relative;
  display: grid;
  width: min(100%, 520px, max(250px, calc(100dvh - 400px)));
  aspect-ratio: 1;
  margin: 0 auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: var(--color-board);
  box-shadow: 0 0 0 1px var(--color-line);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  display: grid;
  min-width: 0;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--color-cell);
  box-shadow: inset 0 0 0 1px var(--color-line);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s;
}

.cell svg {
  width: 70%;
  height: 70%;
  overflow: visible;
}

.cell:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
}

.board.is-playable .cell:not(.is-taken):hover {
  background: color-mix(in srgb, var(--color-accent) 10%, var(--color-cell));
}

.cell.is-taken,
.board.is-locked .cell {
  cursor: default;
}

.board.is-over .cell {
  cursor: pointer;
}

.mark-x {
  color: var(--color-x);
}

.mark-o {
  color: var(--color-o);
}

.mark line,
.mark circle {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 13;
  stroke-dasharray: 1 1;
}

.mark-icon .mark line,
.mark-icon .mark circle,
.status-title .mark line,
.status-title .mark circle {
  stroke-width: 16;
}

.cell .mark.is-new line,
.cell .mark.is-new circle {
  animation: ink 0.22s ease-out backwards;
}

.cell .mark.is-new line + line {
  animation-delay: 0.12s;
}

.mark.is-ghost {
  opacity: 0;
  transition: opacity 0.15s;
}

@media (hover: hover) {
  .board.is-playable .cell:hover .mark.is-ghost {
    opacity: 0.22;
  }
}

.board.is-over .cell:not(.is-win) .mark {
  opacity: 0.35;
  transition: opacity 0.3s;
}

.cell.is-win {
  background: color-mix(in srgb, var(--color-win, var(--color-accent)) 16%, var(--color-cell));
}

.board.win-x {
  --color-win: var(--color-x);
}

.board.win-o {
  --color-win: var(--color-o);
}

.win-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  opacity: 0;
  pointer-events: none;
}

.win-line.is-shown {
  opacity: 1;
}

.win-line line {
  fill: none;
  stroke-linecap: round;
  stroke-dasharray: 1 1;
}

.win-line-edge {
  stroke: var(--color-board);
}

.win-line-ink {
  stroke: var(--color-win, var(--color-accent));
}

.win-line.is-shown line {
  animation: ink 0.4s 0.1s ease-out backwards;
}

/* ------------------------------------------------------------ status */

.status {
  min-height: 74px;
  margin-top: 14px;
  text-align: center;
}

.status-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  font-size: calc(clamp(24px, 5vw, 30px) * var(--font-scale));
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1.15;
}

.status-title .mark {
  width: 0.95em;
  height: 0.95em;
  flex: none;
  overflow: visible;
}

.status-note {
  min-height: 1.45em;
  margin: 6px 0 0;
  color: var(--color-muted);
  font-size: calc(16px * var(--font-scale));
  font-weight: 600;
  line-height: 1.45;
}

.status-note.is-praise {
  color: var(--color-accent);
  font-weight: 800;
}

/* ---------------------------------------------------------- controls */

.play-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.control-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border: 1px solid var(--color-line);
  border-radius: 999px;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  font-size: calc(15px * var(--font-scale));
  font-weight: 800;
}

.control-button svg {
  width: 19px;
  height: 19px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.control-button:hover:not(:disabled) {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.control-button.is-ready {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-accent-text);
}


.control-button:disabled {
  cursor: default;
  opacity: 0.5;
}

.play-hint {
  margin: 14px 0 0;
  color: var(--color-soft);
  font-size: calc(14px * var(--font-scale));
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
}

.text-button {
  display: block;
  min-height: 44px;
  margin: 6px auto 0;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  font-size: calc(15px * var(--font-scale));
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-button:hover {
  color: var(--color-accent);
}

.text-button.is-warning {
  color: var(--color-warning);
}

.storage-warning {
  margin: 10px 0 0;
  color: var(--color-warning);
  font-size: calc(15px * var(--font-scale));
  font-weight: 700;
  text-align: center;
}

@keyframes ink {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes bump {
  40% {
    transform: scale(1.3);
  }
}

/* -------------------------------------------------------- responsive */

/* Wide screens: board on the left, everything else in a side column. */
@media (min-width: 980px) {
  .play-card {
    display: grid;
    width: min(100%, 1060px);
    grid-template-columns: auto minmax(300px, 1fr);
    grid-template-rows: repeat(7, auto) 1fr;
    column-gap: 40px;
  }

  .play-card > * {
    grid-column: 2;
  }

  .play-card > .board {
    grid-row: 1 / -1;
    grid-column: 1;
    width: min(600px, max(380px, calc(100dvh - 220px)));
    margin: 0;
  }

  .play-card > .status {
    text-align: left;
  }

  .status-title {
    justify-content: flex-start;
  }

  .play-controls {
    justify-content: flex-start;
  }

  .play-hint,
  .storage-warning {
    text-align: left;
  }

  .play-card > .text-button {
    align-self: start;
    justify-self: start;
    margin: 6px 0 0;
    padding-left: 0;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 24px, 520px);
  }

  .topbar {
    min-height: 66px;
  }

  .brand {
    gap: 8px;
    font-size: calc(21px * var(--font-scale));
  }

  .brand img {
    width: 30px;
    height: 30px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .font-size-control {
    gap: 0;
  }

  .font-size-control button {
    min-width: 26px;
    padding: 3px 1px;
  }

  .theme-toggle {
    width: 38px;
    height: 38px;
  }

  .language-toggle {
    gap: 2px;
  }

  .language-toggle button {
    min-width: 36px;
    padding: 5px 4px;
    font-size: calc(12px * var(--font-scale));
  }

  .play-layout {
    padding: 10px 0 20px;
  }

  .game-card {
    padding: 14px 12px 16px;
  }

  .mode-toggle button {
    min-height: 46px;
    font-size: calc(16px * var(--font-scale));
  }

  .setting {
    min-height: 76px;
    margin-top: 10px;
  }

  .setting-note--solo {
    min-height: 68px;
  }

  .select-wrap select {
    min-height: 46px;
    font-size: min(calc(17px * var(--font-scale)), 17px);
  }

  .setting-note {
    font-size: calc(14px * var(--font-scale));
  }

  .stats {
    margin-bottom: 12px;
  }

  .stat {
    padding: 7px 4px 8px;
  }

  .stat-value {
    font-size: calc(22px * var(--font-scale));
  }

  .board {
    width: min(100%, max(250px, calc(100dvh - 440px)));
    gap: 6px;
    padding: 6px;
    border-radius: 10px;
  }

  .status {
    min-height: 66px;
    margin-top: 10px;
  }

  .status-note {
    font-size: calc(15px * var(--font-scale));
  }

  .play-controls {
    gap: 6px;
  }

  .control-button {
    min-height: 42px;
    gap: 5px;
    padding: 7px 11px;
    font-size: calc(14px * var(--font-scale));
  }

  .control-button svg {
    width: 17px;
    height: 17px;
  }
}

@media (max-width: 380px) {
  .brand img {
    display: none;
  }

  .control-button {
    padding: 7px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
  }
}
