@layer theme, base, components, utilities;

:root {
  --bg: #070b10;
  --panel: #0e151d;
  --panel-2: #131c26;
  --line: #1f2b38;
  --text: #d7e3ee;
  --dim: #7d8e9e;
  --you: #4cc9f0;
  --enemy: #ff5d73;
  --warn: #ffb454;
  --mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: #0f172a;
  color: #f1f5f9;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Custom Tactical Game & UI Helpers */
.font-mono-code {
  font-family: var(--mono);
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  line-height: 1rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge.you, .badge.win {
  border-color: #22d3ee;
  color: #22d3ee;
  background-color: rgba(6, 182, 212, 0.1);
}

.badge.loss {
  border-color: #f43f5e;
  color: #f43f5e;
  background-color: rgba(244, 63, 94, 0.1);
}

.badge.draw, .badge.warn {
  border-color: #f59e0b;
  color: #f59e0b;
  background-color: rgba(245, 158, 11, 0.1);
}

.badge.dim {
  border-color: #475569;
  color: #94a3b8;
  background-color: rgba(71, 85, 105, 0.2);
}

/* Auth / Lobby Cards */
.game-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem;
  border: 1px solid #334155;
  border-radius: 0.75rem;
  background-color: #1e293b;
  color: #f8fafc;
  text-decoration: none;
  transition: all 0.2s ease-in-out;
}

.game-card:hover {
  border-color: #06b6d4;
  background-color: #0f172a;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.15);
}

.error-banner {
  background-color: rgba(244, 63, 94, 0.15);
  border: 1px solid #f43f5e;
  color: #fca5a5;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.field-error {
  color: #f87171;
  font-size: 0.75rem;
  margin-top: 0.25rem;
  display: block;
}

/* Tactical Battlefield & Game Screen Styles */
button.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(76, 201, 240, 0.25); } }
kbd { font: 11px var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }
.dim { color: var(--dim); }
.loading { display: grid; place-items: center; min-height: 400px; color: var(--dim); }

