:root {
  --ui: 1;
  --panel: rgba(28, 22, 20, 0.82);
  --text: #f4ece0;
  --muted: #c9b9a4;
  --accent: #e8743b;
  --accent-dark: #b9572a;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1c1614;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

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

.hidden { display: none !important; }
body:not(.touch) .touch-only { display: none !important; }
body.touch .pc-only { display: none !important; }

.panel {
  background: var(--panel);
  border-radius: calc(10px * var(--ui));
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.label {
  color: var(--muted);
  font-size: calc(13px * var(--ui));
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.label span { color: var(--text); }
.label.accent { color: var(--accent); }
.key {
  border: 1px solid var(--muted);
  border-radius: 4px;
  padding: 0 0.35em;
  font-size: 0.85em;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.hud-box { padding: calc(8px * var(--ui)) calc(14px * var(--ui)); min-width: calc(110px * var(--ui)); }
.hud-left {
  position: absolute;
  top: calc(12px + var(--safe-t));
  left: calc(12px + var(--safe-l));
}
.hud-right {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  display: flex;
  gap: calc(8px * var(--ui));
  align-items: flex-start;
  text-align: right;
}
.big {
  font-size: calc(32px * var(--ui));
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.lives { color: var(--accent); letter-spacing: 0.1em; }
.hud-btn {
  pointer-events: auto;
  border: 0;
  color: var(--text);
  font-weight: 800;
  font-size: calc(18px * var(--ui));
  width: calc(46px * var(--ui));
  height: calc(46px * var(--ui));
  cursor: pointer;
}
.hud-flap {
  position: absolute;
  left: 50%;
  bottom: calc(14px + var(--safe-b));
  transform: translateX(-50%);
  text-align: center;
  min-width: calc(180px * var(--ui));
}
.meter {
  margin-top: calc(6px * var(--ui));
  height: calc(10px * var(--ui));
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  overflow: hidden;
}
#flap-fill { height: 100%; width: 100%; background: var(--accent); transition: background 0.2s; }
#flap-fill.ready { background: #f2b05e; }

/* ---------- touch ---------- */
#touch-zone { position: fixed; inset: 0; z-index: 2; display: none; }
body.touch.playing #touch-zone { display: block; }

#btn-flap {
  --charge: 1;
  position: fixed;
  z-index: 6;
  right: calc(22px + var(--safe-r));
  bottom: calc(22px + var(--safe-b));
  width: calc(112px * var(--ui));
  height: calc(112px * var(--ui));
  border-radius: 50%;
  border: calc(4px * var(--ui)) solid rgba(244, 236, 224, 0.5);
  color: var(--text);
  font: 800 calc(18px * var(--ui)) "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.12em;
  background:
    linear-gradient(to top, var(--accent) calc(var(--charge) * 100%), rgba(28, 22, 20, 0.82) calc(var(--charge) * 100%));
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
  touch-action: none;
}
#btn-flap.ready { border-color: #ffd59e; }
#btn-flap:active { transform: scale(0.95); }

/* ---------- feedback ---------- */
#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(170, 20, 10, 0.75) 100%);
  transition: opacity 0.6s;
}
#vignette.on { opacity: 1; transition: opacity 0.05s; }

#banner {
  position: fixed;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: 7;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.7);
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner-title {
  font-size: calc(54px * var(--ui));
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
}
#banner-sub {
  font-size: calc(20px * var(--ui));
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #ffc38f;
}

/* ---------- menus ---------- */
.menu {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 14, 12, 0.35);
}
.menu.open { display: flex; }
.menu-panel {
  width: min(92vw, calc(380px * var(--ui)));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: calc(22px * var(--ui));
  display: flex;
  flex-direction: column;
  gap: calc(10px * var(--ui));
  text-align: center;
}
.title {
  margin: 0;
  font-size: calc(50px * var(--ui));
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
}
.title span { color: var(--accent); }
h2 {
  margin: 0 0 calc(4px * var(--ui));
  font-size: calc(26px * var(--ui));
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.tagline { margin: 0 0 calc(6px * var(--ui)); color: var(--muted); font-size: calc(15px * var(--ui)); }
.howto { color: var(--muted); font-size: calc(13px * var(--ui)); line-height: 1.5; margin-top: calc(4px * var(--ui)); }

.btn {
  border: 0;
  border-radius: calc(8px * var(--ui));
  padding: calc(12px * var(--ui)) calc(16px * var(--ui));
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font: 700 calc(16px * var(--ui)) "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, 0.18); }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: #f0874f; }
.btn.small { padding: calc(8px * var(--ui)) calc(14px * var(--ui)); flex: 1; }
.btn.selected { background: var(--accent); }
.row { display: flex; gap: calc(8px * var(--ui)); justify-content: center; }

.result > span { font-size: calc(48px * var(--ui)); font-weight: 900; }

#go-name {
  flex: 2;
  min-width: 0;
  border: 2px solid rgba(244, 236, 224, 0.3);
  border-radius: calc(8px * var(--ui));
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font: 700 calc(16px * var(--ui)) "Segoe UI", system-ui, sans-serif;
  padding: calc(8px * var(--ui));
  user-select: text;
  -webkit-user-select: text;
}

#score-list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
  text-align: left;
}
#score-list li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: calc(6px * var(--ui)) calc(8px * var(--ui));
  font-size: calc(16px * var(--ui));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
#score-list li::before { content: counter(rank) "."; color: var(--accent); font-weight: 800; width: 1.6em; }
#score-list li .name { flex: 1; }
#score-list li .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
#score-list li.empty::before { content: ""; width: 0; }

#rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #1c1614;
  font-size: 18px;
  font-weight: 700;
}
.rotate-icon { font-size: 54px; color: var(--accent); }
@media (orientation: portrait) {
  body.touch #rotate-overlay { display: flex; }
}

/* small landscape phones: tighten the HUD so it doesn't cover the playfield */
@media (max-height: 460px) {
  .big { font-size: calc(24px * var(--ui)); }
  .label { font-size: calc(11px * var(--ui)); }
  .hud-box { padding: calc(5px * var(--ui)) calc(10px * var(--ui)); min-width: calc(90px * var(--ui)); }
  #banner-title { font-size: calc(38px * var(--ui)); }
  .title { font-size: calc(38px * var(--ui)); }
  .menu-panel { gap: calc(7px * var(--ui)); padding: calc(16px * var(--ui)); }
  .btn { padding: calc(9px * var(--ui)) calc(14px * var(--ui)); }
}
