:root {
  --bg: #0b0c10;
  --surface: #18181b;
  --pop: #191a1f;
  --border: #2a2a30;
  --text: #efeff1;
  --text2: #d5d7dd;
  --muted: #8b8b99;
  --line: rgba(208, 217, 251, 0.12);
  --s1: rgba(208, 217, 251, 0.08);
  --s2: rgba(208, 217, 251, 0.12);
  --blue: #335fff;
  --green: #3fcf8e;
  --amber: #f0b429;
  --light: #e8edf5;
  --dark: #6b7385;
  --dur: 0.22s;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --shadow: 0 2px 4px -0.5px rgba(4, 4, 8, 0.25), 0 10px 20px -0.75px rgba(4, 4, 8, 0.25);
  --radius: 14px;
  --radius-sm: 10px;
  --board: min(64vh, calc(100vw - 4.5rem), 420px);
  --frame: var(--board);
  --page: min(520px, calc(100% - 2rem));
  --pad-x: 20px;
  --pad-top: max(4.75rem, calc(env(safe-area-inset-top, 0px) + 3.5rem));
}

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

[hidden] {
  display: none !important;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(255, 255, 255, 0.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
}

.page {
  width: var(--page);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--pad-top) 0 max(4rem, calc(env(safe-area-inset-bottom, 0px) + 2.5rem));
}

/* Center the side-pick start screen in the viewport */
.page:has(#hero:not([hidden])) {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: max(1.5rem, env(safe-area-inset-top, 0px));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
}

.hero {
  text-align: center;
  animation: rise 0.28s var(--ease);
  width: 100%;
}

.hero-title {
  margin: 0 0 22px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.gate {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: min(var(--frame), 100%);
  margin: 0 auto;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.side-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--pop);
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    border-color var(--dur) var(--ease),
    background var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.side-btn:hover {
  background: var(--s1);
  border-color: rgba(255, 255, 255, 0.28);
}

.side-btn:active {
  transform: scale(0.97);
}

.swatch {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.swatch svg {
  display: block;
  flex: 0 0 auto;
}

.swatch.x {
  background: #f4f4f5;
  color: #0e0e10;
}

.swatch.o {
  background: #0e0e10;
  color: #f4f4f5;
}

.app {
  animation: rise 0.28s var(--ease);
}

.panel {
  width: min(var(--frame), 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
  justify-items: stretch;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  font-size: 12.5px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.chip:hover {
  background: var(--s1);
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--text);
}

.status {
  margin: 0;
  min-height: 2.6em;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--s1);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
  text-align: center;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: #121318;
  -webkit-tap-highlight-color: transparent;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  gap: 3px;
  padding: 3px;
  background: #0a0b0f;
  user-select: none;
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
  background: var(--light);
  border: 0;
  border-radius: 4px;
  transition: background var(--dur) var(--ease);
}

.cell:nth-child(even) {
  background: var(--dark);
}

.cell:hover:not(.filled):not(.over) {
  filter: brightness(1.08);
}

.cell.suggest::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 16%;
  box-shadow: inset 0 0 0 3px rgba(63, 207, 142, 0.95);
  background: rgba(63, 207, 142, 0.22);
  pointer-events: none;
  animation: pulse-target 1.4s var(--ease) infinite;
}

.cell.last::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(51, 95, 255, 0.28);
  pointer-events: none;
  border-radius: inherit;
}

.cell.win-line::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(63, 207, 142, 0.35);
  pointer-events: none;
  border-radius: inherit;
}

.mark {
  position: relative;
  z-index: 1;
  display: block;
  width: 1em;
  height: 1em;
  font-size: clamp(42px, 12vw, 72px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  pointer-events: none;
}

.mark.x {
  color: #0e0e10;
  /* optical center for heavy Inter X */
  transform: translate(0.02em, 0.04em);
}

.cell:nth-child(even) .mark.x {
  color: #f4f4f5;
}

.mark.o {
  color: #0e0e10;
  transform: translateY(0.02em);
}

.cell:nth-child(even) .mark.o {
  color: #f4f4f5;
}

.cell.over {
  cursor: default;
}

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

@keyframes pulse-target {
  0%,
  100% {
    box-shadow: inset 0 0 0 3px rgba(63, 207, 142, 0.95);
    background: rgba(63, 207, 142, 0.18);
  }
  50% {
    box-shadow: inset 0 0 0 4px rgba(63, 207, 142, 1);
    background: rgba(63, 207, 142, 0.3);
  }
}

@media (max-width: 640px) {
  :root {
    --page: min(100%, calc(100% - 1.25rem));
    --board: min(100%, calc(100vw - 2.5rem));
    --pad-top: max(5rem, calc(env(safe-area-inset-top, 0px) + 3.75rem));
  }

  .gate {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .side-btn {
    min-height: 52px;
    font-size: 15px;
  }

  .panel {
    width: 100%;
    gap: 12px;
  }

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

  .chip {
    height: 40px;
    font-size: 13px;
  }

  .status {
    font-size: 13px;
    min-height: 2.8em;
  }
}

@media (max-width: 380px) {
  .chip {
    padding: 0 8px;
    font-size: 12px;
  }
}