/* Lobby / Squad */
.lobby { max-width: 900px; margin: 0 auto; }
.maps { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 24px; }
.map { padding: 8px; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.map canvas { width: 100%; max-height: 200px; object-fit: contain; display: block; border-radius: 3px; }
.map.sel { border-color: var(--you); box-shadow: 0 0 0 1px var(--you); }
.map:not(button) { border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); max-width: 320px; }
.squad { display: flex; flex-direction: column; gap: 6px; margin-bottom: 24px; }
.slot { display: grid; grid-template-columns: 18px auto 1fr; align-items: center; gap: 12px; }
.slot .key { color: var(--dim); font-size: 11px; }
.slot .hint { font-size: 12px; }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; padding: 5px 12px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); cursor: pointer; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button b { color: var(--dim); }
.seg button.sel { border-color: var(--you); background: #10212c; color: var(--you); position: relative; z-index: 1; }
.seg button.sel b { color: var(--you); }
.big { font-size: 16px; padding: 12px 28px; }

/* Game Screen */
.game { display: flex; flex-direction: column; height: calc(100dvh - 10rem); min-height: 650px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font: 14px/1.45 var(--mono); color: var(--text); }
.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.brand { color: var(--you); font-weight: 800; letter-spacing: 0.2em; text-decoration: none; }
.turn { font-weight: 700; }
.status { color: var(--dim); flex: 1; min-width: 200px; }
.pills { display: flex; gap: 6px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--dim); }
.pill.done.you { border-color: var(--you); color: var(--you); }
.pill.done.enemy { border-color: var(--enemy); color: var(--enemy); }
.body { flex: 1; display: flex; min-height: 0; }
.board { flex: 1; position: relative; display: flex; padding: 12px; min-width: 0; min-height: 0; background: var(--bg); }
.board canvas { flex: 1; width: 100%; height: 100%; min-width: 0; min-height: 0; display: block; border: 1px solid var(--line); border-radius: 4px; cursor: crosshair; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.panel { width: 290px; flex-shrink: 0; overflow-y: auto; border-left: 1px solid var(--line); background: var(--panel); padding: 8px 14px 16px; }
.panel h3 { font-size: 11px; letter-spacing: 0.15em; color: var(--dim); text-transform: uppercase; margin: 14px 0 8px; }
.panel h3 .dim { letter-spacing: 0; text-transform: none; }
.units { display: flex; flex-direction: column; gap: 4px; }
.unit-row { display: grid; grid-template-columns: 18px 22px 1fr auto; align-items: center; gap: 8px; text-align: left; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--text); cursor: pointer; }
.unit-row .key { color: var(--dim); font-size: 11px; }
.unit-row .glyph { width: 22px; height: 22px; border-radius: 50%; background: var(--you); color: #04121a; display: grid; place-items: center; font-weight: 800; font-size: 11px; }
.unit-row.sel { border-color: var(--you); background: #10212c; }
.unit-row.dead { opacity: 0.45; cursor: default; }
.unit-row.dead .glyph { background: #37414b; }
.unit-row .meta { font-size: 12px; }
.kia { color: var(--enemy); }
.over { color: var(--warn); }
.tag { font-size: 10px; color: var(--warn); border: 1px solid #5c4521; border-radius: 3px; padding: 0 3px; }
.detail { border: 1px solid var(--line); border-radius: 8px; padding: 2px 12px 12px; margin-top: 12px; background: var(--panel-2); }
.detail.hypo { border-color: #5a2430; }
.detail .note { font-size: 12px; color: var(--dim); margin: 0 0 8px; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 10px; font-size: 12px; }
.detail dt { color: var(--dim); }
.detail dd { margin: 0; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.actions button { padding: 5px 4px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; color: var(--text); cursor: pointer; }
.actions button.on { border-color: var(--warn); color: var(--warn); }
.intel p { margin: 0; font-size: 12px; color: var(--dim); }
.intel p + p { margin-top: 4px; }
.abilities { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.abilities button { padding: 0 6px; font-size: 11px; margin-left: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; color: var(--text); cursor: pointer; }
.enemy-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--enemy); margin-right: 8px; }
.keys ul { list-style: none; padding: 0; margin: 0; font-size: 12px; color: var(--dim); display: flex; flex-direction: column; gap: 5px; }
.timeline { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.timeline button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; color: var(--text); cursor: pointer; }
.timeline button.primary { background: var(--you); color: #04121a; border-color: var(--you); font-weight: 700; }
.timeline .track { flex: 1; min-width: 160px; position: relative; padding-top: 16px; }
.timeline input[type=range] { width: 100%; margin: 0; display: block; accent-color: var(--you); }
.timeline .time { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
.timeline button.on { border-color: var(--you); color: var(--you); }
.marks { position: absolute; top: 0; left: 8px; right: 8px; height: 14px; }
.turn-tick { position: absolute; top: 0; height: 30px; border-left: 1px solid var(--line); padding-left: 3px; font-size: 9px; color: var(--dim); pointer-events: none; }
.marker { position: absolute; top: 3px; width: 8px; height: 8px; padding: 0; border: 0; border-radius: 50%; transform: translateX(-50%); z-index: 1; }
.marker:hover:not(:disabled) { outline: 2px solid var(--text); background: inherit; }
.events .turn-group { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.events button { text-align: left; font-size: 12px; padding: 4px 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; color: var(--text); cursor: pointer; }
.events .turn-head { font-weight: 700; background: transparent; border-color: transparent; padding-left: 0; }
.events .event { border-left: 3px solid var(--line); }
.events .event.you { border-left-color: var(--you); }
.events .event.enemy { border-left-color: var(--enemy); }
.events .event.now { background: #10212c; border-color: var(--you); }
.events .dim { font-size: 12px; }
.timeline .summary { color: var(--dim); font-size: 12px; min-width: 150px; }
.summary .you { color: var(--you); }
.summary .enemy { color: var(--enemy); }
.icon { width: 40px; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(4, 8, 12, 0.72); backdrop-filter: blur(2px); z-index: 10; }
.overlay[hidden], .toast[hidden] { display: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; max-width: 460px; width: calc(100% - 32px); max-height: calc(100% - 24px); overflow-y: auto; }
.card h2 { margin: 0 0 8px; letter-spacing: 0.12em; font-size: 1.25rem; font-weight: bold; }
.card h2.win { color: var(--you); }
.card h2.loss { color: var(--enemy); }
.card h2.draw { color: var(--warn); }
.card .link { display: flex; gap: 8px; }
.card input { flex: 1; min-width: 0; font: 13px var(--mono); background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.card .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.card button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; color: var(--text); cursor: pointer; }
.card button.primary { background: var(--you); color: #04121a; border-color: var(--you); font-weight: 700; }
.toast { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); background: #22111a; border: 1px solid #5a2430; color: var(--text); padding: 6px 14px; border-radius: 6px; font-size: 13px; pointer-events: none; z-index: 20; }

/* Mobile Touch Toolbar */
.toolbar, .touch-help, .banner-slot { display: none; }
.toolbar { position: relative; flex-direction: column; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--line); background: var(--panel); }
.toolbar button { min-height: 40px; padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; color: var(--text); cursor: pointer; }
.tool-row { display: flex; align-items: center; gap: 8px; }
.tool-row.specials, .tool-acts { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tool-row.specials button, .tool-acts button { flex: 1 0 auto; white-space: nowrap; }
.tool-row.specials button.on, .tool-acts button.on { border-color: var(--warn); color: var(--warn); }
.tool-acts { flex: 1; min-width: 0; }
.chips { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.chip { width: 40px; flex: none; border-radius: 50%; padding: 0; font-weight: 800; color: var(--you); border-color: #23506a; }
.chip.sel { background: var(--you); color: #04121a; border-color: var(--you); }
.tool-view { display: flex; gap: 6px; margin-left: auto; }
.tool-view button.on { border-color: var(--you); color: var(--you); }
.toolbar .seg button { padding: 6px 12px; }
.banner-slot { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 4; }
.banner-slot.top { top: 10px; bottom: auto; }
.tool-banner { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 10px; border: 1px solid #5c4521; border-radius: 6px; background: #1d1710; color: var(--warn); font-size: 12px; }
.tool-banner span { flex: 1; }
.tool-banner button { width: 40px; color: var(--warn); }

@media (max-width: 860px), (pointer: coarse) {
  .toolbar { display: flex; }
  .banner-slot { display: block; }
  .touch-help { display: block; }
  .keys { display: none; }
  .game { position: relative; height: calc(100dvh - 6rem); min-height: 550px; }
  .topbar { gap: 4px 10px; padding: 6px 10px; }
  .topbar .brand { display: none; }
  .topbar .status { order: 9; flex-basis: 100%; min-width: 0; font-size: 12px; }
  .topbar .cancel-offer { font-size: 12px; }
  .body { flex-direction: column; }
  .board { padding: 0; }
  .panel { display: none; }
  .panel.sheet { display: block; position: absolute; inset: 0; width: 100%; z-index: 3; background: rgba(7, 11, 16, 0.94); backdrop-filter: blur(4px); padding: 12px; overflow-y: auto; }
  .panel.sheet .close { float: right; }
  .timeline { padding: 6px 10px; }
}

/* Sidebar all-games feed: a small read-only board or map per match. The board rules are copied from the
   frontend's style.css (synapse-tactics.css), which can't load on every page, and scoped to the slot. */
.feed-thumb { flex-shrink: 0; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 3px; background: var(--panel); }
.feed-thumb canvas { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.feed-thumb .thumb-turn { display: none; }
.feed-thumb .thumb-board { display: grid; grid-template-columns: repeat(8, 1fr); width: 48px; aspect-ratio: 1; pointer-events: none; }
.feed-thumb .sq { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1; }
.feed-thumb .chess-board .sq.light { background: #c9d4de; }
.feed-thumb .chess-board .sq.dark { background: #5d7489; }
.feed-thumb .checkers-board .sq.light { background: #d8c9a8; }
.feed-thumb .checkers-board .sq.dark { background: #5b6f52; }
.feed-thumb .sq.last { box-shadow: inset 0 0 0 100vmax rgba(255, 180, 84, 0.45); }
.feed-thumb .sq .num { display: none; }
.feed-thumb .chess .piece { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.feed-thumb .checkers .piece { display: block; width: 80%; height: 80%; border-radius: 50%; }
.feed-thumb .checkers .piece.black { background: #22252b; }
.feed-thumb .checkers .piece.white { background: #ece6d8; }
.feed-thumb .checkers .piece .crown { display: none; }
.feed-thumb .checkers .piece.king { box-shadow: inset 0 0 0 1.5px #d29a2e; }
