/* Teahouse: the shelf of an old tea house after closing. A lamplit cabinet of dark polished wood in
   front of glowing paper screens, a hanging scroll above it, a teapot steaming on the counter. The
   room and the vessels are drawn on the canvas (script.js); this sheet styles what sits over it. */
@import url("https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@600;700;800&family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap");

*, *::before, *::after { box-sizing: border-box; }

:root {
  --lacquer: #1a0e08;
  --gold: #e3b866;
  --gold-hi: #f8e2ae;
  --gold-lo: #8a6226;
  --paper: #f3e3c3;          /* lamplit paper, for text on the dark */
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  /* shared toy chrome (assets/toy-chrome.css): lamp gold on the dark of a lacquered tray */
  --tc-accent: #e3b866;
  --tc-on: #2a1607;
  --tc-display: var(--mincho);
  --tc-ground: #140a06;
}

html, body {
  -webkit-tap-highlight-color: transparent;
  margin: 0; height: 100%; overflow: hidden;
  background: #120a06;
  font-family: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: none; overscroll-behavior: none;
}

#canvas {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
  cursor: pointer; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  touch-action: none; outline: none;
}

/* ---------- HUD: a lacquered tablet with gold-leaf figures ---------- */
.hud {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left));
  z-index: 5; display: inline-flex; align-items: stretch; pointer-events: none;
}
html.tc .hud.hud {
  padding: 4px; gap: 4px; border-radius: 12px;
  background: linear-gradient(180deg, #3b2213 0%, #24130a 55%, #170c06 100%);
  border: 1px solid rgba(227, 184, 102, 0.42);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 12px 26px -12px rgba(0, 0, 0, 0.95), inset 0 1px 0 rgba(255, 220, 160, 0.16);
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
.hud__cell {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: 5px 12px 6px; border-radius: 8px;
  background: radial-gradient(130% 150% at 30% 0%, #1f120b 0%, #0d0705 75%);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.8), inset 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.hud__cell--score { min-width: 136px; }
.hud__cell--moves { align-items: center; min-width: 64px; }
html.tc .hud .hud__k { font-size: 8.5px; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(227, 184, 102, 0.62); line-height: 1.3; }
.hud__v {
  font: 700 22px/1.08 var(--mincho); letter-spacing: 0.01em; font-variant-numeric: tabular-nums;
  background-image: linear-gradient(178deg, #fff3d2 0%, #f0cd85 45%, #c48d3c 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
}
.hud__bar {
  position: relative; display: block; width: 100%; height: 4px; margin-top: 4px; border-radius: 2px;
  background: rgba(227, 184, 102, 0.14); overflow: hidden;
}
.hud__bar i {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 2px;
  background: linear-gradient(90deg, #9c6a24, #f2cf7e);
  box-shadow: 0 0 6px rgba(242, 207, 126, 0.6);
  transition: width 360ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
.hud__bar.is-met i { background: linear-gradient(90deg, #4f9a72, #b9f0cf); box-shadow: 0 0 6px rgba(150, 230, 190, 0.6); }
.hud__t { margin-top: 3px; font: 500 9.5px/1.2 "Geist Mono", ui-monospace, Menlo, monospace; letter-spacing: 0.06em; color: rgba(243, 227, 195, 0.55); }
.hud__t.is-met { color: #b9f0cf; }
.hud__cell--moves .hud__v { font-size: 26px; }
.hud__cell--moves.is-low .hud__v { background-image: linear-gradient(178deg, #fff0e2 0%, #ffb28a 45%, #e0603c 100%); }
.hud__cell--moves.tick .hud__v { animation: tick 320ms ease-out; }
@keyframes tick { 0% { transform: scale(1.22); } 100% { transform: scale(1); } }

/* ---------- top buttons: lacquer with a gold edge ---------- */
.topbtns {
  position: fixed; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  z-index: 6; display: inline-flex; align-items: center; gap: 8px;
}
.pill, .iconbtn {
  appearance: none; font-family: inherit; cursor: pointer;
  border: 1px solid rgba(227, 184, 102, 0.55);
  background: linear-gradient(180deg, #2c180d 0%, #160b06 100%);
  color: var(--gold-hi);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 220, 160, 0.14), 0 8px 18px -10px rgba(0, 0, 0, 0.9);
  transition: border-color 140ms ease, color 140ms ease, transform 120ms ease, box-shadow 140ms ease;
}
.pill { height: 38px; padding: 0 16px; border-radius: 10px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.iconbtn { width: 38px; height: 38px; border-radius: 50%; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; }
.pill:hover, .iconbtn:hover { border-color: var(--gold-hi); color: #fff4da; }
.pill:active, .iconbtn:active { transform: translateY(1px); }
.pill:focus-visible, .iconbtn:focus-visible { outline: none; box-shadow: 0 0 0 2px #120a06, 0 0 0 4px var(--gold-hi); }
.iconbtn[aria-pressed="false"] { color: rgba(248, 226, 174, 0.32); }

/* ---------- overlay: the card over the dimmed room ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 42%, rgba(18, 10, 6, 0.42), rgba(8, 4, 2, 0.84));
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  transition: opacity 280ms ease;
}
.overlay[hidden] { display: none; }
.overlay.is-hidden { opacity: 0; pointer-events: none; }
.panel { animation: pop 340ms cubic-bezier(0.2, 0.9, 0.25, 1) both; }
@keyframes pop { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
/* a lacquer tray: a fine gold line inside the edge */
html.tc .overlay .panel.panel {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), 0 26px 70px rgba(0, 0, 0, 0.62),
    0 0 80px rgba(227, 160, 80, 0.12),
    inset 0 0 0 5px color-mix(in srgb, var(--tc-accent) 12%, var(--tc-ground) 88%),
    inset 0 0 0 6px rgba(227, 184, 102, 0.28);
}
html.tc .overlay .panel__title {
  font-weight: 800; letter-spacing: 0.01em; font-size: clamp(38px, 11vw, 50px); line-height: 1.04;
  padding-bottom: 2px;
  background-image: linear-gradient(176deg, #fff4d6 0%, #f2d089 40%, #c4903e 74%, #8c6224 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
  filter: drop-shadow(0 3px 16px rgba(220, 160, 80, 0.26));
}
html.tc .overlay .panel__title.is-met {
  background-image: linear-gradient(176deg, #f2fff8 0%, #bdeed3 40%, #5fb68c 74%, #2c7a58 100%);
  filter: drop-shadow(0 3px 16px rgba(110, 210, 160, 0.3));
}
.panel__text .newbest { color: #bdeed3; font-weight: 600; }
.panel__text .tier { color: var(--gold-hi); font-weight: 600; }

/* the three special pieces, as glaze swatches */
.panel__specials {
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  margin: -6px auto 18px; padding: 10px 12px; max-width: 300px; text-align: left;
  border: 1px solid rgba(227, 184, 102, 0.18); border-radius: 12px; background: rgba(0, 0, 0, 0.18);
  font: 500 12px/1.35 var(--tc-body, "Geist", sans-serif); color: rgba(243, 227, 195, 0.78);
}
.panel__specials span { display: flex; align-items: center; gap: 9px; }
.panel__specials[hidden] { display: none; }
.sw { flex: none; width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.sw--gold { background: radial-gradient(circle at 35% 30%, #fff1c4, #e3b866 45%, #7d5418 100%); box-shadow: 0 0 6px rgba(255, 207, 106, 0.7); }
.sw--crackle {
  background:
    linear-gradient(35deg, transparent 46%, rgba(60, 30, 10, 0.75) 48%, transparent 51%),
    linear-gradient(-60deg, transparent 44%, rgba(60, 30, 10, 0.7) 46%, transparent 49%),
    linear-gradient(100deg, transparent 58%, rgba(60, 30, 10, 0.6) 60%, transparent 63%),
    radial-gradient(circle at 35% 30%, #fff1dc, #e8c9a0 55%, #a8743c 100%);
  box-shadow: 0 0 6px rgba(255, 154, 74, 0.7);
}
.sw--jade { background: radial-gradient(circle at 35% 30%, #e8fff2, #6fd4a0 45%, #1f6e4a 100%); box-shadow: 0 0 6px rgba(125, 255, 192, 0.7); }

/* ---------- frame + hint ---------- */
.frame { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.frame__corner {
  position: absolute; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(243, 227, 195, 0.5);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
.frame__corner--tl { display: none; } /* top-left holds the score tablet */
.frame__corner--tr { display: none; } /* top-right holds the buttons */
.frame__corner--bl { bottom: max(14px, calc(env(safe-area-inset-bottom) + 4px)); left: max(16px, env(safe-area-inset-left)); }
.frame__corner a { color: inherit; text-decoration: none; pointer-events: auto; }
.frame__corner a:hover { color: var(--gold-hi); }
.frame__corner a:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 3px; border-radius: 3px; }

.hint {
  position: fixed; bottom: max(15px, calc(env(safe-area-inset-bottom) + 4px)); left: 50%; transform: translateX(-50%); z-index: 4; margin: 0;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; color: rgba(243, 227, 195, 0.66);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
  pointer-events: none; white-space: nowrap; transition: opacity 300ms ease; max-width: 92vw; text-align: center;
}
.hint.is-gone { opacity: 0; }

/* phones: the back link keeps its corner and the hint rides one line above it */
@media (max-width: 620px) {
  .hint { font-size: 0.68rem; letter-spacing: 0.02em; bottom: calc(max(14px, calc(env(safe-area-inset-bottom) + 4px)) + 22px); }
}

/* the shared tip-jar / fullscreen badges dock bottom-right so they never sit over the shelf */
.opt-tipjar.opt-tipjar { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: none; }
.opt-fs.opt-fs { top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 54px); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge { animation: none; }

/* ---------- short landscape (a phone on its side, 874 x 402) ----------
   The tablet and the buttons stand in columns at the two sides so the cabinet takes the full height;
   the card goes two columns, words on the left, the swatches and the button on the right. */
@media (orientation: landscape) and (max-height: 500px) {
  html.tc .hud.hud {
    top: 50%; transform: translateY(-50%); flex-direction: column;
    left: max(12px, env(safe-area-inset-left));
  }
  .hud__cell--moves { align-items: flex-start; }
  .topbtns {
    top: 50%; transform: translateY(-50%); flex-direction: column; align-items: stretch;
    right: max(12px, env(safe-area-inset-right));
  }
  .iconbtn { align-self: center; }
  html.tc #overlay > .panel.panel {
    width: min(100%, 660px); max-width: 660px; padding: 16px 24px 14px; text-align: left;
    display: grid; grid-template-columns: 1.1fr 1fr; column-gap: 26px; align-content: start; grid-auto-flow: dense;
  }
  html.tc #overlay > .panel > * { grid-column: 2; }
  html.tc #overlay > .panel > .panel__lede { grid-column: 1; grid-row: 1 / span 12; }
  html.tc #overlay > .panel > .play-btn { max-width: none; margin: 4px 0 0; }
  html.tc .overlay .panel__title { font-size: 40px; margin-bottom: 6px; }
  html.tc #overlay .panel__text { margin-bottom: 4px; }
  /* in two columns the swatches move to the right, above the button */
  html.tc #overlay .panel__specials { margin: 0 0 10px; max-width: none; padding: 7px 10px; gap: 3px; font-size: 11.5px; }
  html.tc #overlay .panel__keys { margin-top: 8px; }
  html.tc #overlay .panel .mg { margin-top: 10px; }
  html.tc #overlay .panel .opt-share { margin-top: 10px; }
  .hint { bottom: max(10px, calc(env(safe-area-inset-bottom) + 2px)); }
}

/* the keyboard line is for keyboards; phones have the hint at the foot of the screen */
@media (pointer: coarse) {
  html.tc #overlay .panel__keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .panel { animation: none; }
  .overlay, .hint, .hud__bar i { transition: none; }
  .hud__cell--moves.tick .hud__v { animation: none; }
}
