:root {
  /* Prism: night backgrounds, white daylit walls, cyan / magenta / yellow light */
  --bg: #0e0b1a;
  --bg-glow: #231d3a;
  --panel: #171329;
  --raised: #211c38;       /* menu items, held slot */
  --well: #110e20;         /* tiles, stats, keys: set into a card */
  --line: #2e2848;
  --line-hi: #4a4270;      /* hover */
  --text: #f4f2fb;
  --muted: #a9a3c4;
  --wall: #f4f2fb;
  --wall-2: #cfc9e3;
  --ink: #1d1830;          /* dark text and outlines on the white wall */
  --ink-muted: #5d5a6b;
  --drop: #07050e;         /* the edge under a raised button */
  --cyan: #2fd0e6;
  --magenta: #ff4fa3;
  --yellow: #ffd23f;
  --accent: var(--cyan);
  --success: #5ee6a0;
  --danger: #ff7a8e;
  --title: "Bricolage Grotesque", "Arial Rounded MT Bold", system-ui, sans-serif;
  --body: "Figtree", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, var(--bg-glow) 0%, var(--bg) 75%);
}

#game {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  touch-action: none;
  cursor: pointer;
}

.bar {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
#top { top: 0; padding-top: calc(12px + var(--safe-t)); align-items: stretch; }
#top .counter { margin-left: auto; }
#bottom { bottom: 0; padding-bottom: calc(14px + var(--safe-b)); flex-direction: column; align-items: center; gap: 10px; }
#bottom .buttons { display: flex; gap: 8px; justify-content: center; }
.tip { font-size: 13px; color: var(--muted); text-align: center; min-height: 1em; pointer-events: none; }
.tray { --slot: 64px; height: var(--tray-h, 64px); display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-content: center; align-items: center; max-width: 100%; }
.tray:empty::after { content: "All pieces placed"; font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.slot {
  background: linear-gradient(var(--raised), var(--panel));
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 2px 0 rgba(0, 0, 0, 0.35);
  padding: 0;
  width: var(--slot);
  height: var(--slot);
  flex: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease-out;
}
.slot canvas { display: block; }
/* the piece in hand sits raised, ringed in cyan light */
.slot.held {
  border-color: var(--accent);
  background: linear-gradient(#2b2548, var(--raised));
  box-shadow: 0 0 0 1px var(--accent), 0 0 16px rgba(47, 208, 230, 0.28), 0 5px 0 rgba(0, 0, 0, 0.35);
  transform: translateY(-4px);
}
.slot:hover { border-color: var(--line-hi); }
.slot.held:hover { border-color: var(--accent); }
/* the daily, solved: in the tray's place and height, so the board stays put */
.result { height: var(--tray-h, 64px); display: grid; place-content: center; justify-items: center; gap: 4px; text-align: center; }
.result-time { font-family: var(--mono); font-weight: 700; font-size: 24px; line-height: 1.1; color: var(--success); }
.result-more { font-size: 13px; color: var(--muted); max-width: 26em; text-wrap: balance; }
.slot.spare { opacity: 0.45; cursor: default; border-color: transparent; }   /* left over after a solve */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}
.label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.title .name { font-family: var(--title); font-weight: 700; font-size: 22px; line-height: 1.1; }
.counter { text-align: right; min-width: 104px; }
.counter .label { white-space: nowrap; }
.counter .num { font-family: var(--mono); font-weight: 700; font-size: 21px; line-height: 1.1; }
.counter .par { font-size: 14px; color: var(--muted); margin-left: 4px; }
.counter.done #placed, .counter.done .clock { color: var(--success); }
.clock { font-variant-numeric: tabular-nums; }

.btn {
  font-family: var(--body);
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--line-hi); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
/* the main action: a white wall-colored button on night */
.btn.primary { background: var(--wall); color: var(--ink); border-color: var(--wall); box-shadow: 0 3px 0 var(--wall-2); }
.btn.primary:hover { border-color: var(--wall); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.icon { padding: 0; width: 44px; align-self: stretch; flex: none; color: var(--muted); }
.btn.icon svg { width: 22px; height: 22px; display: block; margin: auto; }
#btn-rotate { font-size: 22px; padding: 6px 12px; }

/* the view switch, on the board between the wall views; a ring and a question until first used */
.view-tool { position: absolute; left: 50%; top: 0; transform: translate(-50%, -50%); display: grid; justify-items: center; pointer-events: none; }
.view-tool > * { pointer-events: auto; }
.view-btn { width: 52px; height: 52px; padding: 0; border-radius: 50%; color: var(--text); }
.view-btn svg { width: 26px; height: 26px; display: block; margin: auto; }
.view-nudge { position: absolute; top: calc(100% + 8px); white-space: nowrap; font-size: 13px; font-weight: 600; color: var(--ink); background: var(--wall); border-radius: 10px; padding: 5px 10px; }
.view-nudge::before { content: ""; position: absolute; left: 50%; top: -5px; margin-left: -5px; border: 5px solid transparent; border-top: 0; border-bottom-color: var(--wall); }
.view-tool.new .view-btn { border-color: var(--cyan); animation: view-ring 1.6s ease-out infinite; }
@keyframes view-ring {
  0% { box-shadow: 0 0 0 0 rgba(47, 208, 230, 0.6); }
  100% { box-shadow: 0 0 0 14px rgba(47, 208, 230, 0); }
}
@media (prefers-reduced-motion: reduce) { .view-tool.new .view-btn { animation: none; box-shadow: 0 0 0 3px rgba(47, 208, 230, 0.5); } }

.stars { font-size: 15px; letter-spacing: 3px; color: var(--yellow); line-height: 1; margin-top: 2px; }
.stars:empty { display: none; }
.stars .off { color: var(--line-hi); }
.label.good { color: var(--success); }
.label.warn { color: var(--yellow); }

/* ---------------------------------------------------------------- title button */

button.panel.title { text-align: left; color: var(--text); font: inherit; cursor: pointer; min-width: 0; }
button.panel.title:hover { border-color: var(--line-hi); }
.title .name { display: flex; align-items: center; gap: 6px; }
.title .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title .chev { width: 14px; height: 14px; color: var(--muted); flex: none; }

/* ---------------------------------------------------------------- screens: one card over the dimmed board */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: calc(16px + var(--safe-t)) 16px calc(20px + var(--safe-b));
  background: rgba(14, 11, 26, 0.74);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
#screen-title { background: rgba(14, 11, 26, 0.55); }
.overlay > .card { margin: auto; flex: none; }
.card {
  width: min(100%, 440px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  animation: rise 0.3s cubic-bezier(.3, 1.3, .5, 1);
}
@keyframes rise { from { transform: translateY(16px) scale(0.97); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } }
.card h2 { font-family: var(--title); font-weight: 800; font-size: 26px; line-height: 1.1; letter-spacing: -0.01em; margin: 0; color: var(--text); }
.card p { margin: 8px 0; font-size: 15px; line-height: 1.45; }
.card p b, .how b { color: var(--text); font-weight: 700; }

.card-nav { display: flex; margin: -6px -6px 10px; }
.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 12px 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--well);
  font: 600 14px var(--body);
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.nav-back:hover { border-color: var(--line-hi); color: var(--text); }
.nav-back svg { width: 18px; height: 18px; }
.nav-back .i-back, .nav-back.to-game .i-home { display: none; }
.nav-back.to-game .i-back { display: block; }

/* the title card: the wordmark on a white wall, its letters casting cyan, magenta and yellow shadows */
.title-card { text-align: center; padding: 16px 16px 20px; }
.logo { font-family: var(--title); font-weight: 800; font-size: 30px; line-height: 1; letter-spacing: -0.02em; color: var(--text); }
.plate {
  display: grid;
  place-items: center;
  padding: 26px 12px 34px;
  border-radius: 12px;
  background: linear-gradient(160deg, #ffffff 0%, var(--wall) 55%, #e9e5f6 100%);
  box-shadow: inset 0 -2px 0 var(--wall-2);
}
.wordmark { position: relative; font: 800 clamp(42px, 14vw, 64px)/1 var(--title); letter-spacing: -0.02em; }
.wordmark span { display: block; }
.wordmark .s { position: absolute; inset: 0; mix-blend-mode: multiply; transform: var(--to); }
.wordmark .cy { color: var(--cyan); --to: translate(-0.11em, 0.09em); }
.wordmark .mg { color: var(--magenta); --to: translate(0.11em, 0.09em); }
.wordmark .ye { color: var(--yellow); --to: translate(0, 0.16em); }
.wordmark .top { position: relative; color: #fff; -webkit-text-stroke: 0.05em var(--ink); paint-order: stroke fill; }
/* on load the three shadows slide out from behind the letters, once */
@media (prefers-reduced-motion: no-preference) {
  .wordmark .s { animation: cast 0.9s cubic-bezier(.2, .8, .3, 1) 0.25s backwards; }
  @keyframes cast { from { transform: translate(0, 0); } }
}
.title-card .tagline { color: var(--text); font-weight: 600; margin: 14px auto 0; max-width: 360px; }
.menu { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--drop);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s;
}
.menu-item:hover { border-color: var(--line-hi); }
.menu-item:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--drop); }
.menu-item.primary { background: var(--wall); border-color: var(--wall); color: var(--ink); box-shadow: 0 4px 0 var(--wall-2); }
.menu-item.primary:active { box-shadow: 0 1px 0 var(--wall-2); }
.menu-item.primary small, .menu-item.primary .mi-side { color: var(--ink-muted); }
.mi-icon { width: 30px; height: 30px; flex: none; color: var(--accent); }
.mi-icon.q { display: grid; place-items: center; width: 26px; height: 26px; border: 2px solid currentColor; border-radius: 50%; font: 700 15px var(--body); }
.mi-text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.2; }
.mi-text b { font-size: 18px; font-weight: 700; }
.mi-text small { font-size: 13px; color: var(--muted); margin-top: 2px; }
.mi-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; font: 700 14px var(--body); white-space: nowrap; }
.mi-side .stars { margin: 0; }
.mi-note { font: 500 11px var(--mono); letter-spacing: 0.04em; color: var(--muted); }
.mi-note:empty { display: none; }
.menu-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-item.small { min-height: 52px; gap: 8px; padding: 8px 10px; justify-content: center; }
.menu-item.small .mi-text { flex: none; }
.menu-item.small .mi-text b { font-size: 15px; }

