/* Super Sloppy Spaghetti Yo — Pasta-Noir tokens */
:root {
  --font-display: 'Clash Display', 'Satoshi', system-ui, sans-serif;
  --font-body: 'Satoshi', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Pasta-noir palette */
  --bg-0: #14100c;        /* deep tomato-tin shadow */
  --bg-1: #1c1612;        /* surfaces */
  --bg-2: #2b1f17;        /* alt */
  --cream: #f6e7c1;       /* noodle/al dente */
  --cream-2: #e9d39a;
  --sauce: #c8421f;       /* primary tomato accent */
  --sauce-hot: #ff6b2a;
  --paprika: #f5a056;
  --basil: #6da34d;
  --olive: #8a8a3d;
  --char: #2a1408;
  --border: #3a2a1f;
  --border-hi: #5a3d27;
  --text: #f6e7c1;
  --text-muted: #b39c75;
  --danger: #d6473b;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 4px 0 rgba(0, 0, 0, 0.6);
  --t-ui: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  background:
    radial-gradient(ellipse at 20% 0%, #2a1812 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, #1f1410 0%, transparent 55%),
    var(--bg-0);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  align-items: center;
  gap: 10px;
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

#frame {
  position: relative;
  width: min(calc(100vw - 16px), calc((100dvh - 126px) * 9 / 16), 540px);
  height: auto;
  max-width: 540px;
  max-height: 960px;
  aspect-ratio: 9 / 16;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Decorative tomato-can rim */
#frame::before {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  border-radius: 14px;
  box-shadow:
    inset 0 0 0 2px rgba(246, 231, 193, 0.05),
    inset 0 0 60px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #1a130e;
}

/* HUD */
#hud {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
  font-family: var(--font-body);
}
.hud-left, .hud-right { display: flex; gap: 6px; pointer-events: auto; }

