@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: rgba(255,255,255,.92);
  --surface-strong: #fff;
  --text: #10203a;
  --muted: #63718a;
  --border: #d9e2ef;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --p1: #175cd3;
  --p2: #d24949;
  --board: #f0d8ad;
  --line: #59442c;
  --focus: #f59e0b;
  --shadow: 0 14px 45px rgba(35,55,80,.10);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: rgba(24,36,55,.94);
  --surface-strong: #172235;
  --text: #eef4ff;
  --muted: #a6b3c7;
  --border: #31415a;
  --primary: #7aa2ff;
  --primary-hover: #94b5ff;
  --p1: #78a6ff;
  --p2: #ff8585;
  --board: #b98f59;
  --line: #2d2115;
  --focus: #fbbf24;
  --shadow: 0 18px 50px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top left, rgba(37,99,235,.10), transparent 36rem), var(--bg); color: var(--text); font-family: Inter, system-ui, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 70%, transparent); outline-offset: 2px; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.site-header { height: 64px; display: flex; align-items: center; gap: .8rem; padding: 0 max(1rem, calc((100vw - 1320px)/2)); border-bottom: 1px solid var(--border); background: var(--surface); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 20; }
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.25rem; }
.header-divider { height: 22px; width: 1px; background: var(--border); }
.icon-button { margin-left: auto; width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-strong); color: var(--text); }
main { width: min(1320px, 100%); margin: 0 auto; padding: 2rem 1rem 4rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.landing { max-width: 680px; margin: 6vh auto 0; padding: clamp(1.5rem, 5vw, 3.5rem); }
.eyebrow { color: var(--primary); text-transform: uppercase; font-size: .72rem; letter-spacing: .12em; font-weight: 700; margin: 0 0 .35rem; }
h1 { font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.05; margin: 0 0 .8rem; letter-spacing: -.04em; }
h2 { margin: 0; font-size: 1rem; }
.lede { color: var(--muted); font-size: 1.05rem; max-width: 54ch; margin-bottom: 2rem; }
.field-label { display: block; font-size: .82rem; font-weight: 600; margin: 0 0 .45rem; }
.field-label span, .subtle { color: var(--muted); font-weight: 400; font-size: .76rem; }
input { width: 100%; min-width: 0; padding: .8rem .9rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-strong); color: var(--text); }
.landing-actions, .control-row, .join-row, .invite-row { display: flex; gap: .7rem; }
.landing-actions { margin-top: 1rem; }
.join-form { border-top: 1px solid var(--border); margin-top: 1.25rem; padding-top: 1.25rem; }
.primary-button, .secondary-button, .danger-button { border-radius: 10px; padding: .72rem 1rem; border: 1px solid transparent; font-weight: 600; white-space: nowrap; }
.primary-button { background: var(--primary); color: #fff; }
.primary-button:hover { background: var(--primary-hover); }
.secondary-button { background: var(--surface-strong); color: var(--text); border-color: var(--border); }
.danger-button { background: #b42318; color: white; }
.message { color: var(--muted); min-height: 1.4em; font-size: .86rem; }
.rules-summary { margin-top: 2rem; color: var(--muted); font-size: .84rem; }
.rules-summary summary { color: var(--text); cursor: pointer; font-weight: 600; }
.room { display: grid; gap: 1rem; }
.room-topbar { padding: 1rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.room-topbar h1 { font-size: clamp(1.35rem, 3vw, 2rem); margin: 0; }
.room-topbar .message { margin: .35rem 0 0; min-height: 0; }
.connection-pill { border: 1px solid var(--border); border-radius: 999px; padding: .45rem .7rem; color: var(--muted); font-size: .75rem; white-space: nowrap; }
.connection-pill.online { color: #067647; border-color: #75e0a7; background: #ecfdf3; }
[data-theme="dark"] .connection-pill.online { color: #75e0a7; background: #053321; }
.invite-panel { padding: 1rem 1.25rem; display: grid; grid-template-columns: 1fr minmax(320px, 1.4fr); gap: 1rem; align-items: center; }
.invite-panel p { margin: .25rem 0 0; color: var(--muted); font-size: .85rem; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(330px, .8fr); gap: 1rem; align-items: start; }
.game-column, .side-column { display: grid; gap: 1rem; }
.player-strip { padding: .85rem; display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.player-card { border: 1px solid var(--border); border-radius: 12px; padding: .75rem; display: grid; grid-template-columns: auto 1fr auto; gap: .65rem; align-items: center; }
.player-card.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.piece-swatch { width: 25px; height: 25px; border-radius: 50%; border: 3px double #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.piece-swatch.p1 { background: var(--p1); }
.piece-swatch.p2 { background: var(--p2); }
.player-name { font-weight: 700; font-size: .88rem; }
.player-meta { color: var(--muted); font-size: .7rem; }
.presence { width: 8px; height: 8px; border-radius: 50%; background: #98a2b3; }
.presence.online { background: #12b76a; }
.board-card { padding: clamp(.7rem, 2vw, 1.25rem); }
.turn-banner { margin: 0 auto 1rem; width: min(100%, 680px); border: 2px solid var(--border); border-radius: 14px; padding: .8rem 1rem; display: grid; grid-template-columns: auto 1fr; gap: .75rem; align-items: center; background: var(--surface-strong); }
.turn-banner .turn-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 5px color-mix(in srgb, var(--muted) 15%, transparent); }
.turn-banner strong, .turn-banner small { display: block; }
.turn-banner strong { font-size: .95rem; }
.turn-banner small { color: var(--muted); margin-top: .15rem; font-size: .73rem; }
.turn-banner.yours { border-color: #38a169; background: color-mix(in srgb, #38a169 9%, var(--surface-strong)); }
.turn-banner.yours .turn-dot { background: #38a169; box-shadow: 0 0 0 5px color-mix(in srgb, #38a169 18%, transparent); animation: turn-pulse 1.8s infinite; }
.turn-banner.theirs { border-color: var(--p2); background: color-mix(in srgb, var(--p2) 7%, var(--surface-strong)); }
.turn-banner.theirs .turn-dot { background: var(--p2); }
.turn-banner.finished { border-color: var(--focus); }
@keyframes turn-pulse { 50% { box-shadow: 0 0 0 9px color-mix(in srgb, #38a169 5%, transparent); } }
.board { width: min(100%, 680px); aspect-ratio: 1; margin: auto; position: relative; border-radius: 16px; background: linear-gradient(140deg, color-mix(in srgb, var(--board) 90%, white), var(--board)); box-shadow: inset 0 0 50px rgba(84,55,20,.18); }
.board svg { width: 100%; height: 100%; }
.board path { fill: none; stroke: var(--line); stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.last-move-layer { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; overflow: visible; }
.last-move-layer line { stroke: #f59e0b; stroke-width: 1.7; stroke-dasharray: 3 2; filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); animation: trace-move .55s ease both; }
.last-move-layer marker path { fill: #f59e0b; stroke: none; }
.last-move-layer circle { fill: color-mix(in srgb, #f59e0b 25%, transparent); stroke: #f59e0b; stroke-width: 1.2; }
.last-move-layer #last-move-origin { fill: none; stroke-dasharray: 1.5 1.5; }
.last-move-layer #last-move-target { animation: target-pop .55s ease both; }
@keyframes trace-move { from { stroke-dashoffset: 18; opacity: 0; } }
@keyframes target-pop { from { transform: scale(.35); transform-origin: center; opacity: 0; } }
.point { position: absolute; width: clamp(24px, 5.8%, 40px); aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; border: 2px solid var(--line); background: color-mix(in srgb, var(--board) 82%, white); padding: 0; box-shadow: 0 2px 5px rgba(0,0,0,.2); }
.point.p1 { background: var(--p1); border: 4px double white; }
.point.p2 { background: var(--p2); border: 4px double white; }
.point.selectable { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 35%, transparent), 0 2px 5px rgba(0,0,0,.2); }
.point.destination { background: color-mix(in srgb, var(--primary) 38%, var(--board)); border: 3px dashed var(--primary); }
.point.selected { outline: 5px solid var(--focus); outline-offset: 2px; }
.point.removable { outline: 4px solid #f04438; outline-offset: 2px; }
.game-controls { min-height: 58px; padding: .75rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: .7rem; }
.game-controls p { margin: 0; color: var(--muted); font-size: .82rem; }
.call-card, .chat-card { padding: 1rem; }
.call-card { overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: .7rem; margin-bottom: .9rem; }
.call-state { display: inline-flex; align-items: center; gap: .25rem; border: 1px solid var(--border); border-radius: 999px; padding: .38rem .55rem; color: var(--muted); font-size: .7rem; white-space: nowrap; }
.call-state i { width: 8px; height: 8px; background: #98a2b3; border-radius: 50%; }
.call-state.active { color: #067647; border-color: #75e0a7; background: #ecfdf3; }
.call-state.active i { background: #12b76a; animation: turn-pulse 1.8s infinite; }
[data-theme="dark"] .call-state.active { color: #75e0a7; background: #053321; }
.incoming-call { padding: .8rem; border: 1px solid var(--primary); border-radius: 12px; background: color-mix(in srgb, var(--primary) 8%, var(--surface)); margin-bottom: .8rem; }
.incoming-call p { margin: 0 0 .65rem; }
.incoming-call div { display: flex; gap: .5rem; }
.call-action { flex: 1; border: 0; border-radius: 12px; padding: .7rem .8rem; color: #fff; font-weight: 700; }
.call-action.accept { background: #079455; }
.call-action.hangup { background: #d92d20; }
.call-action.hangup .call-symbol, .round-control.end span { display: inline-block; transform: rotate(135deg); }
.video-stage { position: relative; overflow: hidden; border-radius: 12px; aspect-ratio: 16/10; background: #070b12; margin-bottom: .8rem; }
.video-stage video { width: 100%; height: 100%; object-fit: cover; }
#local-video { position: absolute; right: .55rem; bottom: .55rem; width: 28%; height: 32%; border-radius: 8px; border: 2px solid white; background: #111827; }
.control-row { flex-wrap: wrap; }
.start-call-button { flex: 1; min-width: 130px; display: flex; align-items: center; gap: .65rem; text-align: left; border: 1px solid var(--border); border-radius: 13px; padding: .75rem; background: var(--surface-strong); color: var(--text); }
.start-call-button:hover:not(:disabled) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 6%, var(--surface-strong)); }
.start-call-button:disabled { cursor: not-allowed; opacity: .45; }
.start-call-button svg { width: 28px; height: 28px; flex: 0 0 auto; fill: none; stroke: var(--primary); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.start-call-button strong, .start-call-button small { display: block; }
.start-call-button strong { font-size: .78rem; }
.start-call-button small { color: var(--muted); font-size: .63rem; margin-top: .1rem; }
#active-call-controls { justify-content: center; }
.round-control { flex: 0 0 62px; display: grid; place-items: center; gap: .2rem; border: 0; background: var(--surface-strong); color: var(--text); border-radius: 13px; padding: .55rem .25rem; }
.round-control span { font-size: 1.05rem; }
.round-control small { font-size: .6rem; }
.round-control.end { background: #d92d20; color: white; }
.call-tip { margin-bottom: 0; padding: .65rem .7rem; border-radius: 10px; background: color-mix(in srgb, var(--primary) 5%, var(--surface-strong)); }
.chat-log { height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; padding: .75rem; background: var(--surface-strong); }
.empty-chat { color: var(--muted); text-align: center; margin-top: 6rem; font-size: .82rem; }
.chat-message { margin-bottom: .8rem; }
.chat-message-head { display: flex; gap: .4rem; align-items: baseline; }
.chat-message strong { font-size: .78rem; }
.chat-message time { color: var(--muted); font-size: .65rem; }
.chat-message p { margin: .2rem 0 0; font-size: .85rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: .5rem; margin-top: .7rem; }

@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 650px) {
  main { padding: 1rem .6rem 2.5rem; }
  .site-header { padding-inline: .8rem; font-size: .82rem; }
  .invite-panel { grid-template-columns: 1fr; }
  .invite-row, .join-row { flex-direction: column; }
  .side-column { grid-template-columns: 1fr; }
  .player-strip { grid-template-columns: 1fr; }
  .landing-actions { flex-direction: column; }
  .landing-actions button { width: 100%; }
  .room-topbar { align-items: flex-start; }
  .connection-pill { margin-top: .1rem; }
  .chat-log { height: 250px; }
}
