:root {
  --bg: oklch(96% 0.01 250);
  --surface: oklch(99% 0 0);
  --ink: oklch(22% 0.02 260);
  --muted: oklch(55% 0.02 260);
  --accent: oklch(58% 0.18 255);
  --accent-soft: oklch(92% 0.05 255);
  --turn: oklch(74% 0.17 145);
  --light-sq: oklch(90% 0.03 85);
  --dark-sq: oklch(58% 0.07 145);
  --sel: oklch(82% 0.16 95);
  --hint: oklch(70% 0.12 145 / 0.55);
  --last: oklch(85% 0.14 95 / 0.6);
  --check: oklch(65% 0.22 25 / 0.7);
  --radius: 20px;
  --shadow: 0 6px 24px oklch(40% 0.05 260 / 0.12);
  --space: clamp(1rem, 0.6rem + 2vw, 2rem);

  /* Liquid Glass (iOS 26-style) material tokens */
  --glass-bg: oklch(99% 0.006 255 / 0.55);
  --glass-bg-strong: oklch(99% 0.006 255 / 0.72);
  --glass-border: oklch(100% 0 0 / 0.55);
  --glass-blur: saturate(180%) blur(20px);
  --glass-highlight: inset 0 1px 0 oklch(100% 0 0 / 0.7), inset 0 0 0 1px oklch(100% 0 0 / 0.06);
  --glass-shadow: 0 10px 34px oklch(40% 0.06 260 / 0.16), 0 2px 8px oklch(40% 0.06 260 / 0.10);

  /* board sizing shared by the board frame and the chat panel */
  --bsize: min(86vw, 520px);
  --gutter: 1.15rem;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  /* layered mesh so the frosted glass has rich color to refract */
  background:
    radial-gradient(900px 600px at 8% -8%, oklch(86% 0.12 285 / 0.55), transparent 60%),
    radial-gradient(1000px 700px at 92% 0%, oklch(88% 0.11 230 / 0.6), transparent 55%),
    radial-gradient(900px 800px at 70% 110%, oklch(90% 0.10 165 / 0.5), transparent 55%),
    radial-gradient(700px 600px at 0% 100%, oklch(88% 0.10 320 / 0.45), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* Reusable frosted-glass surface */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}
.brand .logo { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 11px; box-shadow: var(--shadow); }
.brand .back-link {
  font-size: 1.6rem; line-height: 1; text-decoration: none; color: var(--muted);
  padding: 0.1rem 0.4rem; border-radius: 8px; transition: color 120ms, background 120ms;
}
.brand .back-link:hover { color: var(--accent); background: var(--accent-soft); }
.brand h1 {
  font-size: clamp(1.5rem, 1rem + 2vw, 2.2rem);
  margin: 0;
  letter-spacing: -0.02em;
}
.brand .who { margin-left: auto; font-size: 0.9rem; color: var(--muted); }
.brand .who button {
  margin-left: 0.5rem;
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
}

.card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
  padding: clamp(1.2rem, 1rem + 2vw, 2rem);
  margin-bottom: 1.2rem;
}

h2 { margin: 0 0 1rem; font-size: 1.1rem; letter-spacing: -0.01em; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.8rem 0 0.3rem; }
input, select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 1rem;
  border: 1.5px solid oklch(88% 0.01 260);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

button {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.7rem 1.1rem;
  border: none;
  border-radius: 13px;
  background: linear-gradient(180deg, oklch(64% 0.18 255), var(--accent));
  color: white;
  cursor: pointer;
  box-shadow: inset 0 1px 0 oklch(100% 0 0 / 0.35), 0 4px 14px oklch(58% 0.18 255 / 0.35);
  transition: transform 120ms cubic-bezier(0.16, 1, 0.3, 1), filter 120ms, box-shadow 120ms;
}
button:hover { filter: brightness(1.06); }
button:active { transform: translateY(1px) scale(0.99); }
button.ghost {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  color: var(--accent);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight);
}
button.danger {
  background: linear-gradient(180deg, oklch(66% 0.2 25), oklch(60% 0.2 25));
  box-shadow: inset 0 1px 0 oklch(100% 0 0 / 0.3), 0 4px 14px oklch(60% 0.2 25 / 0.3);
}
button:disabled { opacity: 0.5; cursor: default; }
.row { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; }
.row > button { flex: 0 0 auto; }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tabs button { background: transparent; color: var(--muted); border: none; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }

