/* Talavera tile: cobalt on glazed white, marigold for a hit (the worksheet's "color in the
   space"), chili for a sunk boat, an X for a miss. One column, phone first. */
:root {
  --tile: #f3f5fb;
  --paper: #ffffff;
  --ink: #16204a;
  --muted: #5b648c;
  --cobalt: #2340a0;
  --cobalt-ink: #ffffff;
  --cobalt-soft: #dfe5f7;
  --sea: #e8edf9;
  --line: #c2cbe8;
  --marigold: #f0a20b;
  --chili: #c8361f;
  --leaf: #23865a;
  --boat: #2f4fb8;
  --display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tile: #0d1330; --paper: #151c3e; --ink: #e9edfb; --muted: #9ea7cf; --cobalt: #8ea6ff; --cobalt-ink: #0d1330;
    --cobalt-soft: #222c5c; --sea: #111938; --line: #2b3669; --marigold: #f6b636; --chili: #ff6a4d; --leaf: #4cc48c;
    --boat: #6b87ff; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --tile: #0d1330; --paper: #151c3e; --ink: #e9edfb; --muted: #9ea7cf; --cobalt: #8ea6ff; --cobalt-ink: #0d1330;
  --cobalt-soft: #222c5c; --sea: #111938; --line: #2b3669; --marigold: #f6b636; --chili: #ff6a4d; --leaf: #4cc48c;
  --boat: #6b87ff; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--tile); color: var(--ink); font: 17px/1.45 var(--body);
  padding: 0 16px env(safe-area-inset-bottom, 0px); min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
main, .top, .foot { max-width: 460px; margin-inline: auto; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; letter-spacing: .01em; text-wrap: balance; margin: 0; }
h1 { font-size: 1.55rem; line-height: 1.1; }
h1 span { color: var(--cobalt); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; color: var(--muted); }
b { font-weight: 700; }
.en { color: var(--muted); font-size: .9rem; margin: .2rem 0 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.center { align-items: center; text-align: center; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }

/* Header: a strip of talavera tiles, then the title */
.top { position: sticky; top: 0; z-index: 5; background: var(--tile); padding-top: env(safe-area-inset-top, 0px); margin-inline: -16px; padding-inline: 16px; }
.band {
  height: 18px; margin-inline: -16px; background-color: var(--cobalt);
  background-image:
    radial-gradient(circle at 50% 50%, var(--marigold) 0 2px, transparent 2.5px),
    radial-gradient(circle at 50% 50%, var(--paper) 0 5px, transparent 5.5px),
    radial-gradient(circle at 0 0, var(--paper) 0 6px, transparent 6.5px),
    radial-gradient(circle at 100% 0, var(--paper) 0 6px, transparent 6.5px),
    radial-gradient(circle at 0 100%, var(--paper) 0 6px, transparent 6.5px),
    radial-gradient(circle at 100% 100%, var(--paper) 0 6px, transparent 6.5px);
  background-size: 18px 18px;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px; }
.foot { padding-block: 24px 32px; text-align: center; }
main { padding-block: 6px 24px; }

.intro .lede { font-size: 1.05rem; margin: 0; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
label { font-weight: 700; }
input {
  font: inherit; color: var(--ink); background: var(--tile); border: 2px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus-visible { outline: none; border-color: var(--cobalt); }
#code { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; flex: 1 1 6rem; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* Buttons */
.btn {
  font: 700 1rem var(--body); color: var(--ink); background: var(--cobalt-soft); border: 0; border-radius: 12px;
  padding: 12px 16px; min-height: 48px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--cobalt); color: var(--cobalt-ink); font-family: var(--display); font-weight: 400; font-size: 1.15rem; letter-spacing: .02em; }
.btn.small { min-height: 40px; padding: 8px 12px; font-size: .95rem; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .icon-btn:focus-visible, .cell:focus-visible, .hd:focus-visible, .tabs button:focus-visible, .chip:focus-visible { outline: 3px solid var(--marigold); outline-offset: 2px; }
.icon-btn { background: none; border: 0; color: var(--cobalt); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 26px; height: 26px; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: .9rem; text-decoration: underline; cursor: pointer; padding: 6px; }
.mic-btn svg { width: 24px; height: 24px; flex: none; }
.mic-btn.big { min-height: 64px; font-size: 1.1rem; background: var(--cobalt); color: var(--cobalt-ink); border-radius: 32px; }
.mic-btn.listening { background: var(--chili); color: #fff; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--chili) 22%, transparent); } }

.msg { margin: 0; color: var(--chili); font-weight: 700; font-size: .95rem; }
.msg.ok { color: var(--leaf); }
.heard { margin: 0; color: var(--muted); font-style: italic; overflow-wrap: anywhere; }
.msg:empty, .heard:empty { display: none; }
.wait { color: var(--muted); font-weight: 700; }
.wait::after { content: ""; display: inline-block; width: 1em; text-align: left; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* Lobby */
.qr { width: min(64vw, 240px); aspect-ratio: 1; background: #fff; border-radius: 12px; padding: 6px; border: 1px solid var(--line); }
.qr svg { display: block; width: 100%; height: 100%; }
.code-big { font-family: var(--display); font-size: 2.6rem; letter-spacing: .3em; margin: 0; padding-left: .3em; color: var(--cobalt); }
.link { margin: 0; font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; user-select: all; }

/* Fleet chips */
.fleet { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip {
  font: inherit; color: var(--ink); background: var(--paper); border: 2px solid var(--line); border-radius: 12px;
  padding: 8px 10px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.chip b { font-size: .98rem; }
.chip .dots { display: flex; gap: 3px; }
.chip .dots i { width: 12px; height: 12px; border-radius: 3px; background: var(--boat); }
.chip.active { border-color: var(--cobalt); box-shadow: inset 0 0 0 2px var(--cobalt); }
.chip.placed:not(.active) { opacity: .55; }
.chip.placed:not(.active) .dots i { background: var(--leaf); }

/* Board */
.board { display: flex; flex-direction: column; gap: 6px; }
.grid {
  display: grid; grid-template-columns: 1.9rem repeat(8, minmax(0, 1fr)); gap: 2px;
  font-variant-numeric: tabular-nums; user-select: none;
}
.hd {
  font: 700 .8rem var(--body); color: var(--muted); background: none; border: 0; padding: 0; height: 1.6rem;
  display: grid; place-items: center; cursor: pointer;
}
.hd.row { height: auto; }
.hd.corner { cursor: default; }
.cell {
  position: relative; aspect-ratio: 1.2 / 1; border: 0; padding: 0; border-radius: 4px; background: var(--sea);
  box-shadow: inset 0 0 0 1px var(--line); cursor: pointer;
}
.cell.boat { background: var(--boat); box-shadow: none; border-radius: 2px; }
.cell.boat.h.first { border-radius: 10px 2px 2px 10px; }
.cell.boat.h.last { border-radius: 2px 10px 10px 2px; }
.cell.boat.v.first { border-radius: 10px 10px 2px 2px; }
.cell.boat.v.last { border-radius: 2px 2px 10px 10px; }
.cell.boat::before { content: ""; position: absolute; inset: 38%; border-radius: 50%; background: color-mix(in srgb, var(--paper) 70%, transparent); }
.cell.hit { background: var(--marigold); box-shadow: none; }
.cell.boat.hit { background: var(--boat); }
.cell.boat.hit::before { inset: 22%; background: var(--marigold); }
.cell.sunk, .cell.boat.sunk { background: var(--chili); }
.cell.boat.sunk::before { background: color-mix(in srgb, #000 25%, transparent); inset: 30%; }
.cell.miss::after {
  content: ""; position: absolute; inset: 20%;
  background:
    linear-gradient(45deg, transparent calc(50% - 1.5px), var(--muted) calc(50% - 1.5px) calc(50% + 1.5px), transparent calc(50% + 1.5px)),
    linear-gradient(-45deg, transparent calc(50% - 1.5px), var(--muted) calc(50% - 1.5px) calc(50% + 1.5px), transparent calc(50% + 1.5px));
}
.cell.ghost { box-shadow: inset 0 0 0 2px var(--boat); }
.cell.sel { box-shadow: inset 0 0 0 3px var(--cobalt); }
.cell.ask { z-index: 1; box-shadow: 0 0 0 3px var(--marigold); animation: ask 1s ease-in-out infinite; }
.cell.flash { animation: flash .9s ease-out 1; }
@keyframes ask { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--marigold) 45%, transparent); } }
@keyframes flash { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }

/* Play */
.score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; font-weight: 700; }
.score .p { display: flex; align-items: center; gap: 6px; min-width: 0; }
.score .p:last-child { justify-content: flex-end; }
.score .p span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score .p.turn span { color: var(--cobalt); text-decoration: underline 3px var(--marigold); text-underline-offset: 4px; }
.score .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.score .dot.on { background: var(--leaf); }
.score .wins { font-family: var(--display); font-size: 1.3rem; color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--cobalt-soft); border-radius: 12px; padding: 4px; gap: 4px; }
.tabs button { font: 700 .9rem var(--body); color: var(--ink); background: none; border: 0; border-radius: 9px; padding: 9px 6px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--cobalt); }
.dock {
  position: sticky; bottom: 0; z-index: 4; background: var(--paper); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 16px 16px 0 0; margin-inline: -8px; padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 -6px 24px color-mix(in srgb, var(--ink) 10%, transparent);
}
.turn { margin: 0; font-weight: 700; font-size: 1.05rem; }
.model { display: flex; align-items: center; gap: 8px; background: var(--cobalt-soft); border-radius: 12px; padding: 4px 4px 4px 12px; }
.model span { flex: 1; font-weight: 700; min-width: 0; }
.confirm { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.confirm .bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--cobalt-soft); overflow: hidden; }
.confirm .bar i { display: block; height: 100%; width: 100%; background: var(--marigold); transform-origin: left; }
.confirm.run .bar i { animation: drain var(--wait, 1.8s) linear forwards; }
@keyframes drain { to { transform: scaleX(0); } }
.confirm span { font-weight: 700; }
.over { display: flex; flex-direction: column; gap: 10px; }
.over-title { font-family: var(--display); font-size: 1.7rem; margin: 0; color: var(--cobalt); }
.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .95rem; }
.stats th, .stats td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.stats th:first-child, .stats td:first-child { text-align: left; color: var(--muted); font-weight: 400; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
