/* ============================================================
   base.css - the shell, the palette, and the 8-bit type rules (GDD 13)
   Mobile-first: one column, thumb-reachable actions, no hover required.
   ============================================================ */
:root {
  --ink:        #f0e3d2;
  --ink-dim:    #b3a394;
  --ink-faint:  #7d7065;
  --bg:         #16110f;
  --bg-2:       #1f1815;
  --panel:      #261d19;
  --panel-2:    #2f2420;
  --line:       #40312a;
  --ember:      #ff8a3d;
  --ember-dark: #b3542a;
  --gold:       #f2c94c;
  --good:       #7fc96a;
  --bad:        #e05a4a;
  --cool:       #58a9d6;
  --violet:     #9d7fd0;

  --radius: 6px;
  --tap: 44px;
  --gutter: 14px;
  --maxw: 720px;

  --font: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* `display: flex` on a panel beats the hidden attribute's `display: none`,
   which leaves an invisible full-screen overlay eating every tap. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* A faint scanline wash: 8-bit without making anything unreadable. */
  background-image: repeating-linear-gradient(
    to bottom, rgba(255,255,255,0.016) 0 1px, transparent 1px 3px);
}

canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

#app {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- top bar ---- */
#topbar {
  display: flex; gap: 6px; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) var(--gutter) 6px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 2px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
#topbar .chip:first-child { flex: 1; text-align: left; min-width: 0; }
#place { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

.chip {
  font: inherit; font-size: 12px;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 9px; min-height: 32px;
  display: inline-flex; align-items: center; gap: 5px;
}
button.chip { cursor: pointer; }
button.chip:active { background: var(--panel-2); }
#coin { color: var(--gold); }
#act { color: var(--ember); }

/* ---- screen ---- */
#screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--gutter);
  padding-bottom: 24px;
}
#screen:focus { outline: none; }

/* ---- tab bar ---- */
#tabbar {
  display: flex;
  border-top: 2px solid var(--line);
  background: var(--bg-2);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  position: sticky; bottom: 0; z-index: 30;
}
#tabbar button {
  flex: 1; min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: none; border: none; color: var(--ink-dim);
  font: inherit; font-size: 10px; letter-spacing: 0.5px; cursor: pointer;
  padding: 6px 2px;
}
#tabbar button .tabicon { font-size: 17px; line-height: 1; }
#tabbar button[aria-current="true"] { color: var(--ember); background: rgba(255,138,61,0.08); }
#tabbar button:active { background: rgba(255,255,255,0.05); }

/* ---- back to the games list ---- */
.back-link {
  position: fixed; left: 8px; bottom: calc(env(safe-area-inset-bottom, 0px) + 52px);
  z-index: 60;
  font-size: 10px; color: var(--ink-faint); text-decoration: none;
  background: rgba(22,17,15,0.85); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 7px;
}
.back-link:active { color: var(--ink); }

/* ---- headings and text ---- */
h1, h2, h3 { font-weight: 700; letter-spacing: 0.5px; margin: 0 0 8px; }
h1 { font-size: 20px; color: var(--ember); }
h2 { font-size: 15px; color: var(--ink); text-transform: uppercase; letter-spacing: 1.5px; }
h3 { font-size: 13px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; }
p { margin: 0 0 10px; }
.dim { color: var(--ink-dim); }
.faint { color: var(--ink-faint); font-size: 12px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.gold { color: var(--gold); }
.ember { color: var(--ember); }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.sep { height: 1px; background: var(--line); margin: 12px 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- buttons ---- */
.btn {
  font: inherit; font-size: 13px;
  min-height: var(--tap);
  padding: 10px 14px;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--line); border-radius: var(--radius);
  cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 8px;
}
.btn:active { transform: translateY(1px); background: var(--panel-2); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn.primary { border-color: var(--ember-dark); background: linear-gradient(180deg, #3a241a, var(--panel)); color: var(--ember); }
.btn.danger { border-color: #6d2f2a; color: var(--bad); }
.btn.wide { width: 100%; justify-content: center; text-align: center; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.btn-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.btn-grid.three { grid-template-columns: repeat(3, 1fr); }

/* ---- cards and panels ---- */
.card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
}
.card.tight { padding: 8px; }
.card.clickable { cursor: pointer; }
.card.clickable:active { background: var(--panel-2); }
.card h3 { margin-bottom: 6px; }

/* ---- bars ---- */
.bar {
  height: 8px; background: #120d0b;
  border: 1px solid var(--line); border-radius: 2px; overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--good); transition: width 220ms ease; }
.bar.mp > i { background: var(--cool); }
.bar.xp > i { background: var(--violet); }
.bar.bond > i { background: var(--ember); }
.bar.surge > i { background: linear-gradient(90deg, var(--ember), var(--gold)); }
.bar.thin { height: 5px; }

/* ---- overlay ---- */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(10,7,6,0.88);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.overlay-inner {
  width: 100%; max-width: var(--maxw);
  max-height: 92vh; overflow-y: auto;
  background: var(--bg-2);
  border-top: 3px solid var(--ember-dark);
  padding: 16px var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 16px);
  animation: rise 160ms ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- toasts ---- */
.toasts {
  position: fixed; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 64px);
  z-index: 90;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; padding: 0 var(--gutter);
}
/* With a dialogue open the bottom of the screen is the text; put notices
   at the top so they never land in the middle of a sentence. */
.overlay-open .toasts {
  top: calc(env(safe-area-inset-top, 0px) + 54px);
  bottom: auto;
}

.toast {
  background: var(--panel-2); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 8px 12px; font-size: 12px;
  max-width: 100%; animation: rise 140ms ease-out;
}
.toast.good { border-color: #3f6b35; color: var(--good); }
.toast.bad { border-color: #6d2f2a; color: var(--bad); }
.toast.gold { border-color: #7a6524; color: var(--gold); }

/* ---- sprites ---- */
.sprite { display: block; }
.item-icon { display: block; flex: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Desktop and landscape get the same layout, just centred and a little larger. */
@media (min-width: 760px) {
  html, body { font-size: 16px; }
  #app { border-left: 2px solid var(--line); border-right: 2px solid var(--line); }
}
