:root {
  --snow: #e9f0f8;
  --ink: #2c3e55;
  --ink-soft: #5d7391;
  --warm: #f2b94b;
  --safe-top: env(safe-area-inset-top, 0px);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(230, 238, 247, 0.35);
  transition: opacity 0.35s ease, visibility 0s;
  z-index: 5;
}
/* hidden panels fade out, then become invisible to Tab too (older browsers lack inert) */
.panel.hidden { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity 0.35s ease, visibility 0s 0.35s; }
.hidden { display: none; }
.panel.hidden { display: flex; }

.card {
  padding: 20px 24px 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 40px rgba(60, 90, 140, 0.18);
}
.card h1 { margin: 0 0 2px; font-size: 26px; letter-spacing: 0.3px; }
.card .sub { margin: 0 0 12px; color: var(--ink-soft); font-size: 14px; }
.card .controls { margin: 10px 0 8px; font-size: 13px; line-height: 1.45; color: var(--ink-soft); }
.card .go {
  margin: 8px 0 0;
  font-size: 14px;
  color: #b07a1c;
  animation: pulse 2.2s ease-in-out infinite;
}
.card .go.hidden { display: none; }
@keyframes pulse { 50% { opacity: 0.45; } }

.board-card {
  display: flex;
  flex-direction: column;
  width: min(600px, 100%);
  max-height: 100%;
  box-sizing: border-box;
}
.board-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.board-head .titles { min-width: 0; }
.board-head .sub { margin-bottom: 8px; }
.head-right { display: flex; align-items: center; gap: 8px; flex: none; }

.icon-btn, .pause-btn {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%;
  background: #eef3f9; color: var(--ink-soft); cursor: pointer;
}
.icon-btn svg, .pause-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.icon-btn:hover { color: var(--ink); }

.purse {
  display: flex; align-items: center; gap: 6px; flex: none;
  padding: 5px 12px 5px 9px; border-radius: 999px;
  background: #fff4d6; color: #7a4f0c; font-size: 17px;
}
.coin {
  display: inline-block; flex: none; width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff0c2 0 18%, #f6c453 40%, #d9971f 100%);
  box-shadow: inset 0 0 0 1.4px #c98a1e;
  vertical-align: -2px;
}

.tabs { display: flex; gap: 3px; margin: 2px 0 12px; padding: 3px; background: #eef3f9; border-radius: 12px; }
.tabs button {
  position: relative; flex: 1; padding: 7px 2px; border: 0; border-radius: 9px;
  font: inherit; font-size: 14px; color: var(--ink-soft); background: transparent; cursor: pointer;
}
.tabs button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px rgba(60, 90, 140, 0.15); }
.tabs button.dot::after {
  content: ''; position: absolute; top: 5px; right: 7px; width: 7px; height: 7px; border-radius: 50%;
  background: #e8a21f; box-shadow: 0 0 0 2px #eef3f9;
}

