/* ---------------------------------------------------------------------------
   Fast Escape v1.1 - web
   Plátno je vždy 640x480 a škáluje se celočíselně-ish s pixelated filtrem;
   všechno ostatní je běžná moderní stránka.
   ------------------------------------------------------------------------- */

:root {
  --bg: #101014;
  --panel: #17171d;
  --line: #2a2a34;
  --fg: #d7d7de;
  --muted: #8b8b98;
  --accent: #55ffff;
  --accent-dim: #2b8f8f;
  --font: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--accent); }
a:hover { color: #fff; }
.muted { color: var(--muted); }
code { color: var(--accent-dim); }

/* --- horní lišta ---------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.bar h1 { font-size: 16px; font-weight: 700; letter-spacing: .04em; }
.bar .ver { color: var(--accent); }
.bar .year { color: var(--muted); font-weight: 400; }
.platform-name { color: var(--muted); font-size: 12px; letter-spacing: .08em; }

/* --- plátno --------------------------------------------------------------- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.stage {
  position: relative;
  width: min(100%, calc((100dvh - 230px) * 4 / 3));
  aspect-ratio: 4 / 3;
  background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px #000, 0 12px 40px rgba(0, 0, 0, .6);
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #000;
  outline: none;
}

.stage:fullscreen {
  width: 100vw;
  height: 100dvh;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage:fullscreen canvas {
  width: auto;
  height: auto;
  max-width: 100vw;
  max-height: 100dvh;
  aspect-ratio: 4 / 3;
}

/* Řádkování zapínatelné tlačítkem CRT - výchozí stav je vypnuto, protože
   originál na VGA monitoru žádné takové artefakty neměl. */
.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, .22) 3px,
    rgba(0, 0, 0, .22) 4px);
}
.stage.crt .scanlines { opacity: 1; }

.crash {
  color: #ff8080;
  font-size: 13px;
  text-align: center;
  max-width: 640px;
}
.crash[hidden] { display: none; }

/* --- dotykové ovládání ---------------------------------------------------- */

.touch {
  display: none;
  width: min(100%, 560px);
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

@media (pointer: coarse) {
  .touch { display: flex; }
  .stage { width: min(100%, calc((100dvh - 340px) * 4 / 3)); }
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
  flex: none;
}
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }

.keys {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  flex: 1;
}
.keys .wide { grid-column: span 2; }

.tb {
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  background: #1c1c24;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 40px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.tb.down, .tb:active { background: var(--accent-dim); color: #06161a; }

/* --- informační část ------------------------------------------------------ */

.info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  max-width: 1100px;
  width: 100%;
  margin: 8px auto 0;
  padding: 24px 16px;
  border-top: 1px solid var(--line);
}

.info h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent);
  margin-bottom: 10px;
}
.info p { margin-bottom: 10px; font-size: 14px; }
.info .credits { color: var(--muted); font-size: 13px; }

