/* OpenTTD Browser Edition — host chrome.
   Palette: TTD-ish deep green, warm cream panels, amber accent. */

:root {
  --ink: #10160f;
  --panel: #f0e6c8;
  --panel-edge: #a8976a;
  --accent: #e8a33d;
  --accent-2: #b35c1e;
  --bg: #16241c;
  --bg2: #223528;
  --hud-bg: rgba(16, 24, 18, 0.82);
  --font: Tahoma, "DejaVu Sans", Verdana, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win over the flex/display rules below
   (#fatal, #hud, .dlg-back all use display:flex but start out hidden). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  color: var(--panel);
}

/* ---------- game canvas ---------- */

canvas.emscripten {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  border: 0;
  outline: none;
  /* OpenTTD draws its own cursor */
  cursor: none !important;
  touch-action: none;
  image-rendering: pixelated;
}

/* ---------- boot / loading screen ---------- */

#boot {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background:
    radial-gradient(1200px 500px at 50% 118%, #2c4a32 0%, transparent 70%),
    repeating-linear-gradient(45deg, var(--bg) 0 26px, var(--bg2) 26px 52px);
  transition: opacity 0.45s ease;
}
#boot.done { opacity: 0; pointer-events: none; }

.boot-card {
  width: min(480px, 88vw);
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: 0 10px 0 rgba(0,0,0,.35), inset 0 0 0 2px var(--panel-edge);
  padding: 22px 24px 18px;
  text-align: center;
}

.boot-logo { display: flex; flex-direction: column; line-height: 1; margin-bottom: 14px; }
.boot-logo-word {
  font-weight: 800;
  font-size: 44px;
  letter-spacing: 2px;
  color: var(--ink);
  text-shadow: 2px 2px 0 var(--accent);
}
.boot-logo-word span { color: var(--accent-2); }
.boot-logo-sub {
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: #5c5236;
}

.boot-track {
  position: relative;
  height: 26px;
  margin: 4px 0 12px;
  border-bottom: 3px solid #4a4436;
  overflow: hidden;
}
.boot-track::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0;
  border-bottom: 2px dashed #f4e9c8;
}
.boot-train {
  position: absolute;
  bottom: 4px;
  left: -90px;
  display: flex;
  gap: 4px;
  animation: chug 2.6s linear infinite;
}
.boot-train i {
  width: 26px; height: 14px;
  background: var(--accent-2);
  border: 2px solid var(--ink);
  border-bottom-width: 3px;
}
.boot-train i:first-child { border-radius: 8px 3px 0 0; }
@keyframes chug {
  from { transform: translateX(0); }
  to   { transform: translateX(calc(min(480px, 88vw) + 140px)); }
}

.boot-bar {
  height: 14px;
  border: 2px solid var(--ink);
  background: #fff8e2;
  padding: 2px;
}
#boot-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--accent) 0 10px, #d08a25 10px 20px);
  transition: width .18s ease-out;
}
#boot-status { margin-top: 10px; font-size: 13px; font-weight: bold; min-height: 16px; }
#boot-detail { margin-top: 2px; font-size: 11px; color: #5c5236; min-height: 14px; }
.boot-tips { margin-top: 14px; font-size: 11px; color: #6a5f40; border-top: 1px dashed var(--panel-edge); padding-top: 8px; }
.boot-foot { font-size: 11px; letter-spacing: 1px; color: #8fa38d; }

/* ---------- fatal / error ---------- */

#fatal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 11, .8);
}
.fatal-card {
  width: min(460px, 90vw);
  background: #f8d8d0;
  border: 3px solid #7c1d12;
  color: #3a0d06;
  padding: 18px 20px;
  text-align: center;
  box-shadow: 0 10px 0 rgba(0,0,0,.4);
}
.fatal-title { font-weight: 800; font-size: 18px; margin-bottom: 8px; }
.fatal-msg { font-size: 13px; margin-bottom: 14px; white-space: pre-wrap; }

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

#hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 30;
  display: flex;
  gap: 6px;
  padding: 5px;
  background: var(--hud-bg);
  border: 1px solid #3a5240;
  border-radius: 8px;
  backdrop-filter: blur(3px);
}
.hud-btn, .btn {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  color: var(--panel);
  background: #2b4032;
  border: 1px solid #55704f;
  border-radius: 6px;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  cursor: pointer;
}
.hud-btn:hover, .btn:hover { background: #3a5442; }
.hud-btn:focus-visible, .btn:focus-visible, .dlg-x:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.hud-btn:active { transform: translateY(1px); }

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

#toast {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.toast-msg {
  background: var(--hud-bg);
  border: 1px solid #55704f;
  color: var(--panel);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity .25s;
}
.toast-msg.show { opacity: 1; }

/* ---------- filesystem warning ---------- */

#fs-warn {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 32;
  background: #8e2418;
  color: #ffe9a8;
  border: 1px solid #e0705e;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  transition: opacity .3s;
}

/* ---------- dialogs ---------- */

.dlg-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 11, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.dlg {
  width: min(560px, 94vw);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: 0 10px 0 rgba(0,0,0,.4), inset 0 0 0 2px var(--panel-edge);
}
.dlg-title {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--ink);
  color: var(--panel);
  font-weight: 800;
  font-size: 15px;
  padding: 8px 12px;
}
.dlg-x {
  background: none; border: none; color: var(--panel);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.dlg-body {
  padding: 12px 16px 16px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.45;
}
.dlg-body h3 {
  margin: 14px 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-2);
  border-bottom: 1px solid var(--panel-edge);
  padding-bottom: 2px;
}
.dlg-body ul, .dlg-body ol { margin: 6px 0; padding-left: 20px; }
.dlg-body li { margin: 3px 0; }
.dlg-body .small { font-size: 11px; color: #5c5236; }
.dlg-body b { color: #3a2f16; }

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  .boot-logo-word { font-size: 34px; }
  .hud-btn { min-width: 40px; height: 40px; font-size: 18px; }
  .dlg-body { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .boot-train { animation: none; left: 40%; }
  #boot { transition: none; }
  .toast-msg { transition: none; }
}
