:root {
  --bg: #12162e;
  --panel: #1d2350;
  --panel-2: #2a3270;
  --line: rgba(255, 255, 255, 0.12);
  --gold: #ffcf3f;
  --gold-2: #ff9f1c;
  --ink: #1b1f3b;
  --red: #ff5d6c;
  --green: #55d68a;
  --btn: clamp(62px, 18.5vw, 84px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: 'M PLUS Rounded 1c', -apple-system, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', system-ui, sans-serif;
  --logo: 'Dela Gothic One', 'M PLUS Rounded 1c', 'Hiragino Sans', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: #fff;
  font-family: var(--font);
  font-weight: 800;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
button { font-family: inherit; font-weight: 800; cursor: pointer; color: inherit; }

#app {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
@media (min-width: 561px) {
  #app { box-shadow: 0 0 0 1px var(--line), 0 20px 80px rgba(0, 0, 0, 0.5); }
}
#view { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------------------------------------------------------------- HUD */
#hud {
  position: absolute;
  top: calc(8px + var(--safe-t));
  left: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  transition: opacity 0.2s;
}
body:not([data-mode='play']) #hud { opacity: 0; }
.hud-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(14, 18, 48, 0.62);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.16);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.hud-time { margin-left: auto; }
.hud-coins { min-width: 70px; }
.hud-coins.bump .coin { animation: coinbump 0.25s ease-out; }
@keyframes coinbump { 50% { transform: scale(1.35); } }
#hud-bottle { padding: 0 10px; }
.bottle-icon { width: 15px; height: 24px; }
.bottle-icon .cap { fill: rgba(255, 255, 255, 0.4); }
.bottle-icon .shell { fill: rgba(255, 255, 255, 0.12); stroke: rgba(255, 255, 255, 0.45); stroke-width: 1.2; }
.bottle-icon .liquid { fill: transparent; }
#hud-bottle.full .cap { fill: #fff; }
#hud-bottle.full .shell { fill: rgba(255, 255, 255, 0.25); stroke: #fff; }
#hud-bottle.full .liquid { fill: #f4dc14; }
#hud-bottle.full { box-shadow: inset 0 0 0 2px #f4dc14, 0 0 14px rgba(244, 220, 20, 0.55); }
.coin {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff4b0, #ffd23f 45%, #e39b00);
  box-shadow: inset 0 0 0 2px #c98400;
  flex: none;
}
.clock {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  position: relative;
  flex: none;
}
.clock::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 2px;
  width: 2px;
  height: 5px;
  background: #fff;
  transform: translateX(-50%);
}
.hud-btn {
  pointer-events: auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(14, 18, 48, 0.62);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.16);
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.hud-btn span { width: 4px; height: 13px; background: #fff; border-radius: 2px; }

#toast {
  position: absolute;
  left: 50%;
  top: calc(56px + var(--safe-t));
  transform: translate(-50%, -10px);
  max-width: calc(100% - 24px);
  width: max-content;
  padding: 9px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

#banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
}
#banner.on { animation: banner 1.7s ease both; }
@keyframes banner {
  0% { opacity: 0; transform: scale(0.8); }
  15% { opacity: 1; transform: scale(1.04); }
  25% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.02); }
}
.b-num {
  font-family: var(--logo);
  font-size: 18px;
  letter-spacing: 0.2em;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}
.b-name {
  font-family: var(--logo);
  font-size: clamp(26px, 8vw, 40px);
  text-shadow: 0 3px 0 #2a1a4a, 0 0 18px rgba(0, 0, 0, 0.45);
  -webkit-text-stroke: 1px rgba(0, 0, 0, 0.25);
}

