/* Low Poly Mario - interface styling. Deep green-gray backing, warm off-white text. */

:root {
  --ink: #263b36;
  --ink-deep: #1b2b27;
  --paper: #fff6d9;
  --gold: #ffd24a;
  --gold-deep: #d9a51e;
  --line: rgba(255, 246, 217, 0.22);
  --danger: #ff8a72;
  --ok: #9cf29c;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #9dd8ed;
  color: var(--paper);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

/* ------------------------------------------------------------------ HUD */

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 0;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.hud-side {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-right {
  justify-content: flex-end;
}

.hud-item {
  background: rgba(38, 59, 54, 0.86);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 11px 6px;
  min-width: 64px;
  box-shadow: 0 4px 14px rgba(15, 28, 24, 0.25);
  backdrop-filter: blur(4px);
}

.hud-label {
  display: block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 246, 217, 0.66);
  line-height: 1.2;
}

.hud-value {
  display: block;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--paper);
  line-height: 1.25;
}

.hud-center {
  align-self: center;
  margin-top: 2px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(38, 59, 54, 0.72);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
}

#hud-hurry {
  display: block;
  color: var(--danger);
  font-size: 10px;
  letter-spacing: 0.2em;
  margin-top: 2px;
  animation: pulse 0.9s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

#progress {
  position: absolute;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  width: min(44vw, 420px);
  height: 5px;
  border-radius: 999px;
  background: rgba(38, 59, 54, 0.55);
  border: 1px solid rgba(255, 246, 217, 0.18);
  pointer-events: none;
  overflow: hidden;
}

#progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #ffe9a3);
  border-radius: 999px;
  transition: width 0.2s linear;
}

/* --------------------------------------------------------------- buttons */

#top-controls {
  position: absolute;
  top: 82px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 5;
  pointer-events: auto;
}

#top-controls .icon-btn {
  pointer-events: auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(38, 59, 54, 0.86);
  color: var(--paper);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.12s ease;
  backdrop-filter: blur(4px);
}

.icon-btn:hover {
  background: rgba(56, 83, 76, 0.95);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

.icon-btn.is-muted {
  color: var(--danger);
  text-decoration: line-through;
}

/* ------------------------------------------------------------------ toast */

#toast {
  position: absolute;
  top: 96px;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(38, 59, 54, 0.92);
  border: 1px solid var(--line);
  color: var(--paper);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 6;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------------------------------------------------------- overlay */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: radial-gradient(ellipse at center, rgba(22, 38, 33, 0.28), rgba(14, 24, 21, 0.62));
  z-index: 10;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(560px, 100%);
  max-height: min(82vh, 720px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(180deg, rgba(43, 67, 61, 0.98), rgba(32, 51, 46, 0.98));
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 26px 28px;
  box-shadow: 0 22px 60px rgba(8, 18, 15, 0.5), inset 0 1px 0 rgba(255, 246, 217, 0.14);
  text-align: center;
}

.panel h1 {
  margin: 0 0 6px;
  font-size: clamp(30px, 6.4vw, 50px);
  line-height: 1.02;
  letter-spacing: 0.01em;
  color: var(--gold);
  text-shadow: 0 3px 0 #8a5a12, 0 6px 16px rgba(0, 0, 0, 0.3);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: clamp(26px, 5.6vw, 38px);
  color: var(--gold);
  letter-spacing: 0.02em;
}

.panel h3 {
  margin: 18px 0 8px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 246, 217, 0.62);
  font-weight: 700;
}

.panel p {
  margin: 8px 0;
  font-size: 14px;
  line-height: 1.5;
  color: rgba(255, 246, 217, 0.85);
}

.kicker {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(255, 246, 217, 0.55);
  font-weight: 700;
}

.controls-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 18px;
  text-align: left;
  margin: 12px 0 4px;
  font-size: 12.5px;
  color: rgba(255, 246, 217, 0.82);
}

.controls-list div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px dashed rgba(255, 246, 217, 0.12);
  padding-bottom: 4px;
}

.controls-list kbd {
  font-family: "Consolas", "SFMono-Regular", monospace;
  background: rgba(255, 246, 217, 0.12);
  border: 1px solid rgba(255, 246, 217, 0.18);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--paper);
  white-space: nowrap;
}

.best-row {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin: 12px 0 4px;
  font-size: 12px;
  color: rgba(255, 246, 217, 0.7);
}