.game-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.7rem; }
.game-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.9rem 1rem;
  border-radius: 15px;
  background: oklch(100% 0 0 / 0.4);
  -webkit-backdrop-filter: saturate(160%) blur(8px);
  backdrop-filter: saturate(160%) blur(8px);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 oklch(100% 0 0 / 0.5);
  text-decoration: none;
  color: inherit;
  transition: transform 120ms cubic-bezier(0.16, 1, 0.3, 1), border-color 120ms, box-shadow 120ms;
}
.game-item:hover { transform: translateX(3px); border-color: var(--accent); }
.game-item.your-turn { border-color: var(--turn); background: oklch(95% 0.06 145 / 0.55); }
.game-item .avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 1.1rem; flex: 0 0 auto;
}
.game-item .who-name { font-weight: 600; }
.game-item .sub { font-size: 0.82rem; color: var(--muted); }
.game-item .badge {
  margin-left: auto; font-size: 0.78rem; font-weight: 700;
  padding: 0.35rem 0.7rem; border-radius: 999px;
  background: oklch(92% 0.01 260); color: var(--muted);
}
.game-item .badge.turn { background: var(--turn); color: oklch(20% 0.05 145); }

.error { color: oklch(55% 0.2 25); font-size: 0.88rem; margin-top: 0.6rem; min-height: 1.2em; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }

/* ---- game layout (board + chat) ---- */
.game-main { max-width: 980px; }
.game-layout {
  display: flex;
  gap: 1.4rem;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---- board ---- */
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 1rem; }