.tab-body { position: relative; min-height: 0; }
.tab { height: var(--tab-h, 420px); overflow-y: auto; overscroll-behavior: contain; }
.tab.hidden { display: none; }
.tab-post { display: flex; gap: 18px; align-items: flex-start; }
.tab-post canvas { flex: none; border-radius: 12px; box-shadow: inset 0 0 0 1px rgba(120,145,185,0.25); }
.board-side { min-width: 0; flex: 1; }
.mtn-seg { margin: 0 0 8px; }
.mtn-seg.hidden { display: none; }
.seg.mtn-seg button { flex: 1; min-width: 0; padding: 6px 3px; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.letters > li.mtn-head { padding: 14px 0 4px; font-size: 12px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--ink-soft); border-bottom: none; }
.daily { margin: 0 0 10px; padding: 9px 11px 10px; border-radius: 12px; background: linear-gradient(135deg, #fff6e3, #fdeee8); box-shadow: inset 0 0 0 1px rgba(217,151,31,0.25); }
.daily-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
.daily-head b, .daily-head small { white-space: nowrap; }
.daily-head b { font-size: 14.5px; color: #7a4f0c; }
.daily-head b::before { content: '\1F4EE  '; }
.daily-head small { margin-left: auto; font-size: 12px; color: #a0773a; }
.daily-info { margin: 3px 0 7px; font-size: 12.5px; line-height: 1.35; color: #8a6a3a; }
.daily-btns { display: flex; gap: 6px; }
.daily-btns button { flex: 1; padding: 6px 8px; border: 0; border-radius: 9px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.daily-btns .hidden { display: none; }
.daily.on { background: linear-gradient(135deg, #ffefc6, #ffe3d6); box-shadow: inset 0 0 0 2px rgba(217,151,31,0.55); }
.share-btn { display: block; width: 100%; margin: 0 0 10px; padding: 8px; border: 0; border-radius: 11px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.share-btn.hidden { display: none; }

.board-msg {
  margin: 10px 0 0; padding: 8px 12px; border-radius: 12px;
  background: #e8f4ea; color: #2f6b3d; font-size: 14px;
}
.board-msg.hidden { display: none; }
.board-foot { margin-top: 12px; }
.warn { margin: 0 0 8px; font-size: 12.5px; color: #a0522d; }
.warn.hidden { display: none; }

.go-btn {
  display: block; width: 100%; padding: 12px; border: 0; border-radius: 14px;
  font: inherit; font-size: 17px; font-weight: 600; color: #fff; background: #3f6e9a;
  box-shadow: 0 4px 0 #2f5579; cursor: pointer;
}
.go-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #2f5579; }
.go-btn.hidden { display: none; }
.go-btn .key {
  margin-left: 6px; padding: 1px 6px; border: 1px solid rgba(255,255,255,0.5); border-radius: 5px;
  font-size: 12px; font-weight: 500; opacity: 0.8; vertical-align: 1px;
}

/* Pause / settings menu (above the board and summary) */
#menu { z-index: 8; background: rgba(40, 60, 90, 0.25); }
.menu-card { width: min(360px, 100%); max-height: 100%; overflow-y: auto; box-sizing: border-box; }
.menu-card h1 { margin-bottom: 10px; }
.settings { margin: 0 0 14px; }
.set {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px;
  border-bottom: 1px solid rgba(120,145,185,0.15); font-size: 15px;
}
.set.hidden { display: none; }
.set input[type=range] { flex: 1; max-width: 180px; accent-color: #3f6e9a; height: 28px; }
.switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 46px; height: 28px; margin: 0;
  border-radius: 14px; background: #cfd9e6; cursor: pointer; transition: background 0.2s ease;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(40,60,90,0.3); transition: transform 0.2s ease;
}
.switch:checked { background: #3f6e9a; }
.switch:checked::after { transform: translateX(18px); }
.switch:focus-visible, .seg button:focus-visible { outline: 2px solid #3f6e9a; outline-offset: 2px; }
.seg { display: flex; gap: 3px; padding: 3px; background: #eef3f9; border-radius: 10px; }
.seg button {
  padding: 6px 12px; border: 0; border-radius: 8px; font: inherit; font-size: 14px;
  color: var(--ink-soft); background: transparent; cursor: pointer;
}
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px rgba(60, 90, 140, 0.15); }
.touch-only { display: none; }
.start-over { margin: 0 0 14px; }
.start-over.hidden { display: none; }
.link-btn { padding: 4px 0; border: 0; font: inherit; font-size: 14px; color: #a0522d; background: none; cursor: pointer; }
.link-btn.hidden { display: none; }
.link-btn.home-link { color: #3f6e9a; font-weight: 600; }
.confirm.home { background: #eef3f9; }
.confirm.home p { color: var(--ink); }
.primary-btn { color: #fff; background: #3f6e9a; }
.confirm { padding: 10px 12px; border-radius: 12px; background: #fdf1ea; }
.confirm.hidden { display: none; }
.confirm p { margin: 0 0 10px; font-size: 14px; line-height: 1.4; color: #7a3d1f; }
.confirm-btns { display: flex; gap: 8px; }
.confirm-btns button {
  flex: 1; padding: 9px 6px; border: 0; border-radius: 10px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.soft-btn { color: var(--ink); background: #fff; box-shadow: inset 0 0 0 1px #cfd9e6; }
.danger-btn { color: #fff; background: #b5523b; }

.pause-btn {
  position: fixed; z-index: 4;
  top: calc(var(--safe-top) + 62px);
  right: max(12px, env(safe-area-inset-right));
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 10px rgba(60, 90, 140, 0.15);
}
.pause-btn.hidden { display: none; }

/* Projects */
.shop { list-style: none; margin: 0; padding: 0; }
.shop li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid rgba(120,145,185,0.15); }
.shop li:last-child { border-bottom: none; }
.shop .what { flex: 1; min-width: 0; }
.shop .what b { display: block; font-size: 15px; }
.shop .what span { display: block; font-size: 13px; color: var(--ink-soft); }
.shop .what .more { color: #b07a1c; margin-top: 2px; }
.shop li.done { opacity: 0.6; }
.shop li.waiting { opacity: 0.6; }
.done-tag { font-size: 13px; color: #4f8f5d; font-weight: 600; }
.done-tag::before { content: '\2713  '; }
.buy {
  display: flex; align-items: center; gap: 5px; flex: none; padding: 7px 12px; border: 0; border-radius: 10px;
  font: inherit; font-size: 15px; font-weight: 600; color: #5a3a08; background: #f6c453;
  box-shadow: 0 3px 0 #d9971f; cursor: pointer; white-space: nowrap;
}
.buy:active { transform: translateY(2px); box-shadow: 0 1px 0 #d9971f; }
.buy:disabled { color: var(--ink-soft); background: #eef3f9; box-shadow: none; cursor: default; transform: none; }
.buy:disabled .coin { filter: grayscale(1); opacity: 0.6; }

/* Wardrobe */
.wardrobe { display: flex; gap: 16px; align-items: flex-start; }
#lookCanvas { flex: none; width: 120px; height: 170px; border-radius: 14px; background: linear-gradient(#e3ebf5, #f6f9fc); }
.wardrobe-rows { flex: 1; min-width: 0; }
.wrow h3 { margin: 2px 0 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; color: var(--ink-soft); }
.wrow + .wrow { margin-top: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  position: relative; width: 44px; height: 44px; padding: 2px; border: 2px solid transparent; border-radius: 12px;
  background: #f1f5fa; cursor: pointer;
}
.swatch canvas { display: block; }
.swatch.on { border-color: #3f6e9a; background: #fff; }
.swatch.sel:not(.on) { border-color: #b8c7da; }
.swatch.locked canvas { opacity: 0.35; filter: grayscale(0.7); }
.swatch .tag {
  position: absolute; right: -5px; bottom: -5px; min-width: 14px; padding: 0 4px; border-radius: 7px;
  font-size: 10.5px; font-weight: 700; line-height: 15px; color: #5a3a08; background: #f6c453;
}
.swatch .tag.gift { color: #fff; background: #8aa0bd; }
.wdetail { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-height: 38px; margin-top: 12px; font-size: 14px; }
.soft { color: var(--ink-soft); font-size: 13px; }

/* Letters (the tab, and notes on the summary) */
.letters { list-style: none; margin: 0; padding: 0; }
.letters > li { padding: 10px 0; border-bottom: 1px solid rgba(120,145,185,0.15); }
.letters > li:last-child { border-bottom: none; }
.letters > li.unknown { opacity: 0.5; }
.who { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.who img { width: 22px; height: 22px; flex: none; }
.who b { flex: 1; min-width: 0; font-weight: 600; }
.who small { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.letters .about { margin: 2px 0 0 30px; font-size: 13px; color: var(--ink-soft); }
.letters .letter { margin-left: 30px; }
.letter {
  margin: 8px 0 0; padding: 9px 12px 8px; border-radius: 10px; border-left: 4px solid var(--accent, #8aa0bd);
  background: #fffaf0; text-align: left;
}
.letter-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 14px; }
.letter-head img { width: 20px; height: 20px; }
.letter-head small { margin-left: auto; color: var(--ink-soft); font-size: 12px; }
.letter-text { margin: 0; font-size: 14.5px; line-height: 1.45; font-style: italic; color: #3a4a60; }
.sign { margin: 3px 0 0; text-align: right; font-size: 13px; color: var(--ink-soft); }
.gift {
  display: flex; align-items: center; gap: 8px; margin-top: 6px; padding-top: 6px;
  border-top: 1px dashed rgba(120,145,185,0.35); font-size: 13.5px; color: #7a4f0c;
}
.gift span { flex: 1; }
.wear {
  flex: none; padding: 5px 10px; border: 0; border-radius: 8px; font: inherit; font-size: 13px; font-weight: 600;
  color: #fff; background: #3f6e9a; cursor: pointer;
}
.wear:disabled { color: #4f8f5d; background: transparent; cursor: default; }

.sum-card { max-width: 400px; width: 100%; max-height: 100%; overflow-y: auto; text-align: center; box-sizing: border-box; }
.sum-card .plist { text-align: left; }
/* the lift button stays in view while notes scroll under it */
.sum-card .go-btn { position: sticky; bottom: 0; z-index: 1; margin-top: 14px; box-shadow: 0 4px 0 #2f5579, 0 10px 0 6px #fff, 0 -8px 12px 4px rgba(255,255,255,0.95); }
.sum-card .go-btn:active { box-shadow: 0 2px 0 #2f5579, 0 10px 0 6px #fff, 0 -8px 12px 4px rgba(255,255,255,0.95); }
.hint { margin: 12px 0 0; font-size: 14px; color: var(--ink-soft); }
.hint:empty { display: none; }
.plist .area .coin { width: 12px; height: 12px; margin-right: 4px; vertical-align: -1px; }
.plist li.done .area { color: #8a5a10; font-weight: 600; }
.plist li.bonus .name { color: #8a5a10; }
.plist li.total { border-top: 1.5px solid rgba(120,145,185,0.3); font-weight: 600; }
.plist li.total .area { color: #7a4f0c; font-size: 14px; }

.plist { list-style: none; margin: 0; padding: 0; }
.plist li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 15px;
  border-bottom: 1px solid rgba(120,145,185,0.15);
}
.plist li:last-child { border-bottom: none; }
.plist img { width: 22px; height: 22px; flex: none; }
.plist .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .area { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.plist li.waiting { opacity: 0.55; }
.plist li.done .area { color: #4f8f5d; }
.plist .area.again { color: #b07a1c; }
.ptype { flex: none; padding: 1px 7px; border-radius: 8px; font-size: 11.5px; font-weight: 700; color: #fff; background: var(--accent, #8aa0bd); cursor: help; }
.board-types { margin: 6px 0 0; font-size: 12.5px; line-height: 1.4; color: var(--ink-soft); }

@media (max-width: 520px) {
  .card { padding: 16px 16px 14px; }
  .card h1 { font-size: 22px; }
  .tab-post { gap: 12px; }
  .plist li { font-size: 14px; }
  .tab-post .plist .area { display: none; }
  .tab-post .plist .area.again { display: inline; }
  .tabs button { font-size: 13px; }
  .purse { font-size: 15px; padding: 4px 10px 4px 8px; }
  .wardrobe { flex-direction: column; align-items: center; gap: 10px; }
  #lookCanvas { width: 100px; height: 132px; }
  .wardrobe-rows { width: 100%; }
}
@media (max-height: 520px) {
  .card h1 { font-size: 20px; }
  .board-head .sub { display: none; }
  .tabs { margin-bottom: 8px; }
  .go-btn { padding: 9px; }
}

.controls.touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .controls.touch { display: block; }
  .touch-only { display: flex; }
  .controls.desktop { display: none; }
  .go-btn .key { display: none; }
}

.toast, .note {
  position: fixed;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 4px 18px rgba(60, 90, 140, 0.15);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  white-space: nowrap;
  z-index: 4;
}
.toast { top: calc(var(--safe-top) + 66px); color: var(--ink-soft); font-size: 14px; letter-spacing: 0.4px; }
.note {
  top: calc(var(--safe-top) + 102px); border-left: 5px solid var(--accent, var(--ink)); text-align: center;
  white-space: normal; width: max-content; max-width: calc(100vw - 48px); box-sizing: border-box;
}
.note small { display: block; font-size: 13px; color: var(--ink-soft); }
.toast.show, .note.show { opacity: 1; transform: translate(-50%, 0); }

/* riding the lift back up */
.ride-cap {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 18px); z-index: 3;
  transform: translate(-50%, -8px);
  padding: 9px 20px; border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 18px rgba(60, 90, 140, 0.15);
  text-align: center; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.ride-cap b { display: block; font-size: 16px; }
.ride-cap small { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 1px; }
.ride-cap.show { opacity: 1; transform: translate(-50%, 0); }

.throw-btn {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid var(--accent, #8aa0bd);
  background: rgba(255, 255, 255, 0.85);
  color: var(--accent, #8aa0bd);
  font-size: 36px;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(60, 90, 140, 0.2);
  touch-action: none;
  z-index: 4;
  transition: transform 0.15s ease, background 0.2s ease;
}
.throw-btn.ready { background: #fff; transform: scale(1.08); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 25%, transparent), 0 6px 20px rgba(60, 90, 140, 0.2); }
.throw-btn:active { transform: scale(0.94); }
.throw-btn.hidden { display: none; }
.throw-left .throw-btn { right: auto; left: max(18px, env(safe-area-inset-left)); }

.fade {
  position: fixed;
  inset: 0;
  background: #f4f8fc;
  opacity: 0;
  pointer-events: none;
}

/* ---- Tuning panel (press T, or add ?tune to the URL) ---- */
.tuner {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 300px;
  max-height: calc(100% - 20px);
  overflow-y: auto;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 24px rgba(40, 60, 100, 0.2);
  font: 12px/1.3 ui-monospace, Menlo, monospace;
  color: var(--ink);
  z-index: 10;
  user-select: text;
  -webkit-user-select: text;
}
.tuner h3 { margin: 0 0 6px; font: 600 13px var(--font); }
.tuner .row { display: grid; grid-template-columns: 1fr 70px; gap: 2px 6px; margin: 4px 0; }
.tuner .row label { grid-column: 1 / 3; display: flex; justify-content: space-between; }
.tuner .row input[type=range] { grid-column: 1 / 3; width: 100%; }
.tuner .readout { margin: 6px 0; padding: 6px; background: #eef3f9; border-radius: 6px; white-space: pre; }
.tuner button { font: inherit; margin: 4px 4px 0 0; padding: 4px 8px; border-radius: 6px; border: 1px solid #b8c7da; background: #fff; cursor: pointer; }

/* ---- Postmark on the summary ------------------------------------------------- */
.stamp { display: flex; align-items: center; gap: 14px; margin: 0 0 12px; padding: 10px 12px; border-radius: 14px; background: #f6f9fc; }
.stamp.hidden { display: none; }
.stamp-ring {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 84px; height: 84px; border-radius: 50%; border: 3px dashed currentColor; box-sizing: border-box;
  color: #8aa0bd; transform: rotate(-8deg); text-align: center; line-height: 1.1;
}
.stamp-ring b { font-size: 15px; text-transform: uppercase; letter-spacing: 0.6px; }
.stamp-ring span { font-size: 13px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stamp.gold .stamp-ring { color: #c98a1e; background: #fff6de; }
.stamp.silver .stamp-ring { color: #74849a; background: #f1f4f8; }
.stamp.bronze .stamp-ring { color: #a5683a; background: #fbefe4; }
.stamp.none .stamp-ring b { font-size: 11px; }
.stamp-info { min-width: 0; font-size: 13.5px; line-height: 1.4; color: var(--ink-soft); }
.stamp-info p { margin: 0 0 3px; }
.stamp-info .best { color: #4f8f5d; font-weight: 600; }
.stamp.thump .stamp-ring { animation: thump 0.5s 0.45s both cubic-bezier(.2,1.6,.4,1); }
@keyframes thump { from { transform: rotate(-20deg) scale(1.8); opacity: 0; } to { transform: rotate(-8deg) scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .stamp.thump .stamp-ring { animation: none; } }
