:root {
  --sand: #f6e2b8;
  --sea: #2a9fd0;
  --deep: #12475e;
  --panel: rgba(255, 253, 246, 0.96);
  --ink: #1d3a44;
  --accent: #ff8a4c;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 50% 0%, #7fd4f0 0%, var(--sea) 45%, var(--deep) 100%);
  display: flex;
  justify-content: center;
  overflow: hidden;
  touch-action: manipulation;
}

.app {
  width: min(100vw, 440px);
  height: 100%;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ------------------------------------------------------------------ */
/* Head up display                                                     */
/* ------------------------------------------------------------------ */

.hud {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.hud-box {
  flex: 1;
  background: var(--panel);
  border-radius: 14px;
  padding: 6px 10px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}

.hud-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-next {
  flex: 0 0 82px;
  align-items: center;
}

.hud-next canvas {
  width: 44px;
  height: 44px;
}

/* ------------------------------------------------------------------ */
/* Board                                                               */
/* ------------------------------------------------------------------ */

.board {
  position: relative;
  flex: 1;
  min-height: 0;
  aspect-ratio: 400 / 640;
  margin: 0 auto;
  border-radius: 18px;
  border: 8px solid #b9793f;
  background: #f6e6c4;
  box-shadow:
    inset 0 0 24px rgba(0, 0, 0, 0.12),
    0 8px 0 rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* Overlay                                                             */
/* ------------------------------------------------------------------ */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(10, 40, 55, 0.55);
  backdrop-filter: blur(3px);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 16px;
  padding: 18px 16px;
  text-align: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
}

.panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.panel p {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.45;
  opacity: 0.85;
}

.panel-score {
  font-size: 20px;
  font-weight: 700;
  opacity: 1;
}

.panel-score.hidden,
.submit-row.hidden {
  display: none;
}

.submit-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 9px 10px;
  border: 2px solid rgba(29, 58, 68, 0.2);
  border-radius: 10px;
  background: #fff;
  color: inherit;
}

input[type="text"]:focus-visible,
button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  font-weight: 600;
  padding: 9px 14px;
  border: none;
  border-radius: 10px;
  background: #2a9fd0;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button.primary {
  width: 100%;
  background: var(--accent);
  font-size: 17px;
  padding: 12px;
}

.note {
  min-height: 18px;
  font-size: 13px;
  color: #a0522d;
}

/* ------------------------------------------------------------------ */
/* Leaderboard                                                         */
/* ------------------------------------------------------------------ */

.scores {
  margin-top: 14px;
  text-align: left;
}

.scores h2 {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}

.scores ol {
  margin: 0;
  padding-left: 22px;
  font-size: 14px;
}

.scores li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(29, 58, 68, 0.15);
}

.entry-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.scores li.empty {
  justify-content: center;
  opacity: 0.6;
  list-style: none;
  margin-left: -22px;
}

/* ------------------------------------------------------------------ */
/* Tier strip                                                          */
/* ------------------------------------------------------------------ */

.ladder {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 5px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}

.ladder-cell {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(120, 190, 220, 0.18);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
