/* Design tokens, app shell and shared pixel-UI components. */
:root {
  --ink: #0b0e17;
  --bg: #10141f;
  --panel: #1a2133;
  --panel-2: #232c44;
  --panel-3: #2e3959;
  --line: #3a4668;
  --text: #eef1f8;
  --muted: #8e98b8;
  --accent: #ffb627;
  --accent-ink: #2a1c00;
  --accent-2: #2ec4b6;
  --danger: #ff5d5d;
  --r1: #a3abbd;
  --r2: #5ccf8a;
  --r3: #46a8ff;
  --r4: #b779ff;
  --r5: #ffb627;
  --r6: #ff5c9a;
  --r7: #ff3b30;
  --font-pixel: 'Press Start 2P', ui-monospace, monospace;
  --font-body: 'Pixelify Sans', system-ui, sans-serif;
  --px: 3px;
  --bevel: inset -3px -3px 0 rgba(0, 0, 0, 0.35), inset 3px 3px 0 rgba(255, 255, 255, 0.07);
  --tabbar-h: 68px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over component display rules such as .btn { display: inline-flex }. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 6px 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img, canvas { max-width: 100%; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.app {
  max-width: 440px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-inline: var(--px) solid var(--ink);
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--panel);
  border-bottom: var(--px) solid var(--ink);
  box-shadow: 0 var(--px) 0 var(--line);
}
.brand { flex: 1; font-family: var(--font-pixel); font-size: 11px; color: var(--accent); letter-spacing: 1px; }
.level-chip {
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 6px 8px;
  background: var(--accent-2);
  color: var(--ink);
  border: 2px solid var(--ink);
}
.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--panel-3);
  border: 2px solid var(--ink);
  box-shadow: var(--bevel);
  cursor: pointer;
  font-size: 18px;
}

.screen {
  flex: 1;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  outline: none;
}

/* Bottom tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: 100%;
  max-width: 440px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--panel);
  border-top: var(--px) solid var(--ink);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0 7px;
  font-family: var(--font-pixel);
  font-size: 7px;
  background: var(--panel-2);
  border: var(--px) solid var(--ink);
  box-shadow: var(--bevel);
}
.tab-icon { font-family: system-ui, sans-serif; font-size: 18px; line-height: 1; }
.tab[aria-current='page'] { background: var(--accent); color: var(--accent-ink); }
.tab-scan:not([aria-current='page']) { background: var(--panel-3); }

/* Panels and headings */
.panel { background: var(--panel); border: var(--px) solid var(--ink); box-shadow: var(--bevel); padding: 12px; }
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.h1 { font-family: var(--font-pixel); font-size: 20px; line-height: 1.35; word-break: break-word; }
.pixel-sm { font-family: var(--font-pixel); font-size: 8px; letter-spacing: 0.5px; }
.muted { color: var(--muted); }
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 10px;
  font-family: var(--font-pixel);
  font-size: 9px;
  font-weight: 400;
  color: var(--muted);
}
.section-title::before { content: '>>'; color: var(--accent); }
.section-title::after {
  content: '';
  flex: 1;
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--line) 0 3px, transparent 3px 6px);
}

/* Buttons and chips */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 14px;
  font-family: var(--font-pixel);
  font-size: 9px;
  text-transform: uppercase;
  background: var(--panel-3);
  border: var(--px) solid var(--ink);
  box-shadow: var(--bevel);
  cursor: pointer;
}
.btn:active { transform: translateY(2px); box-shadow: inset 3px 3px 0 rgba(0, 0, 0, 0.35); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger); color: var(--ink); }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-small { min-height: 36px; padding: 8px 10px; font-size: 8px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  min-height: 36px;
  padding: 8px 10px;
  font-family: var(--font-pixel);
  font-size: 8px;
  background: var(--panel-2);
  border: var(--px) solid var(--ink);
  box-shadow: var(--bevel);
  cursor: pointer;
}
.chip[aria-pressed='true'] { background: var(--accent-2); color: var(--ink); }

.badge {
  display: inline-block;
  padding: 5px 6px 4px;
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--ink);
  background: var(--rc, var(--r1));
  border: 2px solid var(--ink);
  white-space: nowrap;
}

.sprite { display: block; width: 100%; height: auto; image-rendering: pixelated; image-rendering: crisp-edges; }

.bar { height: 12px; background: var(--ink); border: 2px solid var(--ink); }
.bar > i {
  display: block;
  height: 100%;
  background: var(--accent-2);
  background-image: repeating-linear-gradient(90deg, transparent 0 6px, rgba(0, 0, 0, 0.28) 6px 8px);
}

/* Toasts and bottom sheets */
#toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(408px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  padding: 10px 12px;
  font-size: 15px;
  background: var(--panel-3);
  border: var(--px) solid var(--ink);
  box-shadow: var(--bevel), 0 6px 0 rgba(0, 0, 0, 0.3);
  animation: pop-in 0.2s steps(4);
}
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(5, 7, 12, 0.72);
}
.sheet {
  width: 100%;
  max-width: 440px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  background: var(--panel);
  border-top: var(--px) solid var(--ink);
  box-shadow: 0 calc(-1 * var(--px)) 0 var(--line);
  outline: none;
  animation: sheet-in 0.25s steps(5);
}
.sheet-title { font-family: var(--font-pixel); font-size: 12px; margin-bottom: 12px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.sheet-actions > :only-child, .sheet-actions > :nth-child(3) { grid-column: 1 / -1; }

@keyframes sheet-in { from { transform: translateY(48px); opacity: 0; } }
@keyframes pop-in { from { transform: scale(0.92); opacity: 0; } }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