/* ---------------------------------------------------------------- pad */
#pad {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px clamp(12px, 5vw, 26px) calc(16px + var(--safe-b));
  background: linear-gradient(180deg, #232a5c 0%, #161b3d 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08);
  touch-action: none;
}
body:not([data-mode='play']) #pad { display: none; }
.dpad { display: flex; gap: 10px; }
.pbtn {
  appearance: none;
  border: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  touch-action: none;
  transition: transform 0.06s, box-shadow 0.06s;
}
.pbtn.dir {
  width: var(--btn);
  height: calc(var(--btn) * 1.05);
  border-radius: 22px;
  background: linear-gradient(180deg, #4a54a0, #343c7c);
  box-shadow: 0 6px 0 #10142e, inset 0 2px 0 rgba(255, 255, 255, 0.22);
}
.pbtn.dir svg { width: 44%; height: 44%; fill: #fff; }
.pbtn.down { transform: translateY(4px); }
.pbtn.dir.down { box-shadow: 0 2px 0 #10142e, inset 0 2px 0 rgba(255, 255, 255, 0.22); background: linear-gradient(180deg, #5a66c0, #3e4794); }
.abtns { position: relative; width: calc(var(--btn) * 2.2); height: calc(var(--btn) * 1.75); flex: none; }
.pbtn.a,
.pbtn.b { position: absolute; border-radius: 50%; }
.pbtn.a {
  right: 0;
  bottom: 0;
  width: calc(var(--btn) * 1.2);
  height: calc(var(--btn) * 1.2);
  background: radial-gradient(circle at 35% 28%, #fff1a6, #ffc23a 50%, #f08f0a);
  box-shadow: 0 6px 0 #8a4c00, inset 0 -4px 0 rgba(0, 0, 0, 0.12);
  color: #5a2e00;
  font-size: clamp(12px, 3.6vw, 15px);
}
.pbtn.a.down { box-shadow: 0 2px 0 #8a4c00; }
.pbtn.b {
  left: 0;
  top: 0;
  width: var(--btn);
  height: var(--btn);
  background: #3a4068;
  box-shadow: 0 5px 0 #191c33;
  color: rgba(255, 255, 255, 0.45);
  font-size: clamp(10px, 3vw, 12px);
}
.pbtn.b svg { width: 16px; height: 26px; color: rgba(255, 255, 255, 0.35); }
.pbtn.b.ready {
  background: radial-gradient(circle at 35% 28%, #fffbd0, #f6e04a 50%, #d9b800);
  box-shadow: 0 5px 0 #7d6a00, 0 0 18px rgba(246, 224, 74, 0.6);
  color: #4a3a00;
  animation: ready 1.4s ease-in-out infinite;
}
.pbtn.b.ready svg { color: #f4dc14; }
.pbtn.b.ready.down { box-shadow: 0 2px 0 #7d6a00; animation: none; }
@keyframes ready { 50% { box-shadow: 0 5px 0 #7d6a00, 0 0 28px rgba(246, 224, 74, 0.95); } }

/* ---------------------------------------------------------------- screens */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  z-index: 10;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
}
.screen.on { display: flex; }
.screen.modal { align-items: center; justify-content: center; background: rgba(10, 12, 32, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.logo { display: flex; flex-direction: column; align-items: center; line-height: 1; transform: rotate(-3deg); }
.logo .l1 {
  font-family: var(--logo);
  font-size: clamp(52px, 17vw, 84px);
  color: #fff;
  -webkit-text-stroke: 2px #1b1f3b;
  text-shadow: 0 5px 0 #1b1f3b, 0 9px 0 rgba(0, 0, 0, 0.25);
  letter-spacing: 0.02em;
}
.logo .l2 {
  margin-top: 8px;
  font-family: var(--logo);
  font-size: clamp(20px, 6.5vw, 30px);
  letter-spacing: 0.18em;
  color: var(--gold);
  -webkit-text-stroke: 1.5px #1b1f3b;
  text-shadow: 0 4px 0 #1b1f3b;
}
.logo.small .l1 { font-size: 46px; }
.logo.small .l2 { font-size: 18px; }

[data-screen='loading'] { align-items: center; justify-content: center; background: var(--bg); }
.loading { display: flex; flex-direction: column; align-items: center; gap: 26px; }
.load-track { width: 200px; height: 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#load-bar { height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transform-origin: left; transform: scaleX(0.05); transition: transform 0.3s; }

[data-screen='title'] { justify-content: space-between; align-items: center; background: linear-gradient(180deg, rgba(18, 22, 46, 0.35) 0%, rgba(18, 22, 46, 0) 30%, rgba(18, 22, 46, 0) 62%, rgba(18, 22, 46, 0.7) 100%); }
.title-top { padding-top: 6vh; }
.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.title-bottom .row { display: flex; gap: 8px; }
.keys { margin: 0; font-size: 11px; opacity: 0.75; text-align: center; }
@media (pointer: coarse) { .keys { display: none; } }

.btn {
  appearance: none;
  border: 0;
  width: 100%;
  max-width: 320px;
  padding: 15px 18px;
  border-radius: 16px;
  font-size: 18px;
  color: #4a2a00;
  background: linear-gradient(180deg, #ffe27a, var(--gold) 45%, var(--gold-2));
  box-shadow: 0 5px 0 #a35b00, inset 0 2px 0 rgba(255, 255, 255, 0.6);
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a35b00; }
.btn.big { font-size: 21px; padding: 18px; }
.btn.sub { color: #fff; background: linear-gradient(180deg, #4a54a0, #343c7c); box-shadow: 0 5px 0 #10142e, inset 0 2px 0 rgba(255, 255, 255, 0.2); }
.btn.sub:active { box-shadow: 0 2px 0 #10142e; }
.btn[hidden] { display: none; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.chip {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(14, 18, 48, 0.7);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 14px;
}
.chip.ghost { background: transparent; }
.chip.center { align-self: center; }
.spk { width: 16px; height: 16px; background: currentColor; -webkit-mask: var(--spk) center / contain no-repeat; mask: var(--spk) center / contain no-repeat;
  --spk: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 9v6h4l5 4V5L7 9H3zm13.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4zM14 3.2v2.1a7 7 0 0 1 0 13.4v2.1a9 9 0 0 0 0-17.6z'/%3E%3C/svg%3E"); }
.chip.off .spk { --spk: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 9v6h4l5 4V5L7 9H3zm13.6 3L19 9.6 17.6 8.2 15.2 10.6 12.8 8.2 11.4 9.6 13.8 12l-2.4 2.4 1.4 1.4 2.4-2.4 2.4 2.4 1.4-1.4z'/%3E%3C/svg%3E"); }

/* course select */
[data-screen='select'] { justify-content: flex-end; background: linear-gradient(180deg, rgba(18, 22, 46, 0) 0%, rgba(18, 22, 46, 0.55) 40%, rgba(18, 22, 46, 0.9) 100%); }
.sheet { display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h2 { margin: 0; font-size: 20px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
#course-list { display: flex; flex-direction: column; gap: 8px; }
.course {
  appearance: none;
  border: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  text-align: left;
  color: #fff;
  background: linear-gradient(90deg, var(--c1, #3c8a46), var(--c2, #2d6a3c));
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), inset 0 0 0 1.5px rgba(255, 255, 255, 0.2);
}
.course:active { transform: translateY(2px); }
.course.t-grass { --c1: #3f9b49; --c2: #2c7a3c; }
.course.t-forest { --c1: #2f6f55; --c2: #234f3e; }
.course.t-sky { --c1: #4a7be0; --c2: #6a5cc8; }
.course.t-volcano { --c1: #b3412c; --c2: #7a2a22; }
.course.t-castle { --c1: #4a3f8a; --c2: #2b2560; }
.course.locked { filter: saturate(0.2) brightness(0.65); }
.c-num {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--logo);
  font-size: 22px;
  background: rgba(0, 0, 0, 0.25);
}
.c-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.c-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-stars { color: var(--gold); font-size: 13px; letter-spacing: 0.06em; }
.c-stars i { font-style: normal; color: rgba(255, 255, 255, 0.25); }
.c-best { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-size: 15px; font-variant-numeric: tabular-nums; }
.c-best small { font-size: 11px; opacity: 0.85; }
.c-best .lock { font-size: 12px; opacity: 0.9; }

/* cards */
.card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 18px 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 0 0 2px rgba(255, 255, 255, 0.1);
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.card h2 { margin: 0 0 6px; font-family: var(--logo); font-size: 26px; font-weight: 400; }
.go-title { color: var(--red); text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
.go-sub { margin: -4px 0 6px; font-size: 14px; opacity: 0.85; }

.result { gap: 8px; padding-top: 40px; position: relative; }
.screen.modal.bottom { justify-content: flex-end; background: linear-gradient(180deg, rgba(10, 12, 32, 0) 30%, rgba(10, 12, 32, 0.55) 100%); backdrop-filter: none; -webkit-backdrop-filter: none; }
.screen.modal.bottom .card { max-width: 380px; }
.r-clear {
  position: absolute;
  top: calc(28px + var(--safe-t));
  left: 0;
  right: 0;
  text-align: center;
  white-space: nowrap;
  font-family: var(--logo);
  font-size: clamp(30px, 10vw, 44px);
  color: var(--gold);
  -webkit-text-stroke: 1.5px #5a2e00;
  text-shadow: 0 4px 0 #6a3a00, 0 0 24px rgba(255, 210, 80, 0.6);
  transform: rotate(-3deg);
  animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  margin-top: -64px;
  background: radial-gradient(circle at 50% 35%, #fff3cf, #ffc94a 70%, #f0a020);
}
.result .avatar { position: absolute; top: 0; left: 50%; transform: translateX(-50%); margin-top: -42px; }
.r-course { font-size: 13px; opacity: 0.85; }
.r-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; margin: 4px 0; }
.stat { padding: 10px 8px; border-radius: 16px; background: rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.s-label { font-size: 12px; opacity: 0.75; }
.s-value { display: flex; align-items: center; gap: 6px; font-size: 26px; font-variant-numeric: tabular-nums; }
.s-value small { font-size: 13px; opacity: 0.7; }
.new { font-size: 11px; color: #fff; background: var(--red); padding: 2px 8px; border-radius: 99px; animation: pulse 1s infinite; }
.r-best { font-size: 12px; opacity: 0.8; }
.r-unlock, .r-allclear { font-size: 13px; color: var(--gold); text-align: center; }
.share { margin: 2px 0 4px; font-size: 12px; opacity: 0.85; }

/* phones held sideways: overlay the pad on the game */
@media (orientation: landscape) and (max-height: 520px) {
  #app { max-width: none; }
  #pad { position: absolute; left: 0; right: 0; bottom: 0; background: none; box-shadow: none; padding-bottom: calc(10px + var(--safe-b)); pointer-events: none; }
  #pad .pbtn { pointer-events: auto; opacity: 0.85; }
  #pad .dpad, #pad .abtns { pointer-events: auto; }
  :root { --btn: 64px; }
}

.row2 { display: flex; gap: 8px; width: 100%; max-width: 320px; }
.row2 .btn { flex: 1; padding: 14px 8px; font-size: 16px; }
.btn.share-btn { color: #fff; background: linear-gradient(180deg, #ff7aa8, #e8457e); box-shadow: 0 5px 0 #8e1c47, inset 0 2px 0 rgba(255, 255, 255, 0.4); }
.btn.share-btn:active { box-shadow: 0 2px 0 #8e1c47; }

/* share-image layouts (?og / ?story) */
body.og-card #app, body.story-card #app { max-width: none; box-shadow: none; }
.og-overlay { position: absolute; inset: 0; z-index: 20; pointer-events: none; display: flex; flex-direction: column; justify-content: center; padding: 0 0 0 6%; gap: 18px; }
.og-overlay .logo { align-items: flex-start; transform: rotate(-4deg); }
.og-overlay .logo .l1 { font-size: 132px; -webkit-text-stroke: 4px #1b1f3b; text-shadow: 0 9px 0 #1b1f3b, 0 16px 0 rgba(0,0,0,.25); }
.og-overlay .logo .l2 { font-size: 52px; -webkit-text-stroke: 3px #1b1f3b; text-shadow: 0 6px 0 #1b1f3b; }
.og-tag { margin: 8px 0 0 6px; font-size: 40px; line-height: 1.25; color: #fff; -webkit-text-stroke: 1.5px #1b1f3b; text-shadow: 0 4px 0 #1b1f3b; }
.og-play { align-self: flex-start; padding: 14px 26px; border-radius: 999px; font-size: 30px; color: #4a2a00; background: linear-gradient(180deg, #ffe27a, var(--gold) 45%, var(--gold-2)); box-shadow: 0 6px 0 #a35b00; }
body.story-card .og-overlay { padding: 9% 7%; justify-content: space-between; align-items: center; }
body.story-card .og-overlay .logo { align-items: center; }
body.story-card .og-overlay .logo .l1 { font-size: 170px; }
body.story-card .og-overlay .logo .l2 { font-size: 66px; }
body.story-card .og-tag { display: none; }
body.story-card .og-play { align-self: center; font-size: 46px; padding: 22px 40px; }