.info table { border-collapse: collapse; width: 100%; font-size: 14px; }
.info td { padding: 3px 10px 3px 0; vertical-align: top; }
.info .keymap td:first-child { color: var(--accent); white-space: nowrap; }
#scores td:nth-last-child(-n+2) { text-align: right; }
#scores td:nth-child(3), #scores tr.me td { color: var(--accent); }
#scores th { padding: 3px 8px 5px 0; color: var(--muted); font-size: 11px; text-align: left; }
#scores th:nth-last-child(-n+2) { text-align: right; }
.score-tabs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-bottom: 10px; }
.score-tabs button { min-height: 30px; color: var(--fg); font: 12px var(--font); background: #20202a; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.score-tabs button:hover, .score-tabs button:focus-visible, .score-tabs button.is-active { color: var(--accent); border-color: var(--accent); outline: none; }
.score-board-title { margin-bottom: 6px !important; color: var(--accent); font-weight: 700; }
.local-score, .score-status { margin-top: 9px; font-size: 12px !important; }

footer {
  padding: 14px 16px 28px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

/* --- společný obal dgame.cz ---------------------------------------------- */

.platform-controls {
  position: fixed;
  z-index: 20;
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.platform-control {
  min-width: 42px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--fg);
  font: 700 13px/1 var(--font);
  background: rgba(23, 23, 29, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .32);
  cursor: pointer;
}
.platform-control:hover,
.platform-control:focus-visible { color: #fff; border-color: var(--accent); outline: none; }
.platform-control:focus-visible { box-shadow: 0 0 0 3px rgba(85, 255, 255, .22); }
.platform-control > span:first-child { font-size: 21px; line-height: 1; }
#btn-account > span:first-child { position: relative; width: 18px; height: 18px; color: var(--accent); font-size: 10px; }
#btn-account > span:first-child::after { content: ''; position: absolute; left: 2px; right: 2px; bottom: 0; height: 8px; border: 2px solid currentColor; border-radius: 9px 9px 3px 3px; }
.account-control { width: auto; min-width: 168px; justify-content: flex-start; gap: 9px; padding: 5px 10px; }
.account-control-copy { display: grid; min-width: 0; text-align: left; line-height: 1.05; }
.account-control-copy strong, .account-control-copy small { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-control-copy strong { font-size: 12px; }
.account-control-copy small { color: var(--muted); font-size: 9px; margin-top: 3px; }

.language-control { position: relative; }
.language-trigger { min-width: 58px; }
.language-flag { display: inline-flex; width: 20px; height: 14px; overflow: hidden; border: 1px solid rgba(255,255,255,.22); }
.language-flag svg { display: block; width: 100%; height: 100%; }
.language-code { min-width: 18px; font-size: 11px; }

.language-menu {
  position: absolute;
  z-index: 1;
  bottom: 0;
  left: 68px;
  width: 176px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .55);
}
.language-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
}
.language-option:hover, .language-option:focus-visible { border-color: var(--accent-dim); outline: none; }
.language-option.is-active { color: var(--accent); }

.settings-overlay {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, .72);
}
.settings-dialog {
  width: min(100%, 470px);
  max-height: min(650px, calc(100dvh - 36px));
  overflow: auto;
  padding: 22px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .65);
}
.settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.settings-heading p { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.settings-heading h2 { font-size: 22px; line-height: 1.2; }
.settings-close { flex: none; width: 34px; height: 34px; color: var(--fg); font: 26px/1 sans-serif; background: transparent; border: 1px solid var(--line); border-radius: 5px; cursor: pointer; }
.settings-close:hover, .settings-close:focus-visible { border-color: var(--accent); color: #fff; outline: none; }
.settings-list { border-top: 1px solid var(--line); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting-row strong, .setting-row small { display: block; }
.setting-row strong { font-size: 14px; }
.setting-row small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.setting-row input { width: 20px; height: 20px; accent-color: var(--accent-dim); }
.settings-action { color: var(--accent); font: inherit; font-size: 13px; background: #20202a; border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; cursor: pointer; }
.settings-action:hover, .settings-action:focus-visible { border-color: var(--accent); outline: none; }
.settings-note { margin-top: 16px; color: var(--muted); font-size: 12px; }
.account-lead { margin-bottom: 16px; }
.account-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.account-field { display: grid; gap: 7px; margin: 16px 0; color: var(--accent); font-size: 12px; font-weight: 700; }
.account-field input, .account-field textarea { width: 100%; color: var(--fg); font: 14px/1.5 var(--font); background: #101014; border: 1px solid var(--line); border-radius: 5px; padding: 9px; resize: vertical; }
.account-field input:focus, .account-field textarea:focus { border-color: var(--accent); outline: none; }
.account-error { margin-top: 14px; color: #ff8080; font-size: 13px; }
.account-nickname-display { color: var(--accent); font-size: 20px; font-weight: 700; }
.account-recovery { margin-top: 14px; padding: 14px; color: #fff; font-size: 14px; line-height: 1.7; overflow-wrap: anywhere; background: #101014; border: 1px solid var(--accent-dim); border-radius: 6px; user-select: all; }

@media (max-width: 520px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .account-control { min-width: 132px; max-width: calc(100vw - 150px); }
  .account-control-copy strong, .account-control-copy small { max-width: calc(100vw - 205px); }
  .bar h1 { font-size: 14px; }
  .platform-controls { right: 0; bottom: 0; left: 0; flex-direction: row; align-items: center; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: rgba(16, 16, 20, .98); border-top: 1px solid var(--line); }
  .settings-dialog { padding: 18px; }
  .settings-heading h2 { font-size: 20px; }
  .setting-row { gap: 10px; }
}

@media (pointer: coarse) {
  .platform-controls { position: fixed; }
  .language-menu { bottom: auto; top: 0; }
}
