/* Tiny Planet Explorer — one stylesheet, same conventions as Sky Courier:
   CSS custom properties for theme + safe-area, .hidden as the only screen
   toggle, and html[data-input] switching per-device wording. */

:root {
  --space: #120d2b;
  --space-deep: #0b0719;
  --violet: #2a1650;
  --cream: #fff6e8;
  --sun: #ffd94d;
  --teal: #3fd9d0;
  --coral: #ff6b6b;
  --leaf: #6ed36e;
  --panel: rgba(26, 16, 52, 0.82);
  --panel-edge: rgba(255, 255, 255, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--space-deep);
  color: var(--cream);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

html[data-input="keyboard"] .only-touch,
html[data-input="touch"] .only-keyboard { display: none !important; }

/* ---------------------------------------------------------- touch layer */
#touch-controls { display: none; position: absolute; inset: 0; z-index: 4; pointer-events: none; }
html[data-input="touch"] #touch-controls.active { display: block; }

#stick-zone {
  position: absolute; left: 0; top: 90px; bottom: 0; width: 45%;
  pointer-events: auto;
}
#camera-zone {
  position: absolute; right: 0; top: 90px; bottom: 0; width: 55%;
  pointer-events: auto;
}

#stick-base {
  position: absolute; left: 24%; top: 70%;
  width: 128px; height: 128px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.15s;
}
#stick-base.visible { opacity: 1; }
#stick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--sun) 60%, #e8a93c);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

#jump-button {
  position: absolute;
  right: calc(28px + var(--safe-right));
  bottom: calc(30px + var(--safe-bottom));
  width: 92px; height: 92px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  background: radial-gradient(circle at 35% 30%, #8ff0e9, var(--teal) 62%, #25a8a1);
  color: #073a38;
  font: 700 15px/1 "Trebuchet MS", sans-serif;
  letter-spacing: 0.06em;
  pointer-events: auto;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
#jump-button.pressed { transform: scale(0.92); filter: brightness(1.15); }

#interact-button {
  position: absolute;
  right: calc(140px + var(--safe-right));
  bottom: calc(48px + var(--safe-bottom));
  min-width: 88px; min-height: 56px;
  padding: 0 18px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  background: radial-gradient(circle at 35% 30%, #ffd1dc, var(--coral) 65%, #d94f4f);
  color: #4a0d0d;
  font: 700 15px/1 "Trebuchet MS", sans-serif;
  pointer-events: auto;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

/* ---------------------------------------------------------------- HUD */
#hud { position: absolute; inset: 0; z-index: 5; pointer-events: none; }

#hud-top-left {
  position: absolute;
  left: calc(18px + var(--safe-left));
  top: calc(14px + var(--safe-top));
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
#star-counter {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(8px);
  font-size: 18px; font-weight: 700;
}
#star-counter .gem { color: var(--sun); font-size: 22px; text-shadow: 0 0 10px rgba(255, 217, 77, 0.7); }

#trial-timer, #seq-timer {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(8px);
  font: 700 17px/1.2 "Trebuchet MS", monospace, sans-serif;
  font-variant-numeric: tabular-nums;
  color: var(--teal);
}
#seq-timer { color: var(--sun); }
#seq-timer.urgent { color: var(--coral); animation: seq-blink 0.5s steps(2, start) infinite; }
@keyframes seq-blink { to { opacity: 0.45; } }

#hud-top-right {
  position: absolute;
  right: calc(18px + var(--safe-right));
  top: calc(14px + var(--safe-top));
  display: flex; gap: 10px; align-items: center;
  pointer-events: auto;
}

/* The rewarded-ad offer. The play triangle says "video" without a word, in
   whichever language the player is reading. */
.btn-reward {
  display: inline-flex; align-items: center; gap: 9px;
  height: 48px; padding: 0 18px;
  border: none; border-radius: 999px;
  background: linear-gradient(120deg, var(--sun), #ffb347);
  color: #4a2c00;
  font: 700 14px/1 "Trebuchet MS", sans-serif;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 179, 71, 0.4);
  animation: toast-in 0.3s ease-out;
}
.btn-reward:disabled { opacity: 0.6; cursor: default; }
.ad-badge {
  width: 0; height: 0;
  border-left: 11px solid currentColor;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
}
html[data-input="touch"] .btn-reward { height: 56px; }
.icon-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 14px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--cream);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.icon-btn:active { transform: scale(0.93); }
#mute-button .vol-off { display: none; }
#mute-button.muted .vol-on { display: none; }
#mute-button.muted .vol-off { display: block; }

#toast {
  position: absolute; z-index: 30;
  left: 50%; top: calc(72px + var(--safe-top));
  transform: translateX(-50%);
  max-width: min(86vw, 520px);
  padding: 10px 22px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(8px);
  font-size: 16px; text-align: center;
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

#controls-hint {
  position: absolute;
  left: 50%; bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(11, 7, 25, 0.55);
  font-size: 12.5px; opacity: 0.85;
  white-space: nowrap;
}
html[data-input="touch"] #controls-hint { display: none; }

/* ------------------------------------------------------------- dialog */
#dialog {
  position: absolute;
  left: 50%; bottom: calc(26px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 6;
  width: min(92vw, 480px);
  padding: 14px 20px 12px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(10px);
  cursor: pointer;
  animation: toast-in 0.2s ease-out;
}
#dialog-name {
  color: var(--sun); font-weight: 700; font-size: 14px;
  letter-spacing: 0.08em; text-transform: uppercase;
  margin-bottom: 4px;
}
#dialog-text { font-size: 16px; line-height: 1.45; }
#dialog-hint { margin-top: 8px; font-size: 12px; opacity: 0.6; text-align: right; }
html[data-input="touch"] #dialog { bottom: calc(150px + var(--safe-bottom)); }