.best-row strong {
  display: block;
  color: var(--paper);
  font-size: 16px;
  margin-top: 2px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 11px;
  padding: 12px 24px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  background: var(--gold);
  color: var(--ink-deep);
  box-shadow: 0 4px 0 var(--gold-deep), 0 8px 16px rgba(0, 0, 0, 0.22);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 var(--gold-deep), 0 10px 20px rgba(0, 0, 0, 0.24);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--gold-deep), 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn.secondary {
  background: rgba(255, 246, 217, 0.12);
  color: var(--paper);
  box-shadow: none;
  border: 1px solid var(--line);
}

.btn.secondary:hover {
  background: rgba(255, 246, 217, 0.2);
  transform: translateY(-1px);
  box-shadow: none;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0 4px;
  text-align: left;
}

.result-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: rgba(14, 26, 22, 0.35);
  border: 1px solid rgba(255, 246, 217, 0.1);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 12.5px;
}

.result-row span:first-child {
  color: rgba(255, 246, 217, 0.65);
}

.result-row span:last-child {
  font-weight: 800;
}

.result-total {
  grid-column: 1 / -1;
  background: rgba(255, 210, 74, 0.12);
  border-color: rgba(255, 210, 74, 0.38);
  font-size: 16px;
}

.badge {
  display: inline-block;
  margin: 8px 6px 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink-deep);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  animation: badge-pop 0.5s ease;
}

@keyframes badge-pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.hint {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: rgba(255, 246, 217, 0.5);
}

/* ------------------------------------------------------------------- fade */

#fade {
  position: absolute;
  inset: 0;
  background: #0a1210;
  opacity: 0;
  pointer-events: none;
  z-index: 8;
}

/* ---------------------------------------------------------- touch controls */

#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  z-index: 7;
  pointer-events: none;
}

.touch-cluster {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

.touch-btn {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 246, 217, 0.35);
  background: rgba(38, 59, 54, 0.62);
  color: var(--paper);
  font-family: inherit;
  font-size: 20px;
  font-weight: 800;
  display: grid;
  place-items: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
  transition: transform 0.06s ease, background 0.06s ease;
}

.touch-btn:active,
.touch-btn.is-held {
  transform: scale(0.94);
  background: rgba(255, 210, 74, 0.32);
}

.touch-btn.touch-small {
  width: 52px;
  height: 52px;
  font-size: 16px;
  margin-bottom: 2px;
}

.touch-btn.touch-jump {
  width: 78px;
  height: 78px;
  font-size: 13px;
  letter-spacing: 0.06em;
  background: rgba(255, 210, 74, 0.28);
  border-color: rgba(255, 210, 74, 0.55);
}

.touch-btn.touch-run {
  width: 64px;
  height: 64px;
  font-size: 12px;
  letter-spacing: 0.06em;
  background: rgba(226, 59, 44, 0.28);
  border-color: rgba(226, 59, 44, 0.55);
}

@media (pointer: coarse), (max-width: 900px) {
  #touch-controls {
    display: flex;
  }

  #hud {
    padding: 8px 10px 0;
  }

  .hud-item {
    padding: 4px 8px 5px;
    min-width: 52px;
  }

  .hud-value {
    font-size: 15px;
  }

  #progress {
    top: 64px;
    width: 56vw;
  }

  .panel {
    padding: 20px 18px;
  }

  .controls-list {
    grid-template-columns: 1fr;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 520px) {
  .hud-item {
    padding: 3px 8px 4px;
  }

  .hud-value {
    font-size: 14px;
  }

  #progress {
    top: 57px;
  }

  .panel {
    padding: 16px 20px;
  }

  .panel h1 {
    font-size: 30px;
  }

  .panel p {
    font-size: 12px;
  }

  .touch-btn {
    width: 54px;
    height: 54px;
  }

  .touch-btn.touch-jump {
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 520px) {
  .hud-center {
    display: none;
  }

  .hud-side {
    gap: 6px;
  }

  .hud-item {
    min-width: 0;
  }

  .hud-label {
    font-size: 8px;
  }

  .hud-value {
    font-size: 14px;
  }

  .hud-power {
    display: none;
  }

  #top-controls {
    top: 64px;
    right: 10px;
  }

  #toast {
    top: 84px;
    font-size: 11px;
    max-width: 90vw;
    white-space: normal;
    text-align: center;
  }
}
