:root {
  color-scheme: light;
  --ink: #18253d;
  --muted: #5f687c;
  --paper: #fbfaf7;
  --surface: #ffffff;
  --line: #e4e7ed;
  --blue: #4169e1;
  --blue-dark: #2d4bb0;
  --coral: #ee7a62;
  --coral-soft: #fff0ec;
  --blue-soft: #edf2ff;
  --green: #23856a;
  --shadow: 0 18px 55px rgba(31, 44, 78, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(251, 250, 247, .84), rgba(251, 250, 247, .92)),
    url('/dotted-lines/assets/dotted-paper-world.webp') center top / cover fixed,
    var(--paper);
}

.skip-link {
  position: fixed;
  z-index: 40;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  padding: 11px 14px;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  border-bottom: 1px solid rgba(228, 231, 237, .85);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-size: .99rem;
  font-weight: 750;
  letter-spacing: -.02em;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 5px);
  gap: 4px;
  width: 22px;
  height: 22px;
  padding: 4px;
  border: 1.5px solid var(--blue);
  border-radius: 7px;
  transform: rotate(-9deg);
}

.brand-mark i { width: 4px; height: 4px; border-radius: 50%; background: var(--coral); }

.connection-indicator, .connection-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 650;
}

.connection-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #aeb5c2;
  box-shadow: 0 0 0 4px rgba(174, 181, 194, .15);
}

[data-state="connected"] .connection-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(35, 133, 106, .13); }
[data-state="connecting"] .connection-dot { background: #e0a42b; box-shadow: 0 0 0 4px rgba(224, 164, 43, .13); animation: pulse 1.3s infinite; }
[data-state="offline"] .connection-dot { background: #aeb5c2; }

@keyframes pulse { 50% { opacity: .45; } }

main { flex: 1; }

.setup-view {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr);
  align-items: center;
  gap: clamp(44px, 9vw, 112px);
  max-width: 1000px;
  min-height: calc(100vh - 150px);
  margin: 0 auto;
  padding: 62px 0 75px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 17px; font-size: clamp(2.65rem, 6vw, 5.3rem); line-height: .98; letter-spacing: -.075em; }
h1 em { color: var(--blue); font-family: Georgia, serif; font-weight: 500; letter-spacing: -.07em; }
.hero-subtitle { max-width: 480px; margin-bottom: 0; color: var(--muted); font-size: 1.02rem; line-height: 1.7; }

.setup-card {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, .86);
  box-shadow: var(--shadow);
}