/* avatar: the player's initial, or a head-and-shoulders silhouette for a guest */
.avatar {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 50%;
  background: var(--raised);
  color: var(--accent);
  font: 800 30px var(--title);
  box-shadow: inset 0 0 0 2px var(--line-hi);
  overflow: hidden;
}
.avatar svg { width: 100%; height: 100%; display: block; }
.avatar.small { width: 26px; height: 26px; font-size: 14px; }

/* puzzles: level select */
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.section { margin: 14px 0 8px; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tile {
  font: inherit;
  color: var(--text);
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 0 6px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.tile .num { font-family: var(--title); font-weight: 700; font-size: 18px; line-height: 1; }
.tile .stars { font-size: 11px; letter-spacing: 1px; }
.tile.done { background: var(--raised); }
.tile.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tile:hover { border-color: var(--line-hi); }

/* profile */
.pf-top { display: flex; gap: 14px; align-items: center; }
.pf-who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pf-who b { font-family: var(--title); font-weight: 800; font-size: 24px; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-who span { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.pf-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 16px; }
.pf-stats div { background: var(--well); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.pf-stats b { display: block; font-family: var(--mono); font-weight: 700; font-size: 21px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pf-stats b small { font-size: 14px; color: var(--muted); margin-left: 3px; }
.pf-stats span { font: 500 11px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; font-weight: 600; }
.setting-row small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.switch {
  position: relative;
  width: 52px;
  height: 30px;
  flex: none;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.15s;
}
.switch span { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(22px); background: var(--ink); }

/* how to play */
.help-card p { color: var(--muted); }
.how { margin: 10px 0; padding-left: 20px; font-size: 15px; line-height: 1.45; color: var(--muted); }
.how li { margin: 6px 0; }
.stars.inline { display: inline; font-size: inherit; letter-spacing: 1px; }
kbd { font: 500 12px var(--mono); color: var(--text); background: var(--well); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; }
@media (hover: none) { .keys { display: none; } }

/* iOS app, on a solved level: the reminder ask and the coming ad break */
.extras { display: grid; gap: 8px; justify-items: center; }
.extras:not(:has(> :not([hidden]))) { display: none; }
.nudge { width: min(100%, 440px); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; text-align: center; font-size: 14px; }
.nudge p { margin: 0; }
.nudge-actions { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.setting-note { margin: -4px 0 8px; font-size: 13px; color: var(--muted); }

/* wide, short screens: the tray sits beside the buttons in one row, so the board keeps its scale */
@media (min-aspect-ratio: 5/4) {
  #bottom { flex-direction: row; justify-content: center; align-items: center; gap: 16px; padding-top: 6px; padding-bottom: calc(8px + var(--safe-b)); }
  #bottom .tip { position: absolute; bottom: 100%; left: 0; right: 0; }
  #bottom .extras { position: absolute; bottom: calc(100% + 24px); left: 16px; right: 16px; }
}

/* ---------------------------------------------------------------- account panel */

.account { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.profile-card .section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.account-line { margin: 0; color: var(--muted); font-size: 14px; }
.account-line b { color: var(--text); font-weight: 600; }
.account-error { margin: 0; color: var(--danger); font-size: 14px; }
.account-google { min-height: 44px; }
.account-native { display: grid; gap: 10px; width: min(100%, 280px); }
/* Native sign-in (iOS app): Apple's white button and Google's dark one, for a dark background. */
.signin-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; border-radius: 22px; font: 600 16px/1 -apple-system, system-ui, sans-serif; cursor: pointer;
}
.signin-btn.apple { background: #fff; color: #000; border: 0; }
.signin-btn.google { background: #131314; color: #e3e3e3; border: 1px solid #8e918f; }
.signin-logo { display: inline-flex; font-size: 19px; line-height: 1; }
.signin-logo svg { width: 18px; height: 18px; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.card .fine { margin: 14px 0 0; font-size: 12px; }
.fine a { color: var(--muted); }