/* ---- chat ---- */
.chat {
  display: flex;
  flex-direction: column;
  width: 320px;
  max-width: 92vw;
  height: calc(var(--bsize) + var(--gutter)); /* match the board + label row */
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
  padding: 1rem;
  margin-top: 2.1rem; /* align with board top, past the status bar */
}
.chat h2 { margin: 0 0 0.6rem; font-size: 1rem; }
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-right: 0.2rem;
}
.chat-empty { color: var(--muted); text-align: center; margin: auto 0; font-size: 0.9rem; }
.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg-who { font-size: 0.68rem; color: var(--muted); margin: 0 0.5rem 1px; }
.msg-body {
  padding: 0.45rem 0.7rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.3;
  word-break: break-word;
}
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.mine .msg-body { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; }
.msg.theirs .msg-body { background: oklch(94% 0.01 260); color: var(--ink); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.chat-input input { flex: 1; min-width: 0; padding: 0.6rem 0.7rem; }
.chat-input button { flex: 0 0 auto; }

@media (max-width: 760px) {
  .chat { width: min(92vw, 520px); height: 300px; margin-top: 0.5rem; }
}
.status-bar {
  display: flex; align-items: center; gap: 0.6rem;
  font-weight: 600; min-height: 1.5em;
}
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.dot.you { background: var(--turn); }
.dot.them { background: var(--accent); }

.board-frame {
  display: grid;
  grid-template-columns: var(--gutter) var(--bsize);
  grid-template-rows: var(--bsize) var(--gutter);
  grid-template-areas: "ranks board" "corner files";
}
.board {
  grid-area: board;
  width: var(--bsize);
  height: var(--bsize);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
  touch-action: manipulation;
  user-select: none;
}
.ranks, .files {
  display: grid;
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 700;
  user-select: none;
}
.ranks { grid-area: ranks; grid-template-rows: repeat(8, 1fr); }
.files { grid-area: files; grid-template-columns: repeat(8, 1fr); }
.ranks span, .files span { display: grid; place-items: center; }
.sq {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  font-size: min(9.5vw, 58px);
  line-height: 1;
  cursor: pointer;
}
.sq.light { background: var(--light-sq); }
.sq.dark  { background: var(--dark-sq); }
.sq.sel::after {
  content: ""; position: absolute; inset: 0; background: var(--sel); mix-blend-mode: multiply;
}
.sq.last::after {
  content: ""; position: absolute; inset: 0; background: var(--last); mix-blend-mode: multiply;
}
.sq.check .piece { filter: drop-shadow(0 0 6px var(--check)); }
.sq .piece { position: relative; z-index: 2; }
.sq .piece.white { color: oklch(99% 0 0); text-shadow: 0 1px 2px oklch(20% 0 0 / 0.55); }
.sq .piece.black { color: oklch(15% 0.01 260); text-shadow: 0 1px 1px oklch(99% 0 0 / 0.35); }
.sq .hint {
  position: absolute; z-index: 1; width: 32%; height: 32%;
  border-radius: 50%; background: var(--hint);
}
.sq .hint.capture {
  width: 92%; height: 92%; background: transparent;
  border: 6px solid var(--hint); box-sizing: border-box;
}
.board.disabled .sq { cursor: default; }

.history {
  font-size: 0.85rem; color: var(--muted);
  max-height: 8rem; overflow-y: auto; line-height: 1.7;
  width: min(92vw, 560px); word-spacing: 0.3rem;
}
.actions { display: flex; gap: 0.6rem; }

dialog {
  border: 1px solid var(--glass-border); border-radius: var(--radius); padding: 1.5rem;
  background: var(--glass-bg-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-highlight), var(--glass-shadow); max-width: 320px;
}
dialog::backdrop { background: oklch(30% 0.05 260 / 0.35); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.promo-row { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1rem; }
.promo-row button { font-size: 2rem; padding: 0.4rem 0.6rem; background: var(--accent-soft); color: var(--ink); }

/* ---- palette picker ---- */
.palette-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.swatch {
  aspect-ratio: 1;
  padding: 0;
  border-radius: 9px;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px oklch(0% 0 0 / 0.08);
  cursor: pointer;
  transition: transform 120ms cubic-bezier(0.16, 1, 0.3, 1), border-color 120ms;
}
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: var(--accent); transform: scale(1.08); }
@media (max-width: 420px) {
  .palette-picker { grid-template-columns: repeat(4, 1fr); }
}

/* ---- scoreboard ---- */
.score-overall { margin-bottom: 0.6rem; }
.score-total { display: flex; gap: 0.5rem; }
.tally, .score-total { font-weight: 700; font-size: 0.95rem; }
.tally span, .score-total span {
  display: inline-block; min-width: 2.4rem; text-align: center;
  padding: 0.2rem 0.5rem; border-radius: 8px; margin-left: 0.3rem;
}
.tally .w, .score-total .w { background: oklch(92% 0.07 145); color: oklch(38% 0.12 145); }
.tally .l, .score-total .l { background: oklch(93% 0.06 25);  color: oklch(45% 0.16 25); }
.tally .d, .score-total .d { background: oklch(92% 0.01 260); color: var(--muted); }
.score-total span { margin-left: 0; }

.score-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.score-list li {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.5rem 0.2rem; border-top: 1px solid oklch(92% 0.01 260);
}
.score-list .opp-name { font-weight: 600; }
.score-list .tally { margin-left: auto; }
.avatar.small { width: 32px; height: 32px; font-size: 0.95rem; }

/* ---- icon button + settings dialog ---- */
.icon-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 1.1rem;
  padding: 0.25rem 0.45rem;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

dialog.settings { max-width: 420px; width: 92vw; }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.dialog-head strong { font-size: 1.05rem; }
.child-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.7rem; }
.child-list li { display: flex; align-items: center; gap: 0.6rem; }
.child-list .opp-name { font-weight: 600; flex: 0 0 auto; min-width: 4rem; }
.child-list .pin-input { flex: 1; min-width: 0; padding: 0.5rem 0.6rem; }
.child-list .reset-pin { flex: 0 0 auto; }
.ok-msg { color: var(--turn); font-size: 0.88rem; margin-top: 0.6rem; min-height: 1.2em; }

/* ---- enable-notifications card ---- */
.push-card { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.push-card #pushText { flex: 1; min-width: 12rem; font-weight: 600; }
.push-card #pushBtn { flex: 0 0 auto; }
.push-status { width: 100%; font-size: 0.85rem; color: var(--muted); min-height: 1em; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
