:root {
  color-scheme: dark;
  --bg: #06070d;
  --panel: #111522;
  --panel-2: #171c2b;
  --line: rgba(255, 255, 255, 0.13);
  --text: #f6f7fb;
  --muted: #aeb5c7;
  --cyan: #11e3ff;
  --pink: #ff2f7d;
  --lime: #b9ff5a;
  --yellow: #ffd166;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  overflow-x: hidden;
  touch-action: manipulation;
}

button,
textarea,
a {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100svh;
  display: flex;
  justify-content: center;
  background:
    linear-gradient(145deg, rgba(17, 227, 255, 0.18), transparent 26%),
    linear-gradient(35deg, rgba(255, 47, 125, 0.18), transparent 30%),
    linear-gradient(180deg, #06070d 0%, #111522 62%, #06070d 100%);
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.game-shell {
  width: min(100%, 480px);
  min-height: calc(100svh - 28px);
  display: grid;
  grid-template-rows: auto auto auto auto 1fr auto auto auto;
  gap: 12px;
}

.topbar,
.score-strip,
.status-panel,
.share-fallback {
  background: rgba(17, 21, 34, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.26);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid var(--cyan);
  border-bottom-color: var(--pink);
  border-right-color: var(--pink);
  border-radius: 8px;
  color: var(--text);
  font-weight: 900;
  font-size: 1.05rem;
  line-height: 1;
}

.eyebrow,
.status-copy,
.score-label,
.footer-row,
.share-fallback label {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 0.78rem;
}

h1 {
  margin: 0;
  font-size: 1.7rem;
  line-height: 1;
}

.icon-button {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0f1a;
  color: var(--lime);
  font-weight: 800;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

.score-strip div {
  padding: 12px 8px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.score-strip div:last-child {
  border-right: 0;
}

.score-label {
  display: block;
  font-size: 0.74rem;
}

.score-strip strong {
  display: block;
  margin-top: 2px;
  font-size: 1.45rem;
}

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

.mode-tab,
.primary-action,
.secondary-action {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(17, 21, 34, 0.84);
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.38);
}

.mode-tab.active {
  border-color: rgba(17, 227, 255, 0.75);
  background: linear-gradient(135deg, rgba(17, 227, 255, 0.24), rgba(255, 47, 125, 0.16));
}

.status-panel {
  padding: 14px;
}

.status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-title {
  margin: 0 0 4px;
  font-size: 1.25rem;
  font-weight: 900;
}

.move-badge {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0f1a;
  color: var(--yellow);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 900;
}

.status-copy {
  margin: 0;
  min-height: 22px;
  font-size: 0.95rem;
}

.board-wrap {
  position: relative;
  align-self: center;
}

.board {
  aspect-ratio: 1;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 7, 13, 0.58);
}

.cell {
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    #151b2a;
  color: var(--text);
  font-size: 4.25rem;
  font-weight: 950;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.cell:enabled:active {
  transform: scale(0.96);
}

.cell:disabled {
  opacity: 1;
}

.cell.mark-x {
  color: var(--cyan);
  text-shadow: 0 0 22px rgba(17, 227, 255, 0.45);
}

.cell.mark-o {
  color: var(--pink);
  text-shadow: 0 0 22px rgba(255, 47, 125, 0.45);
}

.win-line {
  position: absolute;
  z-index: 2;
  height: 8px;
  width: 82%;
  left: 9%;
  top: 50%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--lime), var(--yellow));
  box-shadow: 0 0 24px rgba(185, 255, 90, 0.42);
  transform-origin: center;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.line-0-1-2 {
  top: 18%;
}

.line-3-4-5 {
  top: 50%;
}

.line-6-7-8 {
  top: 82%;
}

.line-0-3-6,
.line-1-4-7,
.line-2-5-8 {
  width: 8px;
  height: 82%;
  top: 9%;
}

.line-0-3-6 {
  left: 18%;
}

.line-1-4-7 {
  left: 50%;
}

.line-2-5-8 {
  left: 82%;
}

.line-0-4-8 {
  transform: rotate(45deg);
  width: 112%;
  left: -6%;
}

.line-2-4-6 {
  transform: rotate(-45deg);
  width: 112%;
  left: -6%;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 10px;
}

.primary-action {
  border-color: transparent;
  background: linear-gradient(135deg, var(--cyan), var(--pink));
  color: #06070d;
}

.primary-action:disabled {
  background: #242939;
  color: #737b90;
}

.secondary-action {
  background: rgba(17, 21, 34, 0.84);
}

.share-fallback {
  padding: 12px;
}

.share-fallback label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.share-fallback textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #080b12;
  color: var(--text);
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.82rem;
}

.footer-row a {
  color: var(--muted);
  text-decoration: none;
}

@media (max-width: 360px) {
  .game-shell {
    gap: 9px;
  }

  .cell {
    font-size: 3.35rem;
  }

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