:root {
  --cream: #fbfbe9;
  --ink: #24402a;
  --green: #4e8a45;
  --green-dark: #3a6b34;
  --gold: #e9b93a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: Georgia, 'Iowan Old Style', Palatino, 'Times New Roman', serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  background: radial-gradient(ellipse at center, rgba(251, 251, 233, 0.55), rgba(251, 251, 233, 0.25));
  animation: fade-in 0.35s ease;
}

#screen-title {
  justify-content: space-between;
  background: linear-gradient(rgba(251, 251, 233, 0.75), rgba(251, 251, 233, 0) 45%, rgba(251, 251, 233, 0) 60%, rgba(251, 251, 233, 0.6));
}

.title-top { text-align: center; margin-top: 6vh; }
.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 3vh; }

h1 {
  margin: 0;
  font-size: clamp(48px, 14vw, 92px);
  font-weight: normal;
  font-style: italic;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}

h2 { margin: 0 0 6px; font-weight: normal; font-style: italic; font-size: 30px; }

.sub { margin: 6px 0 0; font-size: 17px; opacity: 0.85; }
.hint { margin: 4px 0 0; font-size: 15px; opacity: 0.8; text-align: center; }
.small-hint { font-size: 13px; max-width: 300px; }
.story { line-height: 1.5; font-size: 16px; margin: 8px 0; }

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(360px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 20px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 6px 0 rgba(36, 64, 42, 0.25);
  text-align: center;
}
.card.wide { width: min(440px, 100%); }

/* ---------- buttons ---------- */
.btn {
  min-width: 210px;
  padding: 13px 28px;
  font: inherit;
  font-size: 20px;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--green); color: var(--cream); }
.btn.small { min-width: 150px; padding: 8px 20px; font-size: 16px; box-shadow: 0 3px 0 var(--ink); }

/* ---------- level select ---------- */
.level-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.level {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  color: var(--ink);
  text-align: left;
  background: #f3f6d8;
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}
.level:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.level.locked { opacity: 0.45; cursor: default; }
.level .num {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: var(--cream);
  font-size: 18px;
}
.level .info { flex: 1; min-width: 0; }
.level .name { font-size: 18px; }
.level .desc { font-size: 13px; opacity: 0.75; }
.level .mini-stars { flex: none; font-size: 18px; letter-spacing: 1px; color: #cfcab0; }
.level .mini-stars .on { color: var(--gold); }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + 12px);
  right: calc(var(--safe-r) + 12px);
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}
.hud-daisies {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 12px 5px 8px;
  background: rgba(251, 251, 233, 0.85);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.hud-progress {
  position: relative;
  flex: 1;
  height: 10px;
  background: rgba(251, 251, 233, 0.8);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.hud-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--green); border-radius: 999px; }
.hud-marker {
  position: absolute; top: 50%; left: 0;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.hud-flag { position: absolute; top: -7px; width: 2px; height: 20px; background: var(--ink); }
.hud-flag::after { content: ''; position: absolute; left: 2px; top: 0; border-left: 8px solid #c8553d; border-top: 4px solid transparent; border-bottom: 4px solid transparent; }
.hud-flag.on::after { border-left-color: var(--gold); }
.hud-lamp { position: absolute; right: -6px; top: -7px; width: 12px; height: 20px; border-radius: 3px 3px 1px 1px; background: #ffe58f; border: 2px solid var(--ink); }
.hud-pause {
  pointer-events: auto;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  background: rgba(251, 251, 233, 0.9);
  border: 2px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
}
.hud-pause span { width: 5px; height: 16px; background: var(--ink); border-radius: 2px; }

.tip {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + 70px);
  max-width: calc(100% - 32px);
  padding: 9px 18px;
  transform: translate(-50%, -10px);
  background: rgba(251, 251, 233, 0.95);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 17px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
.tip.show { opacity: 1; transform: translate(-50%, 0); }

.banner {
  position: fixed;
  left: 0; right: 0;
  top: 24%;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
}
.banner.show { opacity: 1; }
#banner-title { font-size: clamp(30px, 8vw, 46px); font-style: italic; }
#banner-sub { font-size: 17px; opacity: 0.85; margin-top: 4px; }

/* ---------- results ---------- */
.stars { display: flex; gap: 8px; font-size: 46px; line-height: 1; }
.stars span { color: #d8d3b6; transform: scale(0.6); transition: transform 0.3s cubic-bezier(.3, 1.8, .5, 1), color 0.2s; }
.stars span.on { color: var(--gold); transform: scale(1); text-shadow: 0 2px 0 #a17a14; }
.stats { font-size: 16px; line-height: 1.7; }
.stats b { font-weight: normal; font-variant-numeric: tabular-nums; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (orientation: landscape) and (max-height: 500px) {
  .title-top { margin-top: 1vh; }
  h1 { font-size: 54px; }
  .title-bottom { flex-direction: row; flex-wrap: wrap; justify-content: center; margin-bottom: 1vh; }
  .title-bottom .hint { width: 100%; }
  .card { padding: 14px 16px; gap: 8px; }
  .stars { font-size: 34px; }
}