/* ------------------------------------------------------------ overlays */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex;
  padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right))
           calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
  background:
    radial-gradient(ellipse at 50% 120%, rgba(63, 217, 208, 0.12), transparent 60%),
    linear-gradient(180deg, rgba(11, 7, 25, 0.82), rgba(18, 13, 43, 0.88));
  backdrop-filter: blur(4px);
  overflow-y: auto;
}

.panel {
  margin: auto;
  width: min(94vw, 640px);
  padding: 30px 34px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.title {
  font-size: clamp(30px, 6vw, 46px);
  line-height: 1.05;
  letter-spacing: 0.04em;
  background: linear-gradient(120deg, var(--sun), #ffb347 40%, var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 10px;
}
.hero { font-size: 30px; margin: 6px 0 12px; letter-spacing: 0.3em; }
.panel-story p { font-size: 16px; line-height: 1.55; opacity: 0.92; }

.panel-actions { margin-top: 22px; display: flex; flex-direction: column; gap: 18px; align-items: center; }

.controls-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 14.5px; opacity: 0.9;
}
.controls-list b { color: var(--sun); font-weight: 700; }

.setting-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px 12px; font-size: 14.5px; }
.seg {
  display: flex;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  overflow: hidden;
}
.seg-btn {
  padding: 9px 18px;
  border: none;
  background: transparent;
  color: var(--cream);
  font: 600 13.5px/1 "Trebuchet MS", sans-serif;
  cursor: pointer;
  opacity: 0.7;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--panel-edge); }
.seg-btn.active { background: linear-gradient(120deg, var(--teal), #6ee7b7); color: #073a38; opacity: 1; }

.btn {
  padding: 15px 42px;
  border: none; border-radius: 999px;
  background: linear-gradient(120deg, var(--sun), #ffb347);
  color: #4a2c00;
  font: 700 18px/1 "Trebuchet MS", sans-serif;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 8px 26px rgba(255, 179, 71, 0.35);
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(255, 179, 71, 0.45); }
.btn:active { transform: scale(0.96); }

.btn-secondary {
  padding: 13px 30px;
  border-radius: 999px;
  border: 2px solid var(--panel-edge);
  background: transparent;
  color: var(--cream);
  font: 600 15px/1 "Trebuchet MS", sans-serif;
  cursor: pointer;
}
.btn-secondary:active { transform: scale(0.96); }

.btn-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

.stats { display: flex; gap: 26px; justify-content: center; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat span { font-size: 13px; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.08em; }
.stat b { font-size: 26px; color: var(--sun); }

/* ---------------------------------------------------------- coaching */
#coach { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
#coach-bubble {
  position: absolute;
  top: calc(84px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, 86vw);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 14px 20px 12px;
  border-radius: 18px;
  border: 2px solid rgba(63, 217, 208, 0.5);
  background: rgba(18, 13, 43, 0.92);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: toast-in 0.28s ease-out;
}
#coach-text { font-size: clamp(14px, 1.9vw, 17px); line-height: 1.45; }
#coach-skip { pointer-events: auto; }
.btn-small { padding: 8px 18px; font-size: 13px; }
html[data-input="touch"] .btn-small { min-height: 44px; }

/* ---------------------------------------------------------- time trial */
.trial-list {
  width: 100%;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px;
}
.trial-btn {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--cream);
  font: 600 15px/1.3 "Trebuchet MS", sans-serif;
  text-align: left;
  cursor: pointer;
}
.trial-btn:hover { background: rgba(255, 255, 255, 0.12); }
.trial-btn:active { transform: scale(0.97); }
.trial-btn:disabled { opacity: 0.5; cursor: default; }
.trial-btn .swatch { width: 100%; height: 6px; border-radius: 999px; margin-bottom: 4px; }
.trial-btn small { font-weight: 400; font-size: 12.5px; opacity: 0.75; }
.trial-btn .best { color: var(--sun); font-size: 13px; }
.record { color: var(--sun); font-weight: 700; font-size: 17px; animation: toast-in 0.3s ease-out; }

/* ------------------------------------------------------------ fps meter */
#fps-meter {
  position: absolute; z-index: 40;
  left: calc(14px + var(--safe-left)); bottom: calc(14px + var(--safe-bottom));
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(11, 7, 25, 0.7);
  font: 600 13px/1 monospace;
  color: var(--leaf);
}

/* ------------------------------------------------------- responsiveness */
@media (max-height: 520px) and (min-width: 640px) {
  .panel { display: grid; grid-template-columns: 1.2fr 1fr; gap: 8px 28px; text-align: left; padding: 22px 28px; }
  .panel .title { font-size: 30px; }
  .panel-actions { margin-top: 0; }
}
@media (max-width: 560px) and (orientation: portrait) {
  .panel { padding: 22px 20px; }
  .hero { font-size: 24px; }
  .controls-list { font-size: 13.5px; }
}
html[data-input="touch"] .icon-btn { width: 56px; height: 56px; }
html[data-input="touch"] .seg-btn { min-height: 48px; padding: 9px 20px; }
html[data-input="touch"] .trial-btn { min-height: 56px; }
html[data-input="touch"] .btn { min-height: 56px; }
