:root {
  color-scheme: light;
  --bg: #8a8a52;
  --panel: rgba(251, 241, 220, 0.97);
  --ink: #3b2416;
  --muted: #86664c;
  --bone: #f1e5c9;
  --red: #b8352f;
  --gold: #f2b542;
  --chips: #2f6d8f;
  --hud: rgba(52, 30, 18, 0.72);
  --serif: "Georgia", "Times New Roman", serif;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

canvas#game { position: fixed; inset: 0; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: max(8px, env(safe-area-inset-top)) 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
  color: #fff4dc;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud[hidden], .turn[hidden] { display: none; }
.icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(255, 230, 190, 0.18);
  background: var(--hud);
  display: grid;
  place-items: center;
}
.icon:active { transform: scale(0.94); }
.hud-mid {
  flex: 1;
  min-width: 0;
  max-width: 340px;
  margin: 0 auto;
  padding: 6px 14px 8px;
  border-radius: 16px;
  background: var(--hud);
  display: grid;
  gap: 5px;
  justify-items: center;
}
.hud-kon { margin: 0; font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hud-kon b { font-family: var(--serif); font-size: 16px; letter-spacing: 0.02em; margin-right: 6px; }
.bar { width: 100%; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #d0702c, var(--gold)); transition: width 0.3s ease; }

/* throws left: little bones */
.throws {
  flex: none;
  min-width: 42px;
  height: 42px;
  padding: 0 10px;
  border-radius: 14px;
  background: var(--hud);
  display: flex;
  align-items: center;
  gap: 4px;
}
.throws i {
  width: 9px;
  height: 16px;
  border-radius: 5px 5px 4px 4px / 7px 7px 5px 5px;
  background: linear-gradient(90deg, #f6ecd6, #cdb894);
  box-shadow: inset 0 -2px 0 rgba(90, 60, 30, 0.35);
  transition: opacity 0.3s, transform 0.3s;
}
.throws i.spent { opacity: 0.22; transform: scale(0.8); }
.throws i.bonus { background: linear-gradient(90deg, #ffe39a, #e2a537); }

/* the throw being counted: chips × mult */
.turn {
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 4px;
  pointer-events: none;
}
.calc { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 16px; background: var(--hud); }
.box {
  min-width: 64px;
  padding: 5px 10px;
  border-radius: 11px;
  font-weight: 900;
  font-size: 22px;
  text-align: center;
  color: #fff;
  font-variant-numeric: tabular-nums;
  transition: transform 0.12s ease;
}
.box.chips { background: linear-gradient(180deg, #3b84ab, var(--chips)); }
.box.mult { background: linear-gradient(180deg, #d4483f, var(--red)); }
.box.bump { transform: scale(1.18); }
.x { color: #fff4dc; font-weight: 900; font-size: 20px; }
.turn-note { margin: 0; min-height: 18px; color: #fff4dc; font-size: 13px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

.hint-line {
  position: fixed;
  left: 50%;
  top: calc(max(8px, env(safe-area-inset-top)) + 58px);
  transform: translateX(-50%);
  margin: 0;
  max-width: min(92vw, 520px);
  padding: 7px 14px;
  border-radius: 12px;
  background: rgba(52, 30, 18, 0.86);
  color: #fff4dc;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 4;
}
.hint-line.show { opacity: 1; }

#ui { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 10; padding: 16px; }
#ui > * { pointer-events: auto; }

.panel {
  width: min(400px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 26px 22px 22px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(40, 20, 10, 0.45), 0 0 0 3px #8f2f2a, 0 0 0 6px #e7c48a;
  text-align: center;
  animation: rise 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }

.logo {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(64px, 19vw, 100px);
  line-height: 1;
  font-weight: 700;
  color: #8f2f2a;
  text-shadow: 0 3px 0 #e7c48a;
}
.sub { margin: 8px 0 0; color: var(--muted); font-size: 15px; line-height: 1.45; }
.panel h2 { margin: 0; font-family: var(--serif); font-size: 30px; color: #8f2f2a; }
.stats { margin: 14px 0 0; display: grid; gap: 6px; font-size: 16px; }
.stats b { font-variant-numeric: tabular-nums; }
.rules { margin: 16px 0 0; padding: 0; list-style: none; display: grid; gap: 7px; text-align: left; font-size: 14px; color: var(--ink); }
.rules li { padding-left: 22px; position: relative; line-height: 1.4; }
.rules li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 3px; background: #8f2f2a; }
.btn {
  margin-top: 20px;
  width: 100%;
  padding: 15px 18px;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(180deg, #b8453a, #8f2f2a);
  color: #fff4dc;
  font-weight: 800;
  font-size: 19px;
  box-shadow: 0 4px 0 #5e1d1a;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #5e1d1a; }
.btn.ghost { margin-top: 10px; background: transparent; color: var(--muted); box-shadow: none; font-size: 15px; padding: 8px; }

.panel.wide { width: min(560px, 100%); }
.btn.second { margin-top: 10px; background: linear-gradient(180deg, #3b84ab, #2f6d8f); box-shadow: 0 4px 0 #1f4c66; }

/* chapters */
.chapters { margin-top: 16px; display: grid; gap: 10px; }
.chapter {
  display: grid;
  gap: 3px;
  text-align: left;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(90, 40, 20, 0.18);
  background: #fff8ea;
  color: var(--ink);
}
.chapter b { font-family: var(--serif); font-size: 19px; color: #8f2f2a; }
.chapter span { color: var(--muted); font-size: 14px; }
.chapter .dots { font-style: normal; display: flex; gap: 6px; margin-top: 4px; }
.chapter em { font-style: normal; color: rgba(90, 40, 20, 0.25); }
.chapter em.on { color: #d0702c; }
.chapter.locked { opacity: 0.5; cursor: default; }
.chapter:not(.locked):active { transform: scale(0.98); }

/* dialogue */
.talk {
  position: fixed;
  left: 50%;
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 76px);
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 20px));
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 12px 12px;
  border-radius: 20px;
  background: rgba(251, 241, 220, 0.97);
  box-shadow: 0 14px 40px rgba(40, 20, 10, 0.45), 0 0 0 3px #8f2f2a;
  cursor: pointer;
  animation: rise 0.25s ease;
}
.talk[hidden] { display: none; }
.talk-pic canvas { width: 64px; height: 64px; border-radius: 50%; display: block; box-shadow: 0 0 0 3px #e7c48a; }
.talk-body { flex: 1; min-width: 0; }
.talk-name { font-family: var(--serif); color: #8f2f2a; font-size: 16px; }
.talk-text { margin: 3px 0 0; font-size: 17px; line-height: 1.38; color: var(--ink); min-height: 2.6em; }
.talk-next { color: #8f2f2a; font-size: 20px; animation: nudge 1s ease-in-out infinite; }
.talk-skip { position: absolute; top: -40px; right: 0; padding: 7px 12px; border: 0; border-radius: 11px; background: rgba(52, 30, 18, 0.78); color: #fff4dc; font-size: 13px; font-weight: 700; }
@keyframes nudge { 50% { transform: translateX(4px); } }

/* chapter film */
.film { position: fixed; inset: 0; z-index: 20; background: #000; display: grid; place-items: center; }
.film[hidden] { display: none; }
.film video { width: 100%; height: 100%; object-fit: contain; }
.film-skip { position: absolute; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); padding: 10px 16px; border-radius: 12px; border: 0; background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 18px; }

/* narrow phones: the chapter title and the score may take two lines */
@media (max-width: 480px) {
  .hud-kon { white-space: normal; text-align: center; line-height: 1.2; font-size: 13px; }
  .hud-kon b { font-size: 14px; }
}

/* bazaar */
.purse { margin: 4px 0 0; font-size: 22px; font-weight: 900; color: #b8762a; }
.bazar { display: grid; gap: 8px; margin-top: 8px; text-align: left; }
.bazar h3 { margin: 10px 0 0; font-family: var(--serif); color: #8f2f2a; font-size: 17px; }
.ware { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: #fff8ea; border: 1px solid rgba(90, 40, 20, 0.16); }
.ware-icon { width: 52px; height: 52px; flex: none; }
.ware-mark { width: 52px; height: 52px; flex: none; display: grid; place-items: center; font-style: normal; font-size: 26px; color: #b8762a; background: rgba(208, 112, 44, 0.12); border-radius: 50%; }
.ware-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.ware-text b { font-size: 15px; }
.ware-text span { font-size: 13px; color: var(--muted); line-height: 1.35; }
.buy { flex: none; min-width: 74px; padding: 9px 12px; border: 0; border-radius: 11px; background: linear-gradient(180deg, #e9a53c, #c97a1f); color: #fff; font-weight: 800; box-shadow: 0 3px 0 #8a4f12; }
.buy.on { background: linear-gradient(180deg, #6aa54a, #4d8434); box-shadow: 0 3px 0 #2f5a1d; }
.buy.poor { opacity: 0.45; }
.tag { flex: none; font-style: normal; font-size: 13px; font-weight: 800; color: #4d8434; padding: 6px 10px; }

.logo-sub { margin: 2px 0 0; font-family: var(--serif); font-size: 18px; letter-spacing: 0.18em; text-transform: uppercase; color: #b8762a; }