.hud-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(20, 14, 10, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums lining-nums;
}
.hud-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sauce-hot); box-shadow: 0 0 8px var(--sauce-hot); }
.medal-chip { border-color: rgba(245, 160, 86, 0.45); }
.medal-chip.medal-gold { color: #ffe39a; border-color: #f0d066; box-shadow: 0 0 16px rgba(240, 208, 102, 0.18); }
.medal-chip.medal-silver { color: #dfe8ee; border-color: #9fb4c0; }
.medal-chip.medal-bronze { color: #f2b56e; border-color: #b8793d; }
.medal-chip.medal-clear { color: var(--text-muted); border-color: var(--border); }

.hud-btn {
  width: 34px; height: 34px;
  background: rgba(20, 14, 10, 0.78);
  border: 1px solid var(--border);
  color: var(--cream);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  display: grid; place-items: center;
  transition: transform var(--t-ui), background var(--t-ui), border-color var(--t-ui);
}
.hud-btn:hover { background: rgba(40, 24, 16, 0.9); border-color: var(--border-hi); transform: translateY(-1px); }
.hud-btn:active { transform: translateY(0); }

/* Touch */
#touch {
  position: relative;
  width: min(calc(100vw - 16px), 540px);
  min-height: 96px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: auto;
  z-index: 20;
  background: linear-gradient(180deg, rgba(20, 14, 10, 0.72), rgba(12, 7, 5, 0.94));
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(246, 231, 193, 0.05);
}
.touch-pad, .touch-actions { display: flex; gap: 12px; pointer-events: auto; }
.tbtn {
  width: clamp(62px, 18vw, 78px);
  height: clamp(62px, 18vw, 78px);
  border-radius: 999px;
  background: rgba(20, 14, 10, 0.75);
  border: 1.5px solid var(--border-hi);
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: grid; place-items: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 80ms;
}
.tbtn:active { transform: scale(0.92); background: rgba(200, 66, 31, 0.5); }
.tbtn.act-jump {
  width: clamp(82px, 27vw, 116px);
  background: rgba(200, 66, 31, 0.88);
  border-color: #ff8a3c;
  border-radius: 26px;
}
.tbtn.act-switch { display: none; }

@media (hover: none) and (pointer: coarse) {
  #hud { font-size: 11px; }
}

/* Overlays */
.overlay {
  position: absolute; inset: 0;
  z-index: 10;
  display: grid; place-items: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(200, 66, 31, 0.18), transparent 60%),
    rgba(10, 7, 5, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }

.ov-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #221812 0%, #18110c 100%);
  border: 1px solid var(--border-hi);
  border-radius: 16px;
  padding: 28px 28px 24px;
  box-shadow: 0 30px 60px rgba(0,0,0,0.6), inset 0 1px 0 rgba(246,231,193,0.04);
  text-align: center;
}
.ov-card.hidden { display: none; }
.ov-card h2 {
  font-family: var(--font-body);
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 14px;
  color: var(--cream);
  letter-spacing: 0;
  word-spacing: 0.08em;
}

.logo-row { display: flex; align-items: center; gap: 18px; justify-content: center; margin-bottom: 10px; }
.logo-mark { width: 72px; height: 72px; filter: drop-shadow(0 6px 12px rgba(200, 66, 31, 0.4)); }
.title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
  word-spacing: normal;
  margin: 0;
  color: var(--cream);
  text-align: left;
}
.title-sub { color: var(--sauce-hot); }
.tag { color: var(--text-muted); margin: 6px 0 22px; font-size: 14px; }
.footnote { color: #6e5a3f; font-size: 11px; margin-top: 16px; font-family: var(--font-mono); }

.cta-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.btn-primary, .btn-ghost {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform var(--t-ui), background var(--t-ui), border-color var(--t-ui), box-shadow var(--t-ui);
  border: 1px solid transparent;
}
.btn-primary {
  background: linear-gradient(180deg, #d8552b 0%, #b6391a 100%);
  color: #fff5d8;
  border-color: #f5a056;
  box-shadow: 0 4px 0 #6a1f0c, 0 8px 20px rgba(200, 66, 31, 0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #6a1f0c, 0 12px 26px rgba(200, 66, 31, 0.5); }
.btn-primary:active { transform: translateY(1px); box-shadow: 0 2px 0 #6a1f0c; }

.btn-ghost {
  background: transparent;
  color: var(--cream);
  border-color: var(--border-hi);
}
.btn-ghost:hover { background: rgba(246, 231, 193, 0.06); border-color: var(--paprika); }

.controls {
  text-align: left;
  list-style: none;
  padding: 0; margin: 0 0 14px;
  display: grid; gap: 8px;
  font-size: 14px;
  color: var(--cream);
}
.controls li { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.controls .alt { color: var(--text-muted); font-size: 12px; }
kbd {
  display: inline-block;
  background: #2a1d14;
  border: 1px solid var(--border-hi);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--cream);
  min-width: 22px;
  text-align: center;
}
.hint { color: var(--text-muted); font-size: 13px; margin: 6px 0 18px; line-height: 1.5; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin: 4px 0 20px;
}
.level-card {
  background: #1f1610;
  border: 1px solid var(--border-hi);
  color: var(--cream);
  padding: 14px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-display);
  text-align: left;
  transition: transform var(--t-ui), border-color var(--t-ui), background var(--t-ui);
}
.level-card:hover { transform: translateY(-2px); border-color: var(--sauce-hot); background: #2a1d14; }
.level-card .lc-num { font-size: 11px; color: var(--paprika); letter-spacing: 0.1em; font-family: var(--font-mono); }
.level-card .lc-name { font-size: 15px; font-weight: 700; margin-top: 4px; }
.level-card .lc-desc { font-size: 11px; color: var(--text-muted); font-weight: 500; margin-top: 6px; font-family: var(--font-body); letter-spacing: 0; line-height: 1.4; }
.level-card .lc-target { font-size: 10px; color: #d5b16d; margin-top: 7px; font-family: var(--font-mono); line-height: 1.35; }
.level-card .lc-best { font-size: 10px; color: var(--basil); margin-top: 6px; font-family: var(--font-mono); }
.level-card .lc-best.muted { color: #6e5a3f; }
.summary-line { margin: -4px 0 14px; color: var(--text-muted); font: 500 12px/1.4 var(--font-mono); }

.win-stats {
  display: flex; gap: 28px; justify-content: center; margin: 6px 0 18px;
  color: var(--text-muted);
  font-size: 13px;
}
.win-stats b { color: var(--cream); font-family: var(--font-mono); margin-left: 6px; }
.win-medal { margin: -4px 0 6px; font: 900 18px/1.2 var(--font-body); letter-spacing: 0.02em; }
.win-medal.medal-gold { color: #ffe39a; text-shadow: 0 0 18px rgba(240, 208, 102, 0.35); }
.win-medal.medal-silver { color: #dfe8ee; }
.win-medal.medal-bronze { color: #f2b56e; }
.win-medal.medal-clear { color: var(--cream); }
.win-detail { margin: 0 0 18px; color: var(--text-muted); font: 500 12px/1.45 var(--font-mono); }

#debug {
  display: none;
}

@media (max-width: 720px) {
  #frame {
    width: min(calc(100vw - 16px), calc((100dvh - 116px - env(safe-area-inset-bottom)) * 9 / 16), 540px);
    height: auto;
    aspect-ratio: 9 / 16;
    border-radius: 12px;
  }
  #app { gap: 8px; }
  .overlay { padding: 12px; }
  .ov-card { padding: 20px 16px; max-height: calc(100dvh - 150px); overflow: auto; }
  .title { font-size: 26px; }
  .logo-row { gap: 12px; }
  .logo-mark { width: 50px; height: 50px; }
  .tag { font-size: 12px; margin-bottom: 16px; }
  .hud-left { flex-wrap: wrap; max-width: 70%; }
  .hud-chip { font-size: 9px; padding: 4px 7px; gap: 4px; }
  .medal-chip { display: none; }
  .hud-btn { width: 30px; height: 30px; }
  #touch { min-height: 92px; border-radius: 16px; }
}
