:root {
  color-scheme: dark;
  --cyan: #63fff2;
  --green: #79ff8b;
  --yellow: #ffe66f;
  --orange: #ff9b54;
  --red: #ff4f70;
  --blue: #4fa8ff;
  --ink: #02060c;
  --panel: rgba(3, 15, 24, 0.94);
  --line: rgba(99, 255, 242, 0.42);
  font-family: "Lucida Console", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #000; }
body { color: #eaffff; user-select: none; }
button, input, select { font: inherit; }
button { touch-action: manipulation; }

#app { position: fixed; inset: 0; overflow: hidden; background: radial-gradient(circle at 50% 40%, #071929 0, #02060d 44%, #000 100%); }
#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: crosshair; }
/* Suppress browser pan/zoom/double-tap-zoom so a steering drag never scrolls the page. */
#gameCanvas { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.retro-pixels #gameCanvas { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---- Touch controls (shown only when touch input is detected) ---- */
.touch-controls { position: absolute; inset: 0; z-index: 11; pointer-events: none; --stick: 112px; }
/* A panel is open: the controls would only show through it (see syncPanelOpen in game.js). */
body.panel-open .touch-controls, body.panel-open .touch-controls * { visibility: hidden; transition: none; }
.touch-controls.hidden { display: none; }
/* Floating stick: js/touch-input.js moves it under the thumb that starts a steering touch and drags the knob.
   Before the first steering touch it rests, faint, at its home position so a new player sees where to start. */
.touch-stick {
  position: absolute; left: 0; top: 0;
  width: var(--stick); height: var(--stick); margin: calc(var(--stick) / -2) 0 0 calc(var(--stick) / -2);
  border: 1px solid rgba(99, 255, 242, .3); border-radius: 50%;
  background: radial-gradient(circle, rgba(99,255,242,.10), rgba(2,10,18,.34));
  pointer-events: none; opacity: 0; will-change: transform, opacity;
}
.touch-stick.is-hint { opacity: .5; }
.touch-stick.is-active { opacity: 1; border-color: rgba(99, 255, 242, .6); }
.touch-knob {
  position: absolute; left: 50%; top: 50%;
  width: 44%; height: 44%; margin: -22% 0 0 -22%;
  border-radius: 50%; background: rgba(99, 255, 242, .34);
  border: 1px solid rgba(99, 255, 242, .7);
  will-change: transform;
}
.touch-buttons {
  position: absolute; right: max(4.5%, env(safe-area-inset-right, 0px)); bottom: 23%;
  display: flex; flex-direction: column; gap: 3vmin; align-items: flex-end;
}
.touch-btn {
  pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none;
  min-width: 21vmin; min-height: 21vmin; max-width: 104px; max-height: 104px;
  border-radius: 50%; border: 1px solid rgba(121, 255, 139, .55);
  background: rgba(4, 26, 18, .52); color: var(--green);
  font-size: clamp(.58rem, 2.1vw, .72rem); letter-spacing: .1em;
  display: flex; align-items: center; justify-content: center;
}
.touch-btn:active, .touch-btn.is-down { background: rgba(121, 255, 139, .26); }
.touch-secondary { border-color: rgba(79, 168, 255, .55); color: var(--blue); background: rgba(4, 18, 34, .52); }
.touch-secondary:active { background: rgba(79, 168, 255, .26); }
/* Cockpit key strip: every classic keyboard command as a 44 px tap target. Two rows of seven on portrait
   phones, one row of fourteen where the screen is wide enough. */
.touch-console {
  position: absolute; left: 50%; top: calc(6px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px;
  width: min(343px, calc(100vw - 16px)); pointer-events: none;
}
.touch-key {
  pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none;
  min-width: 0; min-height: 44px; padding: 0 2px; border-radius: 4px;
  border: 1px solid rgba(160, 140, 255, .55); background: rgba(16, 8, 48, .66); color: #d9ccff;
  font-size: .76rem; font-weight: 700; letter-spacing: .04em; line-height: 1;
}
.touch-key:active, .touch-key.is-on { background: rgba(160, 140, 255, .34); color: #fff; }
.touch-key-warp { border-color: rgba(255, 230, 111, .6); color: var(--yellow); }
.touch-key-low { border-color: rgba(121, 255, 139, .6); color: var(--green); }
@media (min-width: 700px), (min-width: 601px) and (max-height: 480px) {
  .touch-console {
    grid-template-columns: repeat(14, minmax(0, 1fr));
    width: min(681px, calc(100vw - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  }
}
/* 14 keys of 44 px need 14 x 44 + 13 gaps: on 601-699 px wide landscape screens the gaps shrink instead of the keys. */
@media (min-width: 601px) and (max-width: 699px) and (max-height: 480px) {
  .touch-console { gap: 2px; }
}
/* touch-input.js writes the real bottom edge of the key strip into --touch-strip-bottom, so banners clear it
   on every screen shape. */
body.touch-ui .status-banner { top: calc(var(--touch-strip-bottom, 112px) + 8px); }
/* Landscape phones have almost no vertical room: pull the clusters in. */
@media (max-height: 480px) {
  .touch-buttons { bottom: 24%; gap: 2vmin; }
  .touch-btn { min-width: 17vmin; min-height: 17vmin; }
}

#shieldWash, #screenFx, #scanlines, #vignette { position: absolute; inset: 0; pointer-events: none; }
#shieldWash { opacity: 0; background: linear-gradient(180deg, rgba(38, 118, 255, .14), rgba(0, 190, 255, .05)); mix-blend-mode: screen; transition: opacity .12s linear; }
#screenFx { opacity: 0; background: rgba(255, 40, 50, .35); mix-blend-mode: screen; }
#scanlines { opacity: .36; background: repeating-linear-gradient(180deg, rgba(255,255,255,.035) 0, rgba(255,255,255,.035) 1px, rgba(0,0,0,.07) 2px, rgba(0,0,0,.07) 4px); }
body.no-crt #scanlines { display: none; }
#vignette { box-shadow: inset 0 0 13vw rgba(0,0,0,.9), inset 0 0 2vw rgba(40,170,255,.08); }
body.bloom #gameCanvas { filter: saturate(1.14) contrast(1.04) drop-shadow(0 0 3px rgba(70,255,230,.15)); }

/* S2: panels are flex columns. The head (kicker + heading) stays put, .panel-body scrolls, .panel-actions is the
   footer that is always on screen, so the buttons never fall below the fold. The size follows #app (the visible
   area) and keeps clear of notches and rounded corners. */
.panel {
  position: absolute;
  left: calc(50% + (env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) / 2);
  top: calc(50% + (env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) / 2);
  width: min(650px, calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-height: calc(100% - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translate(-50%, -50%);
  z-index: 20;
  padding: clamp(20px, 3.2vw, 42px);
  border: 1px solid var(--line);
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(99,255,242,.07), transparent 32%),
    linear-gradient(315deg, rgba(79,168,255,.06), transparent 38%),
    var(--panel);
  box-shadow: 0 0 0 4px rgba(0,0,0,.55), 0 0 45px rgba(50,190,255,.18), inset 0 0 35px rgba(39,140,190,.08);
  backdrop-filter: blur(9px);
}
.panel::before, .panel::after { content: ""; position: absolute; width: 44px; height: 12px; border-top: 2px solid var(--cyan); top: 10px; opacity: .65; }
.panel::before { left: 12px; border-left: 2px solid var(--cyan); }
.panel::after { right: 12px; border-right: 2px solid var(--cyan); }
.wide-panel { width: min(920px, calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); }
.title-panel { text-align: center; }
.panel-kicker, .panel > h1, .panel > h2 { flex: none; }
.panel-body {
  flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto;
  margin: 0 -10px; padding: 4px 10px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: rgba(99,255,242,.45) transparent;
}
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(99,255,242,.4); border-radius: 4px; }
.panel-body > :first-child { margin-top: 0; }
.panel > .panel-actions { flex: none; margin-top: 12px; padding-top: 14px; border-top: 1px solid rgba(99,255,242,.2); }
.first-run-hint { color: var(--yellow); font-size: .76rem; line-height: 1.5; margin: 14px 0 0; letter-spacing: .03em; }
.quickstart {
  margin: 0; padding: 14px 16px; text-align: left;
  border: 1px solid rgba(255,230,111,.5);
  background: linear-gradient(135deg, rgba(255,230,111,.10), rgba(0,0,0,.30));
  box-shadow: 0 0 22px rgba(255,230,111,.07);
}
.quickstart h3 { margin: 0 0 8px; color: var(--yellow); font-size: 1rem; letter-spacing: .08em; }
.quickstart ol { margin: 0 0 10px; padding-left: 1.5em; color: #d6eef0; font-size: .8rem; line-height: 1.6; }
.quickstart li { margin: 4px 0; padding-left: 2px; }
.quickstart li::marker { color: var(--yellow); font-weight: 700; }
.quickstart-devices { margin: 0; color: #9fd0d6; font-size: .72rem; line-height: 1.55; }
.help-columns { margin-top: 22px; }
.pad-card { margin-top: 22px; padding: 15px; border: 1px solid rgba(99,255,242,.22); background: rgba(0,0,0,.24); text-align: left; }
.pad-card h3 { margin: 0 0 8px; }
.pad-map dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 18px; }
.pad-map dt { margin: 0; }
.pad-map dd { margin: 0; }
.pad-card .tiny { margin: 12px 0 0; }

.panel-kicker { color: var(--cyan); letter-spacing: .2em; font-size: clamp(.66rem, 1.4vw, .84rem); margin-bottom: 10px; text-shadow: 0 0 12px rgba(99,255,242,.7); }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 6.2vw, 4.6rem); line-height: .96; margin-bottom: 18px; letter-spacing: .025em; text-shadow: 0 0 8px rgba(255,255,255,.24), 0 0 24px rgba(65,220,255,.32); }
h1 span { display: block; color: var(--yellow); font-size: .46em; letter-spacing: .5em; margin-right: -.5em; margin-bottom: 9px; }
h2 { margin-bottom: 22px; color: var(--yellow); font-size: clamp(1.8rem, 4vw, 3.1rem); letter-spacing: .09em; }
h3 { color: var(--cyan); font-size: .96rem; letter-spacing: .08em; }
.lead { color: #d2f9ff; line-height: 1.6; font-size: clamp(.86rem, 1.6vw, 1rem); }
.tiny { color: #8bb7bf; font-size: .72rem; line-height: 1.45; margin: 18px 0 8px; }
.legal { color: #66838b; font-size: .62rem; margin: 0; }

.menu-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin-top: 24px; }
.menu-grid button:first-child:nth-last-child(4), .menu-grid button:first-child:nth-last-child(4) ~ button { }
.menu-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }
button, select {
  color: #dfffff;
  background: rgba(4, 27, 38, .86);
  border: 1px solid rgba(99,255,242,.45);
  border-radius: 3px;
  padding: 12px 15px;
  min-height: 44px;
  letter-spacing: .045em;
  transition: .13s ease;
}
button { cursor: pointer; }
button:hover, button:focus-visible, select:focus-visible { color: #fff; border-color: var(--cyan); background: rgba(8,53,70,.95); box-shadow: 0 0 14px rgba(99,255,242,.23); outline: none; transform: translateY(-1px); }
button.primary { color: #001417; background: linear-gradient(180deg, #87fff3, #36cbbb); border-color: #aafff7; font-weight: 700; }
button.primary:hover { background: linear-gradient(180deg, #c4fff9, #4bf2dd); }
button.danger { color: #ffdce3; border-color: rgba(255,79,112,.6); }
button.danger:hover { border-color: var(--red); background: rgba(80,9,28,.9); }

.difficulty-row { display: grid; grid-template-columns: 1fr 1.55fr; align-items: center; gap: 12px; margin-top: 18px; color: #9ed9df; font-size: .76rem; text-align: left; }
.difficulty-row select { width: 100%; padding: 9px; min-height: 38px; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 15px 24px; text-align: left; }
.settings-grid label { display: grid; grid-template-columns: 1fr auto; gap: 7px; align-items: center; color: #bde8ec; font-size: .78rem; }
.settings-grid label output { color: var(--yellow); }
.settings-grid input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: #4ce4d3; }
.settings-grid select { grid-column: 1 / -1; width: 100%; padding: 9px; min-height: 38px; }
.settings-grid label.check { display: flex; grid-template-columns: none; gap: 10px; min-height: 36px; }
.settings-grid input[type="checkbox"] { width: 18px; height: 18px; accent-color: #4ce4d3; }

.help-columns { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 20px; text-align: left; }
dl { margin: 0; }
dt { color: var(--yellow); font-size: .72rem; margin-top: 9px; }
dd { color: #b6dadd; margin: 3px 0 0; font-size: .7rem; line-height: 1.35; }
.mission-brief { margin-top: 22px; padding: 15px; border: 1px solid rgba(99,255,242,.22); background: rgba(0,0,0,.24); color: #bbdfe3; font-size: .75rem; line-height: 1.6; text-align: left; }
kbd { color: #001012; background: var(--cyan); border-radius: 2px; padding: 1px 5px; font-weight: bold; }

.status-banner { position: absolute; z-index: 12; top: 22px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); text-align: center; color: var(--yellow); background: rgba(2,7,12,.82); border: 1px solid rgba(255,230,111,.5); padding: 8px 16px; letter-spacing: .14em; font-size: clamp(.68rem, 1.7vw, .88rem); text-shadow: 0 0 11px currentColor; pointer-events: none; }
.toast { position: absolute; z-index: 14; left: 50%; bottom: 24%; transform: translateX(-50%); max-width: min(720px, calc(100vw - 30px)); color: #eaffff; background: rgba(0,10,17,.88); border-left: 3px solid var(--cyan); border-right: 3px solid var(--cyan); padding: 10px 18px; font-size: clamp(.7rem, 1.6vw, .88rem); letter-spacing: .04em; text-align: center; box-shadow: 0 0 26px rgba(60,230,255,.18); pointer-events: none; }
.toast.toast-over { z-index: 24; }
.pointer-hint { position: absolute; z-index: 13; left: 50%; bottom: calc(clamp(100px, 18vh, 140px) + 10px); transform: translateX(-50%); color: #a8f7ff; background: rgba(0,0,0,.68); border: 1px solid rgba(99,255,242,.35); padding: 8px 12px; font-size: .65rem; letter-spacing: .1em; pointer-events: none; }
.end-stats { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 20px; color: #bde5e7; text-align: left; border-top: 1px solid rgba(99,255,242,.25); border-bottom: 1px solid rgba(99,255,242,.25); padding: 16px 4px; }
.end-stats b { color: var(--yellow); text-align: right; }
/* Long words (German "Einsatzbewertung", "FRACHTERKAPITAEN") must wrap instead of pushing the grid wider than the panel. */
.end-stats > * { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) { .end-stats { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 6px 12px; font-size: .86rem; } }
@media (max-width: 380px) { .end-stats { font-size: .8rem; } }
@media (max-width: 340px) { .end-stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 10px; font-size: .72rem; } }
/* Classic end-of-sortie rating card with a twelve-step rank ladder. */
.rank-card { grid-column: 1 / -1; text-align: center; padding: 6px 0 12px; margin-bottom: 4px; border-bottom: 1px dashed rgba(160,140,255,.35); }
.rank-card .rank-label { color: #b9a8ff; font-size: .7rem; letter-spacing: .24em; }
.rank-card .rank-name { color: var(--yellow); font-size: clamp(1.25rem, 3.6vw, 2rem); letter-spacing: .12em; font-weight: 700; margin: 6px 0 2px; text-shadow: 0 0 12px rgba(255,230,111,.45); }
.rank-card .rank-class { color: #eaffff; font-size: .86rem; letter-spacing: .2em; }
.rank-card .rank-date { color: #8fd8ff; font-size: .72rem; letter-spacing: .16em; margin-top: 6px; }
.rank-ladder { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; margin: 12px auto 0; max-width: 460px; align-items: end; }
.rank-ladder i { display: block; height: 6px; background: rgba(160,140,255,.22); border-radius: 1px; }
.rank-ladder i.reached { background: rgba(160,140,255,.62); }
.rank-ladder i.current { background: var(--yellow); box-shadow: 0 0 8px rgba(255,230,111,.7); height: 10px; }
/* Xenology Log: one card per explored world, finds as small pixel thumbnails. */
.xeno-list { display: grid; gap: 14px; text-align: left; }
.xeno-empty { color: #8bb7bf; font-size: .78rem; line-height: 1.55; text-align: center; padding: 18px 8px; border: 1px dashed rgba(99,255,242,.25); }
.xeno-world { border: 1px solid rgba(99,255,242,.22); background: rgba(0,0,0,.24); padding: 12px; }
.xeno-world-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-bottom: 10px; }
.xeno-world-head canvas { width: 64px; height: 48px; image-rendering: pixelated; image-rendering: crisp-edges; border: 1px solid rgba(160,140,255,.45); flex: none; }
.xeno-world-name { color: var(--yellow); font-weight: 700; letter-spacing: .1em; font-size: .9rem; }
.xeno-world-meta { color: #8fd8ff; font-size: .7rem; letter-spacing: .06em; }
.xeno-finds { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 8px; }
.xeno-find > div { min-width: 0; }
.xeno-find { display: flex; gap: 8px; align-items: center; padding: 6px; border: 1px solid rgba(160,140,255,.25); background: rgba(16,8,48,.35); }
.xeno-find canvas { width: 64px; height: 48px; image-rendering: pixelated; image-rendering: crisp-edges; flex: none; }
.xeno-find b { display: block; color: #eaffff; font-size: .72rem; letter-spacing: .04em; overflow-wrap: break-word; hyphens: auto; }
.xeno-find span { display: block; color: #8bb7bf; font-size: .64rem; margin-top: 2px; }
.xeno-find.unknown { opacity: .55; }
.xeno-find.unknown canvas { filter: grayscale(1) brightness(.35); }
.hidden { display: none !important; }

@media (max-width: 760px) {
  .panel { padding: 22px 18px; }
  .menu-grid, .settings-grid, .help-columns { grid-template-columns: 1fr; }
  .menu-grid.panel-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .difficulty-row { grid-template-columns: 1fr; }
  .help-columns { gap: 8px; }
}
@media (max-width: 420px) {
  .menu-grid.panel-actions { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .pad-map dl { grid-template-columns: 1fr; gap: 0; }
  .pad-map dd { margin-bottom: 7px; }
}
/* Short screens (landscape phones, small laptop windows): a compact head, more room for the body. */
@media (max-height: 560px) {
  .panel { padding: 14px 18px; }
  .panel-kicker { margin-bottom: 4px; font-size: .62rem; }
  h1 { font-size: clamp(1.5rem, 5vw, 2.3rem); margin-bottom: 8px; }
  h1 span { display: inline; font-size: .6em; letter-spacing: .3em; margin: 0 .5em 0 0; }
  h2 { font-size: 1.35rem; margin-bottom: 8px; }
  .lead { display: none; }
  .menu-grid { gap: 8px; margin-top: 10px; }
  #titlePanel .menu-grid, #pausePanel .menu-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .menu-row { margin-top: 10px; }
  .panel > .panel-actions { margin-top: 8px; padding-top: 10px; }
  .tiny { margin: 8px 0 4px; }
  .difficulty-row { margin-top: 8px; grid-template-columns: 1fr 1.55fr; }
  .first-run-hint { margin-top: 8px; }
  .help-columns { margin-top: 12px; }
  .mission-brief, .pad-card { margin-top: 12px; }
  .end-stats { padding: 10px 4px; gap: 5px 20px; }
  .rank-card { padding: 2px 0 8px; }
}

/* Until js/i18n.js has chosen the language, the title panel stays unpainted: a visitor who is about to
   get English must not see the German markup for a moment. The animation is the fail-safe that reveals
   the panel after 2.5 s even if the script never runs (blocked, offline). */
html:not(.sr11-lang-ready) #titlePanel {
  visibility: hidden;
  animation: sr11-title-failsafe .01ms 2.5s forwards;
}
@keyframes sr11-title-failsafe { to { visibility: visible; } }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
