:root {
  color-scheme: dark;
  --ink: #eef3f4;
  --muted: #9eabb6;
  --night: #070c14;
  --panel: rgba(9, 16, 27, 0.93);
  --line: rgba(198, 215, 223, 0.18);
  --gold: #f4ba38;
  --gold-bright: #ffd66f;
  --danger: #d47667;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: #03060b;
  color: var(--ink);
  font-family: "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.app {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(0px, 2vw, 24px);
}

.game-frame {
  position: relative;
  width: min(100%, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--night);
  border: 1px solid rgba(211, 225, 230, 0.15);
  box-shadow: 0 24px 80px #000, inset 0 0 90px rgba(0, 0, 0, 0.55);
  touch-action: manipulation;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  z-index: 4;
  inset: clamp(10px, 2.2vw, 28px) clamp(12px, 2.6vw, 34px) auto;
  display: flex;
  gap: clamp(14px, 3vw, 38px);
  align-items: flex-start;
  pointer-events: none;
}

.hud-item { display: grid; gap: 2px; text-transform: uppercase; }
.hud-record { display: none; }
.hud-item span { color: var(--muted); font-size: clamp(0.66rem, 1.25vw, 0.9rem); letter-spacing: 0.16em; }
.hud-item strong { font: 800 clamp(1.05rem, 2.4vw, 1.75rem)/1 ui-monospace, monospace; letter-spacing: 0.08em; text-shadow: 0 2px 8px #000; }
.hud .icon-button { margin-left: auto; pointer-events: auto; }

.icon-button {
  width: clamp(38px, 4vw, 48px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(6, 11, 19, 0.72);
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(1rem, 2vw, 1.25rem);
}
.icon-button:hover, .icon-button:focus-visible { border-color: var(--gold); outline: none; }

.screen {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 38px);
  background: radial-gradient(circle at 31% 48%, transparent 0 20%, rgba(3, 7, 13, 0.43) 68%, rgba(1, 3, 7, 0.78));
}

.panel {
  width: min(92%, 430px);
  padding: clamp(20px, 4vw, 42px);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(12px);
}

.login-panel { margin-right: min(31%, 340px); }
.game-logo { display: block; width: clamp(112px, 15vw, 190px); height: clamp(112px, 15vw, 190px); object-fit: contain; margin: -8px auto 8px; filter: drop-shadow(0 10px 18px rgba(0,0,0,.65)); }
.login-main h1 { text-align: center; }
.eyebrow { margin: 0 0 8px; color: var(--gold); font-size: clamp(0.68rem, 1.25vw, 0.82rem); font-weight: 800; letter-spacing: 0.2em; }
h1, h2 { margin: 0; text-transform: uppercase; }
h1 { font-size: clamp(2.3rem, 6.6vw, 5rem); line-height: 0.79; letter-spacing: -0.055em; }
h1 span { color: transparent; -webkit-text-stroke: 1.5px var(--ink); }
h2 { font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1; }

form { display: grid; margin-top: clamp(20px, 3vw, 34px); }
label { margin-bottom: 8px; color: var(--ink); font-size: 0.92rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
input {
  min-height: 50px;
  width: 100%;
  padding: 0 15px;
  border: 1px solid rgba(204, 219, 227, 0.28);
  border-radius: 0;
  outline: none;
  background: rgba(2, 7, 12, 0.8);
  color: var(--ink);
  font-size: 1rem;
}
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(244, 186, 56, 0.14); }
.field-hint, .key-hint { margin: 7px 0 0; color: var(--muted); font-size: clamp(0.72rem, 1.3vw, 0.82rem); }
.form-error { min-height: 19px; margin: 5px 0 8px; color: #ef9b8d; font-size: 0.82rem; }

.primary-button, .secondary-button, .text-button {
  min-height: 48px;
  border: 1px solid transparent;
  padding: 0 20px;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.primary-button { background: var(--gold); color: #171004; box-shadow: 0 8px 26px rgba(244, 186, 56, 0.2); }
.primary-button:hover, .primary-button:focus-visible { background: var(--gold-bright); outline: none; }
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.secondary-button { border-color: var(--line); background: transparent; color: var(--ink); }
.secondary-button:hover, .secondary-button:focus-visible { border-color: var(--gold); outline: none; }
.text-button { width: 100%; margin-top: 10px; background: transparent; color: var(--muted); }
.text-button:hover, .text-button:focus-visible { color: var(--gold-bright); outline: none; }

.countdown {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  background: rgba(3, 7, 13, 0.27);
  text-shadow: 0 4px 18px #000;
}
.countdown p { margin: 0; color: var(--gold-bright); font-weight: 900; font-size: clamp(0.8rem, 2vw, 1.1rem); letter-spacing: 0.14em; }
.countdown strong { font-size: clamp(5rem, 14vw, 10rem); line-height: 1; }

.result-panel { width: min(92%, 540px); }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 24px 0 12px; background: var(--line); }
.result-grid div { padding: 12px 14px; background: #0b131f; }
.result-grid dt { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; }
.result-grid dd { margin: 5px 0 0; color: var(--ink); font: 800 clamp(1.1rem, 2.6vw, 1.55rem)/1 ui-monospace, monospace; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.server-status { min-height: 18px; margin: 8px 0; color: var(--muted); font-size: 0.82rem; }

.desktop-ranking {
  position: absolute;
  z-index: 7;
  top: 24px;
  right: 24px;
  bottom: 24px;
  display: none;
  width: min(22%, 270px);
  padding: 20px 18px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--gold);
  background: rgba(6, 12, 21, 0.88);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px);
  overflow: hidden;
  pointer-events: none;
}
.ranking-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.ranking-title span { color: var(--gold); font: 900 0.72rem/1 ui-monospace, monospace; letter-spacing: 0.14em; }
.ranking-title h2 { font-size: clamp(1.15rem, 2vw, 1.55rem); }
.compact-ranking-list { display: grid; gap: 2px; margin: 10px 0 0; padding: 0; list-style: none; counter-reset: ranking; }
.compact-ranking-list li { counter-increment: ranking; display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 38px; padding: 6px 4px; border-bottom: 1px solid rgba(198, 215, 223, 0.09); }
.compact-ranking-list li::before { content: counter(ranking); color: var(--gold); font: 800 0.75rem/1 ui-monospace, monospace; }
.compact-ranking-list .compact-name { overflow: hidden; font-size: 0.82rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.compact-ranking-list .compact-score { color: var(--muted); font: 800 0.8rem/1 ui-monospace, monospace; }
.compact-ranking-list li.current-user .compact-name,
.compact-ranking-list li.current-user .compact-score { color: var(--gold-bright); }
.compact-ranking-status { margin: 12px 0 0; color: var(--muted); font-size: 0.76rem; }
.mobile-start-ranking { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); }
.mobile-start-ranking h2 { font-size: 0.82rem; letter-spacing: 0.1em; }
.mobile-start-ranking .compact-ranking-list li { min-height: 30px; padding-block: 3px; }

@media (min-width: 901px) and (hover: hover) and (pointer: fine) {
  .desktop-ranking { display: block; }
  .mobile-start-ranking { display: none; }
}

.leaderboard-panel { width: min(96%, 820px); max-height: 90%; display: flex; flex-direction: column; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.close-button { flex: 0 0 auto; font-size: 1.7rem; line-height: 1; }
.current-place { margin: 18px 0 8px; padding: 10px 12px; border-left: 2px solid var(--gold); background: rgba(244, 186, 56, 0.08); font-size: 0.9rem; }
.table-wrap { margin-top: 18px; overflow: auto; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: clamp(0.76rem, 1.6vw, 0.92rem); }
th, td { padding: 10px 12px; border-bottom: 1px solid rgba(198, 215, 223, 0.1); text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; background: #101925; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
th:nth-child(2), td:nth-child(2) { width: 100%; text-align: left; }
tbody tr.current-user td { color: var(--gold-bright); background: rgba(244, 186, 56, 0.07); }

.orientation-note { display: none; }

@media (max-width: 740px) {
  .app { padding: 0; }
  .game-frame { width: 100vw; max-height: none; border: 0; }
  .panel { padding: 20px; }
  .login-panel { margin: 0; }
  .game-logo { width: clamp(110px, 30vw, 170px); height: clamp(110px, 30vw, 170px); }
  .field-hint { display: none; }
  form { margin-top: 16px; }
  input, .primary-button, .secondary-button { min-height: 44px; }
}

@media (max-width: 740px), (pointer: coarse) {
  .hud-score, .hud-coins { display: none; }
  .hud-record { display: grid; }
}

@media (orientation: portrait) and (max-width: 700px) {
  .game-frame { width: 100vw; height: 100dvh; aspect-ratio: auto; }
  #game-canvas { object-fit: cover; object-position: 18% center; }
  .login-panel { margin: 0; }
  .screen { padding: 16px; }
  .orientation-note {
    position: absolute;
    z-index: 8;
    right: 10px;
    bottom: 10px;
    left: 10px;
    display: block;
    padding: 8px 10px;
    border: 1px solid rgba(244, 186, 56, 0.3);
    background: rgba(7, 12, 20, 0.86);
    color: var(--muted);
    font-size: 0.72rem;
    text-align: center;
    pointer-events: none;
  }
  .orientation-note span { color: var(--gold); }
  .leaderboard-panel { max-height: 86%; }
  th, td { padding: 8px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app { padding: 0; }
  .game-frame { width: min(100vw, calc(100dvh * 16 / 9)); max-height: 100dvh; border-block: 0; }
  .panel { padding: 14px 22px; }
  .login-panel { width: min(94%, 650px); margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 18px; }
  .eyebrow { margin-bottom: 4px; font-size: 0.68rem; }
  h1 { font-size: 3rem; }
  h2 { font-size: 1.65rem; }
  form { margin-top: 11px; }
  label { margin-bottom: 4px; font-size: 0.76rem; }
  input, .primary-button, .secondary-button { min-height: 40px; }
  .field-hint, .key-hint { display: none; }
  .form-error { min-height: 14px; margin: 2px 0 4px; font-size: 0.7rem; }
  .text-button { min-height: 34px; margin-top: 2px; }
  .mobile-start-ranking { margin-top: 0; padding: 4px 0 0 16px; border-top: 0; border-left: 1px solid var(--line); }
  .mobile-start-ranking .compact-ranking-list { margin-top: 5px; }
  .mobile-start-ranking .compact-ranking-list li { min-height: 29px; }
  .result-grid { margin: 10px 0 5px; }
  .result-grid div { padding: 7px 10px; }
  .button-row { margin-top: 7px; }
  .server-status { min-height: 14px; margin: 4px 0; }
  .leaderboard-panel { max-height: 96%; }
  .leaderboard-panel .table-wrap { margin-top: 8px; }
  .leaderboard-panel th, .leaderboard-panel td { padding: 6px 9px; }
  .hud-score, .hud-coins { display: none; }
  .hud-record { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}

#lives { color: #ef9b8d; letter-spacing: 0.08em; }
#abilities { min-height: 1em; }
#lemonka-status { font-size: clamp(8px, 1vw, 12px); letter-spacing: 0; }
.timeline-wrap { position: absolute; top: 65px; left: 1%; width: 96%; color: #aebdb8; font-size: clamp(9px,1vw,12px); }
#next-reward { margin-bottom: 9px; }
#timeline { height: 4px; background: #34403c; position: relative; margin: 0 20px; }
#timeline-fill { height: 100%; background: #e7c774; }
#timeline span { position: absolute; top: 10px; transform: translateX(-50%); white-space: nowrap; }
#timeline .reached { color: #ffe098; }
#phase-notice { position: absolute; top: 23%; left: 50%; transform: translateX(-50%); z-index: 4; display: grid; gap: 8px; text-align: center; padding: 16px 25px; color: #ffe19a; background: #101b20e8; border-top: 2px solid #e7c774; pointer-events: none; font-size: clamp(10px,1.6vw,20px); }
.result-panel { max-height: 95%; overflow: auto; }
@media(max-height:550px) { .timeline-wrap { top: 43px; } .hud { gap: 14px; } .result-grid { margin: 10px 0; } .result-grid div { padding: 6px; } }
/* Keep score and coins visible on phones; record is secondary. */
.hud .hud-score, .hud .hud-coins { display: grid; }
.hud .hud-record { display: none; }
@media (max-width: 900px), (max-height: 550px) {
  .hud { gap: 12px; }
  .hud-item strong { font-size: clamp(12px,2vw,18px); }
  .hud-item span { font-size: 9px; letter-spacing: 0.05em; }
  .timeline-wrap { top: 43px; }
  .hud .icon-button { width: 32px; }
}
.result-grid > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
/* Static timeline positions comply with nginx's style-src self policy. */
#timeline [data-marker="start"] { left: 0; }
#timeline [data-marker="helper"] { left: 16.666667%; }
#timeline [data-marker="boots"] { left: 33.333333%; }
#timeline [data-marker="shield"] { left: 50%; }
#timeline [data-marker="base"] { left: 66.666667%; }
#timeline [data-marker="summit"] { left: 100%; }
/* Desktop ranking occupies its own column; never covers Canvas or HUD. */
@media (min-width: 901px) and (hover: hover) and (pointer: fine) {
  .app { grid-template-columns: 180px minmax(0, 1fr); gap: 16px; max-width: calc(100dvh * 16 / 9 + 244px); margin-inline: auto; }
  .desktop-ranking { position: static; align-self: start; margin-top: 100px; width: 180px; padding: 12px 10px; height: auto; backdrop-filter: none; }
  .desktop-ranking .ranking-title h2 { font-size: 1rem; }
  .desktop-ranking .ranking-title span { display: none; }
  .desktop-ranking .compact-ranking-list li { min-height: 29px; padding: 4px 0; gap: 4px; grid-template-columns: 15px minmax(0,1fr) auto; }
  .desktop-ranking .compact-name, .desktop-ranking .compact-score { font-size: .7rem; }
  .game-frame { width: 100%; }
}

@media (min-width:901px) and (hover:hover) and (pointer:fine) {
 .desktop-ranking { pointer-events:auto; max-height:calc(100dvh - 150px); overflow-y:auto; overscroll-behavior:contain; scrollbar-width:thin; }
 .desktop-ranking .ranking-title { position:sticky; top:-12px; background:#080f18; padding-top:8px; }
}

/* Presentation changes are confined to the home and result screens. */
#login-screen, #gameover-screen {
  grid-template-columns: minmax(0, 1.15fr) minmax(260px, .85fr);
  gap: clamp(24px, 4vw, 64px);
  padding: clamp(24px, 5vw, 72px);
  overflow: auto;
  background: radial-gradient(ellipse at 30% 42%, rgba(105,75,33,.15), transparent 55%), rgba(5,9,14,.94);
}
.home-brand, .result-brand { width: 100%; text-align: center; align-self: center; }
#login-screen .home-logo, #gameover-screen .home-logo {
  display: block; width: min(100%, 380px); height: min(38vw, 46dvh);
  object-fit: contain; margin: 0 auto 20px;
  filter: drop-shadow(0 20px 35px rgba(0,0,0,.4));
}
#login-screen h1 { font-size: clamp(23px, 2.7vw, 40px); line-height: 1.1; letter-spacing: -.04em; font-weight: 700; }
#login-screen h1 span { color: #d6b878; -webkit-text-stroke: 0; }
.home-brand p { margin: 12px 0 0; color: #858d95; font-size: 13px; letter-spacing: .04em; }
#login-screen .login-panel, #gameover-screen .result-panel {
  width: 100%; max-width: 360px; margin: 0; padding: 0; border: 0;
  background: transparent; box-shadow: none; backdrop-filter: none;
  display: block; max-height: none; overflow: visible;
}
#login-screen .entry-label { color: #91989f; font-size: 10px; letter-spacing: .18em; margin: 0 0 26px; }
#login-screen form { margin-top: 0; }
#login-screen label { font-size: 12px; font-weight: 400; letter-spacing: .02em; text-transform: none; color: #c3c7cc; }
#login-screen input { min-height: 48px; border-radius: 8px; background: rgba(255,255,255,.035); border-color: #30353c; }
#login-screen .field-hint { font-size: 10px; line-height: 1.5; color: #777f89; }
#login-screen .primary-button, #gameover-screen .primary-button {
  border-radius: 8px; background: #dbbb7b; box-shadow: none; letter-spacing: .02em;
  font-weight: 700; text-transform: none;
}
#login-screen .primary-button:hover, #gameover-screen .primary-button:hover { background: #ecd3a0; }
#login-screen .text-button, #gameover-screen .secondary-button {
  font-size: 12px; font-weight: 400; letter-spacing: .02em; text-transform: none; border-radius: 8px;
}
#login-screen .mobile-start-ranking { margin-top: 18px; }
#gameover-screen .eyebrow { font-size: 10px; font-weight: 400; color: #ac9875; letter-spacing: .16em; }
#gameover-screen h2 { font-size: clamp(24px, 3vw, 40px); line-height: 1.1; letter-spacing: -.04em; text-transform: none; }
#gameover-screen .result-grid { background: transparent; gap: 16px 24px; margin: 24px 0 14px; }
#gameover-screen .result-grid div { background: transparent; padding: 0 0 10px; border-bottom: 1px solid #252b32; }
#gameover-screen .result-grid div:first-child { grid-column: 1 / -1; }
#gameover-screen #final-score { color: #e3c58e; font-size: clamp(36px, 4vw, 54px); font-weight: 500; }
#gameover-screen .result-grid dt { font-size: 10px; text-transform: none; letter-spacing: .02em; color: #8c959e; }
#gameover-screen .result-grid dd { font-size: 18px; font-weight: 500; }
#gameover-screen .server-status, #gameover-screen .key-hint { font-size: 10px; line-height: 1.5; color: #858d95; }
@media (max-width: 700px) and (orientation: portrait) {
  #login-screen, #gameover-screen { grid-template-columns: minmax(0,1fr); gap: 24px; padding: 26px 24px; align-content: start; }
  #login-screen .home-logo, #gameover-screen .home-logo { height: 220px; width: 240px; margin-bottom: 12px; }
  #gameover-screen .home-logo { height: 140px; }
  #login-screen .entry-label { display: none; }
  #login-screen .login-panel, #gameover-screen .result-panel { max-width: 340px; }
}
@media (max-height: 550px) and (orientation: landscape) {
  #login-screen, #gameover-screen { padding: 20px 32px; gap: 28px; }
  #login-screen .home-logo, #gameover-screen .home-logo { height: 48dvh; margin-bottom: 8px; }
  #login-screen .entry-label { margin-bottom: 12px; }
  #login-screen .mobile-start-ranking { display: none; }
  #gameover-screen .result-grid { gap: 8px 20px; margin: 12px 0; }
  #gameover-screen .result-grid div { padding-bottom: 5px; }
}