.mode-tabs { display: flex; gap: 4px; margin-bottom: 28px; padding: 4px; border-radius: 12px; background: #f1f2f5; }
.mode-tab { flex: 1; min-height: 44px; padding: 10px 8px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: .8rem; font-weight: 700; }
.mode-tab.is-active { color: var(--ink); background: var(--surface); box-shadow: 0 3px 12px rgba(24, 37, 61, .08); }
.mode-tab:focus-visible, .primary-button:focus-visible, .quiet-button:focus-visible, .code-button:focus-visible, .edge:focus-visible, .brand:focus-visible, .site-footer a:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

.room-form { display: grid; gap: 9px; }
.room-form label { margin-top: 6px; color: var(--ink); font-size: .76rem; font-weight: 750; }
.room-form input, .room-form select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: #fff;
  transition: border-color .18s, box-shadow .18s;
}
.room-form input:focus, .room-form select:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(65, 105, 225, .11); }
.room-code-input { font-weight: 800; letter-spacing: .22em; text-transform: uppercase; }

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  min-height: 48px;
  margin-top: 15px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--blue);
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(65, 105, 225, .2);
  transition: background .18s, transform .18s, box-shadow .18s;
}
.primary-button:hover:not(:disabled) { background: var(--blue-dark); transform: translateY(-1px); box-shadow: 0 11px 22px rgba(65, 105, 225, .25); }
.primary-button:disabled { opacity: .58; box-shadow: none; }
.solo-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid rgba(238, 122, 98, .56);
  border-radius: 10px;
  color: #a44434;
  background: rgba(255, 240, 236, .82);
  font-weight: 760;
  transition: transform .18s, background .18s, box-shadow .18s;
}
.solo-button:hover { transform: translateY(-1px); background: #ffe7e1; box-shadow: 0 8px 18px rgba(238, 122, 98, .14); }
.solo-button:focus-visible { outline: 3px solid rgba(238, 122, 98, .3); outline-offset: 3px; }
.solo-button img { width: 30px; height: 30px; margin: -5px 1px -5px -4px; object-fit: contain; }
.form-message { min-height: 1.25em; margin: 13px 0 0; color: #b54738; font-size: .78rem; line-height: 1.4; }
.record-line { color: var(--muted); font-size: .78rem; line-height: 1.4; }
.rules-note { grid-column: 1 / -1; margin: -35px 0 0; color: var(--muted); font-size: .78rem; text-align: center; }
.rules-note span { margin-right: 5px; color: var(--coral); }

.game-view { padding: 32px 0 66px; }
.game-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 19px; }
.game-toolbar h2 { margin: 0; font-size: clamp(2rem, 4vw, 3.2rem); letter-spacing: -.07em; }
.room-code-block { display: grid; gap: 5px; justify-items: end; color: var(--muted); font-size: .67rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.invite-actions { display: inline-flex; gap: 8px; }
.code-button { display: inline-flex; align-items: center; min-height: 44px; gap: 10px; padding: 5px 0 5px 13px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fff; letter-spacing: .12em; }
.code-button strong { padding-right: 3px; font-size: 1.05rem; }
.copy-icon { display: inline-grid; place-items: center; width: 30px; height: 30px; border-left: 1px solid var(--line); color: var(--blue); font-size: 1rem; }
.game-message { min-height: 1.35em; margin-bottom: 15px; color: var(--muted); font-size: .82rem; }

.player-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 720px; margin-bottom: 20px; }
.player-card { display: flex; align-items: center; gap: 12px; min-height: 70px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .72); }
.player-card.is-current { border-color: var(--blue); background: var(--blue-soft); box-shadow: 0 5px 15px rgba(65, 105, 225, .1); }
.player-card.is-you { box-shadow: inset 3px 0 0 var(--coral); }
.player-avatar { display: grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; border-radius: 11px; color: #fff; font-size: .83rem; font-weight: 800; }
.player-card.player-one .player-avatar { background: var(--blue); }
.player-card.player-two .player-avatar { background: var(--coral); }
.player-avatar.is-bot { overflow: visible; background: var(--coral-soft); }
.player-avatar.is-bot img { width: 42px; height: 42px; max-width: none; object-fit: contain; }
.player-details { min-width: 0; flex: 1; }
.player-name { overflow: hidden; color: var(--ink); font-size: .86rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.player-you { margin-left: 4px; color: #963e2d; font-size: .64rem; text-transform: uppercase; letter-spacing: .08em; }
.player-presence { color: var(--muted); font-size: .66rem; }
.player-score { color: var(--ink); font-size: 1.4rem; font-weight: 800; }

.game-layout { display: grid; grid-template-columns: minmax(0, 720px) minmax(185px, 220px); align-items: start; gap: clamp(25px, 5vw, 70px); }
.board-wrap { min-width: 0; }
.board {
  --cols: 4;
  --rows: 4;
  position: relative;
  width: min(100%, 720px);
  aspect-ratio: var(--cols) / var(--rows);
  overflow: visible;
  border-radius: 19px;
  background-color: #f5f7fc;
  background-image: radial-gradient(circle, rgba(65, 105, 225, .09) 1px, transparent 1.5px);
  background-size: 24px 24px;
  box-shadow: inset 0 0 0 1px rgba(65, 105, 225, .06), 0 15px 35px rgba(31, 44, 78, .07);
}
.box { position: absolute; z-index: 1; border-radius: 8px; background: transparent; transition: background .25s, transform .25s; }
.box.player-one { background: rgba(65, 105, 225, .19); }
.box.player-two { background: rgba(238, 122, 98, .22); }
.box span { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(24, 37, 61, .6); font-size: clamp(.65rem, 2vw, .9rem); font-weight: 850; }
.box.is-new { animation: box-pop .55s cubic-bezier(.2, 1.4, .4, 1) both; }
.edge { position: absolute; z-index: 3; display: block; min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 999px; background: transparent; }
.edge.horizontal { height: 44px; transform: translateY(-50%); }
.edge.vertical { width: 44px; transform: translateX(-50%); }
.edge::before { content: ''; position: absolute; border-radius: 999px; transition: background .16s, box-shadow .16s, width .16s, height .16s; }
.edge.horizontal::before { left: 0; right: 0; top: 50%; height: 0; transform: translateY(-50%); }
.edge.vertical::before { top: 0; bottom: 0; left: 50%; width: 0; transform: translateX(-50%); }
.edge.open:hover:not(:disabled):not([aria-disabled="true"])::before, .edge.open:focus-visible::before { background: rgba(65, 105, 225, .2); box-shadow: 0 0 0 5px rgba(65, 105, 225, .07); }
.edge.open.horizontal:hover:not(:disabled):not([aria-disabled="true"])::before, .edge.open.horizontal:focus-visible::before { height: 14px; }
.edge.open.vertical:hover:not(:disabled):not([aria-disabled="true"])::before, .edge.open.vertical:focus-visible::before { width: 14px; }
.edge.open[aria-disabled="true"] { cursor: default; }
.edge.claimed { z-index: 4; }
.edge.claimed.horizontal::before { height: clamp(7px, 1.1vw, 11px); background: var(--blue); box-shadow: 0 2px 5px rgba(65, 105, 225, .2); }
.edge.claimed.vertical::before { width: clamp(7px, 1.1vw, 11px); background: var(--blue); box-shadow: 0 2px 5px rgba(65, 105, 225, .2); }
.edge.claimed.player-two::before { background: var(--coral); box-shadow: 0 2px 5px rgba(238, 122, 98, .2); }
.edge.is-last::before { animation: line-flash .65s ease-out both; }
.edge.is-last::after { content: ''; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; transform: translate(-50%, -50%); border: 2px solid #fff; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2px rgba(24, 37, 61, .18); }
.edge.is-hinted { outline: 3px dashed var(--blue); outline-offset: 2px; }
.edge.open.is-hinted.horizontal::before, .edge.open.is-hinted.vertical::before { background: rgba(65, 105, 225, .38); animation: hint-pulse 1.2s ease-out both; }
.edge.open.is-hinted.horizontal::before { height: 14px; box-shadow: 0 0 0 6px rgba(65, 105, 225, .14); }
.edge.open.is-hinted.vertical::before { width: 14px; box-shadow: 0 0 0 6px rgba(65, 105, 225, .14); }
.dot { position: absolute; z-index: 6; width: clamp(11px, 2vw, 17px); height: clamp(11px, 2vw, 17px); transform: translate(-50%, -50%); border: 3px solid var(--ink); border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(24, 37, 61, .12); }
.board-help { margin: 13px 0 0; color: var(--muted); font-size: .72rem; text-align: center; }

.game-aside { display: grid; gap: 11px; }
.turn-card { display: grid; gap: 8px; min-height: 112px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; transition: border-color .2s, box-shadow .2s; }
.turn-card.is-your-turn { border-color: rgba(65, 105, 225, .55); box-shadow: 0 7px 20px rgba(65, 105, 225, .1); }
.turn-label { color: #963e2d; font-size: .65rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.turn-card strong { color: var(--ink); font-size: .94rem; line-height: 1.3; }
.move-count { color: var(--muted); font-size: .69rem; }
.series-status { width: fit-content; padding: 5px 8px; border: 1px solid rgba(65, 105, 225, .18); border-radius: 999px; color: var(--blue-dark); background: var(--blue-soft); font-size: .66rem; font-weight: 800; line-height: 1.25; }
.series-status.is-match-point { border-color: rgba(238, 122, 98, .38); color: #963e2d; background: var(--coral-soft); }
.strategy-count { color: var(--blue-dark); font-size: .69rem; font-weight: 700; line-height: 1.35; }
.game-aside .primary-button { width: 100%; margin-top: 0; }
.game-aside .solo-button { width: 100%; }
.quiet-button { min-height: 44px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: transparent; font-size: .78rem; font-weight: 700; }
.quiet-button:hover { color: var(--ink); border-color: #c8ceda; background: #fff; }
.sound-toggle {
  min-height: 44px;
}
.sound-toggle[aria-pressed="true"] {
  border-color: rgba(65, 105, 225, .42);
  color: var(--blue-dark);
  background: var(--blue-soft);
}
.sound-toggle:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}
.connection-note { justify-content: center; margin: 8px 0 0; font-size: .67rem; line-height: 1.4; text-align: center; }
.connection-note .connection-dot { width: 6px; height: 6px; box-shadow: none; }

.site-footer { padding: 22px 0 26px; color: var(--muted); font-size: .68rem; text-align: center; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(360px, calc(100vw - 40px)); padding: 13px 16px; border: 1px solid #f2c5bb; border-radius: 11px; color: #8e392d; background: #fff8f6; box-shadow: var(--shadow); font-size: .78rem; line-height: 1.4; }
.game-message.capture-message { color: var(--blue-dark); font-weight: 750; }
.score-pop { animation: score-pop .55s cubic-bezier(.2, 1.4, .4, 1) both; }
.intel-pop { animation: intel-pop .48s ease-out both; }

@keyframes box-pop {
  0% { opacity: .2; transform: scale(.62); }
  65% { opacity: 1; transform: scale(1.04); }
  100% { transform: scale(1); }
}

@keyframes line-flash {
  0% { filter: brightness(1.5); box-shadow: 0 0 0 5px rgba(65, 105, 225, .22); }
  100% { filter: brightness(1); box-shadow: 0 2px 5px rgba(65, 105, 225, .2); }
}

@keyframes hint-pulse {
  0% { box-shadow: 0 0 0 3px rgba(65, 105, 225, .05); }
  40% { box-shadow: 0 0 0 10px rgba(65, 105, 225, .22); }
  100% { box-shadow: 0 0 0 6px rgba(65, 105, 225, .14); }
}

@keyframes score-pop {
  0% { transform: scale(.82); color: var(--coral); }
  65% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes intel-pop {
	0% { opacity: .35; transform: translateY(3px); }
	100% { opacity: 1; transform: translateY(0); }
}

@media (max-width: 760px) {
  .page-shell { padding: 0 max(22px, env(safe-area-inset-right)) 0 max(22px, env(safe-area-inset-left)); }
  .site-header { min-height: 68px; }
  .setup-view { display: block; min-height: auto; padding: 62px 0 40px; }
  .hero-copy { margin-bottom: 40px; }
  h1 { font-size: clamp(2.9rem, 14vw, 5rem); }
  .setup-card { padding: 22px; }
  .rules-note { margin: 34px 0 0; }
  .game-view { padding-top: 25px; }
  .game-toolbar { align-items: start; }
  .room-code-block { padding-top: 4px; }
  .game-layout { grid-template-columns: 1fr; }
  .game-aside { grid-template-columns: 1fr 1fr; align-items: center; }
  .turn-card { grid-column: 1 / -1; }
  .connection-note { grid-column: 1 / -1; }
}

@media (max-width: 440px) {
  .connection-indicator #connection-text { display: none; }
  .player-strip { gap: 7px; }
  .player-card { min-height: 62px; padding: 9px; gap: 8px; }
  .player-avatar { flex-basis: 29px; width: 29px; height: 29px; border-radius: 9px; font-size: .72rem; }
  .player-score { font-size: 1.15rem; }
  .player-name { font-size: .76rem; }
  .player-you { display: block; margin: 2px 0 0; font-size: .56rem; }
  .code-button { padding-left: 9px; }
	.game-message { min-height: 1.55em; margin-bottom: 12px; font-weight: 700; }
}

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

@media (forced-colors: active) {
  .edge.open::before { border: 2px dashed ButtonText; }
  .edge.claimed::before { border: 4px solid ButtonText; }
  .dot { border-color: CanvasText; }
}
