/* bitdoodle: follows the pixel logo. Two colors (ink + sunflower-stem green), stepped "pixel"
   corners on controls, chunky 3px strokes, plain paper. Text stays in a readable grotesk and
   the color palette keeps smooth corners, so only the logo itself is pixel type.
   No gradients on controls, no emoji, no blur. */

:root {
  --bg: #f2eee5;
  --surface: #e7e1d4;
  --ink: #1d1b17;
  --on-ink: #f7f3ea;
  --muted: #6b6457;
  --cell: #e4ddcf;
  --gridline: #cfc6b4;
  --brand: #3fa34d;       /* logo green: fills, large text */
  --brand-deep: #358c41;  /* hover */
  --brand-text: #2b7a37;  /* small green text on paper, 4.8:1 */
  --on-brand: #14120f;
  --danger: #b8321f;
  --step: 4px;            /* size of one corner "pixel" */
  --font: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --r-sm: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161512; --surface: #221f1b; --ink: #eee8db; --on-ink: #161512;
    --muted: #9d9586; --cell: #2a2723; --gridline: #1b1916;
    --brand: #4cbb5c; --brand-deep: #5fcb6e; --brand-text: #6fd07e; --on-brand: #10120f;
    --danger: #ff7a63;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161512; --surface: #221f1b; --ink: #eee8db; --on-ink: #161512;
  --muted: #9d9586; --cell: #2a2723; --gridline: #1b1916;
  --brand: #4cbb5c; --brand-deep: #5fcb6e; --brand-text: #6fd07e; --on-brand: #10120f;
  --danger: #ff7a63;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(48px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
a { color: inherit; }

/* ---------- pixel corners ----------
   One stepped notch at each corner, cut with clip-path. Outlines get clipped too, so these
   elements show focus and selection with inset shadows instead. */
.btn, .chip, .pick, .gamerow, .invite, .tab, .grid, .thumb, .seatlink {
  clip-path: polygon(
    0 var(--step), var(--step) var(--step), var(--step) 0,
    calc(100% - var(--step)) 0, calc(100% - var(--step)) var(--step), 100% var(--step),
    100% calc(100% - var(--step)), calc(100% - var(--step)) calc(100% - var(--step)),
    calc(100% - var(--step)) 100%, var(--step) 100%, var(--step) calc(100% - var(--step)),
    0 calc(100% - var(--step))
  );
  border-radius: 0;
}
.btn:focus-visible, .chip:focus-visible, .pick:focus-visible, .gamerow:focus-visible,
.tab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--brand);
}

/* ---------- type ---------- */
h1 { font-size: 2rem; line-height: 1.05; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 12px; }
h2 { margin: 0; }
p { margin: 0; }
.g { color: var(--brand); }
.lede { color: var(--muted); font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.pad { padding: 16px 0; }
.stamp {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.label { font-weight: 600; margin-bottom: 8px; }
.error { color: var(--danger); font-weight: 600; font-size: 0.9rem; margin-top: 8px; }
.caption { font-size: 1.15rem; margin-top: 14px; }
.caption strong { color: var(--brand-text); }
.empty { color: var(--muted); padding: 40px 0; font-size: 1.05rem; }

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 28px;
}
.top .stamp { margin-left: auto; }
/* Pixel logo: sunflower + "bitdoodle." on one pixel scale; text baseline meets the stem. */
.wordmark {
  display: inline-flex;
  align-items: flex-end;
  gap: 8px;
  padding: 9px 0; /* keeps the tap target near 44px while staying vertically centered */
  color: var(--ink);
  text-decoration: none;
}
.wordmark svg { display: block; flex-shrink: 0; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
}
.btn.primary { background: var(--brand); color: var(--on-brand); }
.btn.primary:hover:not(:disabled) { background: var(--brand-deep); }
.btn.wide { width: 100%; min-height: 54px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.text { background: none; padding: 0; color: var(--muted); clip-path: none; }
.btn.danger { background: var(--danger); color: var(--on-ink); }
.btn .icon { display: block; flex-shrink: 0; }

.field { display: grid; gap: 4px; margin-bottom: 16px; }
.field span { font-weight: 600; font-size: 0.875rem; color: var(--muted); }
input[type="text"], input:not([type]) {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-bottom: 3px solid var(--gridline);
  border-radius: 0;
  background: transparent;
  padding: 8px 0;
  font-size: 1.1rem;
  outline: none;
}
input:focus { border-bottom-color: var(--brand); }
input::placeholder { color: var(--muted); opacity: 0.7; }

/* ---------- home ---------- */
.hero { margin-bottom: 32px; }
.start { margin-bottom: 40px; }
.games h2 { margin-bottom: 8px; }
.games ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.gamerow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 14px;
  background: var(--surface);
  text-decoration: none;
}
.gname { font-weight: 600; }
.gstatus { text-align: right; flex-shrink: 0; }

/* ---------- game ---------- */
.vs { margin-bottom: 16px; color: var(--muted); }
.vs strong { color: var(--brand-text); }
.invite { background: var(--surface); padding: 16px; margin-bottom: 20px; }
.linkrow { display: flex; gap: 8px; align-items: center; margin: 4px 0 8px; }
.linkrow code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 600 0.9rem/1 var(--font);
}
.linkrow .btn { background: var(--brand); color: var(--on-brand); }

.tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab {
  flex: 1;
  min-height: 44px;
  border: 0;
  background: none;
  font-weight: 600;
  color: var(--muted);
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--on-ink); }
.tab .pip {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 8px;
  vertical-align: 2px;
  background: var(--brand);
}

/* The grid. Editable: cell lines. Display: seamless pixels. */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  width: 100%;
  aspect-ratio: 1;
  background: var(--cell);
  user-select: none;
  -webkit-user-select: none;
}
/* touch-action: none so a finger drag paints instead of scrolling the page. */
.grid.editable { gap: 1px; padding: 1px; background: var(--gridline); touch-action: none; }
.cell { display: block; border: 0; padding: 0; margin: 0; background: var(--cell); min-width: 0; min-height: 0; }
.cell.on { background: var(--c); }
.grid.editable .cell:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; position: relative; z-index: 1; }
.board { margin-bottom: 4px; }

.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 16px 0 20px; }
.swatch {
  aspect-ratio: 1;
  min-height: 36px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
}
.swatch[aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: 2px; }
.send-note { margin-top: 8px; text-align: center; }

/* word pick step */
.pick-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin: 8px 0 16px; }
.wordpick { display: grid; gap: 8px; margin-bottom: 16px; }
.pick {
  min-height: 64px;
  padding: 0 20px;
  border: 0;
  background: var(--surface);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: left;
}
.pick:hover { background: var(--brand); color: var(--on-brand); }

/* draw step */
.drawhead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.drawword { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; color: var(--brand); }
.toolbar { display: flex; align-items: center; gap: 8px; margin: -4px 0 16px; min-height: 44px; }
.confirm-q { font-weight: 600; margin-right: auto; }

.guessrow { display: flex; gap: 10px; align-items: flex-end; margin-top: 20px; }
.guessrow input { flex: 1; min-width: 0; }
.tries { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.tries li { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; }
.shake { animation: shake 0.32s steps(4); }
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) { .shake { animation: none; } }

.result { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- history ---------- */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 28px; }
.history .stamp { margin-bottom: 8px; }
.pairrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: var(--cell);
  image-rendering: pixelated;
}
.nodraw { display: grid; place-items: center; color: var(--muted); font-size: 0.875rem; }
.hcap { margin-top: 6px; font-size: 0.9rem; line-height: 1.3; }
.hcap strong { display: block; color: var(--brand-text); }
.hcap span { color: var(--muted); }

/* ---------- settings ---------- */
.settings { margin-top: 48px; }
.settings summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.settings summary::-webkit-details-marker { display: none; }
.settings[open] summary { color: var(--ink); }
.settings .group { padding: 8px 0 20px; display: grid; gap: 10px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row input { flex: 1; min-width: 0; }
.seatlink { background: var(--surface); padding: 12px; word-break: break-all; font-weight: 600; font-size: 0.875rem; }

/* ---------- notifications ---------- */
.newdot { display: none; width: 8px; height: 8px; background: var(--brand); flex-shrink: 0; }
.gmain { display: grid; gap: 2px; min-width: 0; }
.gname { display: flex; align-items: center; gap: 8px; min-width: 0; }
.gname-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gamerow.has-news .newdot { display: inline-block; }
.gnews { color: var(--brand-text); font-size: 0.875rem; font-weight: 600; line-height: 1.3; }
.gamerow.has-news { box-shadow: inset 4px 0 0 var(--brand); }

.newsbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 10px 10px 14px;
  min-height: 52px;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
  clip-path: polygon(
    0 var(--step), var(--step) var(--step), var(--step) 0,
    calc(100% - var(--step)) 0, calc(100% - var(--step)) var(--step), 100% var(--step),
    100% calc(100% - var(--step)), calc(100% - var(--step)) calc(100% - var(--step)),
    calc(100% - var(--step)) 100%, var(--step) 100%, var(--step) calc(100% - var(--step)),
    0 calc(100% - var(--step))
  );
}
.newsbar .newdot { display: inline-block; background: var(--on-brand); }
.newsbar-text { flex: 1; min-width: 0; }
.newsbar-go { background: var(--on-brand); color: var(--brand); flex-shrink: 0; }
