/* ───────────────── Questlog — dusk-overworld pixel board ───────────────── */

:root {
  --night: #140c2b;
  --night-2: #1d1140;
  --panel: #241a47;
  --panel-2: #2e2159;
  --edge: #0b0619;
  --line: #3d2d73;
  --parchment: #f3e7cd;
  --muted: #a697d6;
  --gold: #ffc247;
  --emerald: #5ce08a;
  --rose: #ff5d73;
  --cyan: #63d4ff;
  --violet: #c08bff;
  --ember: #ff8a3d;

  --hud-w: 280px;
  --r: 4px;
  --px: 'Press Start 2P', monospace;
  --ui: 'Pixelify Sans', 'Trebuchet MS', system-ui, sans-serif;
  --body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  overflow-x: hidden;
  min-height: 100%;
  background: var(--night);
  color: var(--parchment);
  font-family: var(--ui);
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(1100px 620px at 78% -8%, #3a2272 0%, rgba(58,34,114,0) 62%),
    radial-gradient(760px 520px at 8% 102%, #1b3b5e 0%, rgba(27,59,94,0) 60%),
    linear-gradient(180deg, var(--night-2) 0%, var(--night) 55%, #0f0a22 100%);
  background-attachment: fixed;
}

canvas.px, .px { image-rendering: pixelated; image-rendering: crisp-edges; }

#stars {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select, textarea { font-family: inherit; font-size: 1rem; color: inherit; }

/* ───────────────── buttons & fields ───────────────── */

.btn {
  font-family: var(--px);
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: .03em;
  padding: 11px 14px;
  border: 2px solid var(--edge);
  border-radius: var(--r);
  background: var(--panel-2);
  color: var(--parchment);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--edge);
  transition: transform .06s steps(2), box-shadow .06s steps(2), background .12s;
}
.btn:hover { background: #3a2a6b; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge); }
.btn-gold { background: var(--gold); color: #2a1a00; border-color: #7a4e00; box-shadow: 0 3px 0 #7a4e00; }
.btn-gold:hover { background: #ffd271; }
.btn-ghost { background: transparent; border-color: var(--line); box-shadow: 0 3px 0 #1c1338; }
.btn-small { font-size: 8px; padding: 8px 10px; }

input[type=text], input[type=email], input[type=search], input[type=date], select, textarea {
  width: 100%;
  padding: 11px 12px;
  background: #1a1138;
  border: 2px solid var(--line);
  border-radius: var(--r);
  color: var(--parchment);
  font-family: var(--body);
  font-size: 15px;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible,
[tabindex]:focus-visible, button:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
}
::placeholder { color: #6f5fa6; }

/* ───────────────── gate ───────────────── */

.gate {
  position: relative; z-index: 1;
  min-height: 100svh;
  display: grid; place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel) 0%, #1d1440 100%);
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 0 0 4px var(--edge), 0 24px 60px rgba(0,0,0,.6);
  padding: 34px 28px 28px;
  text-align: center;
}
.gate-hero { width: 112px; height: auto; margin-bottom: 18px; }
.gate-title {
  font-family: var(--px);
  font-size: 22px;
  color: var(--gold);
  text-shadow: 0 3px 0 #7a4e00, 0 6px 14px rgba(0,0,0,.6);
  margin-bottom: 14px;
}
.gate-sub { color: var(--muted); font-family: var(--body); font-size: 14px; margin: 0 0 24px; line-height: 1.6; }
.gate form { text-align: left; display: grid; gap: 8px; }
.gate label { font-family: var(--px); font-size: 9px; color: var(--muted); }
.gate .btn { margin-top: 8px; }
.gate-error { min-height: 20px; margin: 4px 0 0; color: var(--rose); font-family: var(--body); font-size: 13px; }

/* ───────────────── layout ───────────────── */

#app {
  position: relative; z-index: 1;
  min-height: 100svh;
  display: grid;
  grid-template-columns: var(--hud-w) minmax(0, 1fr);
}

/* ───────────────── HUD ───────────────── */

.hud {
  border-right: 2px solid var(--line);
  background: linear-gradient(180deg, rgba(36,26,71,.96), rgba(20,13,44,.96));
  padding: 20px 18px 28px;
  display: flex; flex-direction: column; gap: 22px;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 100svh;
  position: sticky; top: 0;
}
.hud-top { display: flex; gap: 14px; align-items: center; }
.hero-plate {
  background: #170e36;
  border: 2px solid var(--line);
  border-radius: var(--r);
  padding: 6px;
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 2px #0f0a26;
}
.hero-plate canvas { width: 72px; height: auto; display: block; }
.hero-plate.cheer { animation: hop .5s steps(4) 1; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-9px); }
  70% { transform: translateY(-3px); }
}
.hud-meta { flex: 1; min-width: 0; }
.hud-level { font-family: var(--px); font-size: 30px; color: var(--gold); line-height: 1; text-shadow: 0 3px 0 #7a4e00; }
.hud-levelword { font-family: var(--px); font-size: 8px; color: var(--muted); margin: 6px 0 9px; }

.xpbar {
  position: relative; height: 18px;
  background: #140d2e;
  border: 2px solid var(--edge);
  border-radius: 2px;
  overflow: hidden;
}
.xpbar-fill {
  height: 100%; width: 0;
  background: repeating-linear-gradient(90deg, var(--emerald) 0 6px, #46c974 6px 8px);
  transition: width .55s steps(14);
}
.xpbar-text {
  display: block;
  margin-top: 7px;
  font-family: var(--body); font-size: 11px; letter-spacing: .02em;
  color: var(--muted);
}
.xpbar.small { height: 10px; border-width: 2px; }

.hud-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: #1b1239;
  border: 2px solid var(--line);
  border-radius: var(--r);
  padding: 10px;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 8px; align-items: center;
}
.stat-ico { width: 20px; height: 20px; grid-row: 1 / span 2; }
.stat b { font-family: var(--px); font-size: 14px; color: var(--parchment); }
.stat span { font-family: var(--body); font-size: 11px; color: var(--muted); line-height: 1.3; }

.hud-section h2 { font-family: var(--px); font-size: 9px; color: var(--muted); margin-bottom: 12px; }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.badge {
  aspect-ratio: 1;
  display: grid; place-items: center;
  background: #16102f;
  border: 2px solid var(--line);
  border-radius: var(--r);
  filter: grayscale(1) brightness(.5);
  cursor: help;
}
.badge canvas { width: 22px; height: 22px; }
.badge.earned { filter: none; border-color: var(--gold); background: #2a1f0d; }

.label-admin { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.label-admin .chip { cursor: default; }
.label-admin .chip button {
  background: none; border: 0; color: inherit; cursor: pointer;
  opacity: .55; padding: 0 0 0 5px; font-size: 13px; line-height: 1;
}
.label-admin .chip button:hover { opacity: 1; }
.label-new { display: grid; grid-template-columns: minmax(0,1fr) auto auto; gap: 6px; align-items: center; }
.label-new input[type=color] {
  width: 38px; height: 38px; padding: 2px; background: #1a1138;
  border: 2px solid var(--line); border-radius: var(--r); cursor: pointer;
}
.label-new input:not([type=color]) { font-size: 13px; padding: 9px 10px; }

/* ───────────────── topbar ───────────────── */

.board-wrap { display: flex; flex-direction: column; min-width: 0; }

.topbar { display: none; }

.filters {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 20px 24px 12px;
}
.filters input[type=search] { max-width: 300px; }
.filter-labels { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-labels .chip { cursor: pointer; opacity: .42; }
.filter-labels .chip[aria-pressed=true] { opacity: 1; }

/* ───────────────── board ───────────────── */

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  padding: 8px 24px 40px;
  align-items: stretch;
  flex: 1;
}

.lane {
  background: rgba(21,14,45,.72);
  border: 2px solid var(--line);
  border-radius: 6px;
  min-height: 220px;
  display: flex; flex-direction: column;
}
.lane.over { border-color: var(--gold); background: rgba(44,32,86,.9); }

.lane-head {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 12px 10px;
  border-bottom: 2px solid var(--line);
  background: linear-gradient(180deg, #2b1f55, #221747);
  border-radius: 4px 4px 0 0;
}
.lane-head canvas { width: 18px; height: 18px; }
.lane-name { font-family: var(--px); font-size: 10px; letter-spacing: .02em; white-space: nowrap; }
.lane-count {
  margin-left: auto; flex: none;
  font-family: var(--px); font-size: 9px; color: var(--muted);
  background: #150e30; border: 2px solid var(--edge); border-radius: 2px;
  padding: 4px 6px;
}
.lane-add {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 22px; line-height: 1; padding: 0 2px;
}
.lane-add:hover { color: var(--gold); }

.lane-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.lane-empty {
  font-family: var(--body); font-size: 13px; color: #6f5fa6;
  text-align: center; padding: 22px 10px; line-height: 1.6;
}

/* ───────────────── cards ───────────────── */

.card {
  background: linear-gradient(180deg, #2a1e55, #231848);
  border: 2px solid var(--edge);
  border-left: 5px solid var(--prio, var(--violet));
  border-radius: var(--r);
  padding: 11px 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.45);
  display: grid; gap: 8px;
}
.card:hover { background: linear-gradient(180deg, #32245f, #281b52); }
.card.dragging { opacity: .4; }
.card.done .card-title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; }
.card-top { display: flex; gap: 8px; align-items: flex-start; }
.card-top canvas { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.card-title { font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.chip {
  font-family: var(--body);
  font-size: 11px; line-height: 1;
  padding: 5px 8px;
  border-radius: 2px;
  border: 2px solid currentColor;
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(0,0,0,.28);
}
.chip.due { color: var(--cyan); }
.chip.due.soon { color: var(--gold); }
.chip.due.late { color: var(--rose); }
.chip.xp { color: var(--emerald); font-family: var(--px); font-size: 8px; padding: 6px 7px; }
.card-thumbs { display: flex; gap: 5px; }
.card-thumbs img, .card-thumbs .file-pill {
  width: 38px; height: 38px; object-fit: cover;
  border: 2px solid var(--line); border-radius: 2px; background: #140d2e;
}
.file-pill { display: grid; place-items: center; font-size: 15px; color: var(--muted); }
.card-check {
  justify-self: start;
  font-family: var(--px); font-size: 8px;
  background: #16102f; border: 2px solid var(--line); border-radius: 2px;
  color: var(--muted); padding: 7px 8px; cursor: pointer;
}
.card-check:hover { color: var(--emerald); border-color: var(--emerald); }
.card-foot { display: flex; align-items: center; gap: 8px; }

/* ───────────────── sheet ───────────────── */

.sheet-scrim { position: fixed; inset: 0; background: rgba(8,5,20,.72); z-index: 40; }
.sheet {
  position: fixed; z-index: 50;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: min(88svh, 900px);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--panel), #1b1240);
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 0 0 4px var(--edge), 0 30px 70px rgba(0,0,0,.6);
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 2px solid var(--line);
}
.sheet-head h2 { font-family: var(--px); font-size: 12px; color: var(--gold); }
.icon-btn {
  margin-left: auto; background: none; border: 0; color: var(--muted);
  font-size: 20px; cursor: pointer; line-height: 1; padding: 4px 6px;
}
.icon-btn:hover { color: var(--parchment); }
.sheet-body { padding: 18px; overflow-y: auto; display: grid; gap: 7px; grid-auto-rows: min-content; align-content: start; }
.sheet-body textarea { min-height: 96px; }
.sheet-body label { font-family: var(--px); font-size: 9px; color: var(--muted); margin-top: 10px; }
.sheet-body label:first-child { margin-top: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 label { margin-top: 10px; display: block; }

.prio-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.prio {
  display: grid; place-items: center; gap: 5px;
  padding: 10px 4px;
  background: #1a1138; border: 2px solid var(--line); border-radius: var(--r);
  cursor: pointer; font-family: var(--body); font-size: 11px; color: var(--muted);
}
.prio canvas { width: 20px; height: 20px; }
.prio[aria-pressed=true] { border-color: var(--gold); color: var(--parchment); background: #2a1f4f; }

.label-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.label-pick .chip { cursor: pointer; opacity: .42; }
.label-pick .chip[aria-pressed=true] { opacity: 1; }

.media-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.media-item { position: relative; }
.media-item img, .media-item .file-pill { width: 72px; height: 72px; border-radius: 2px; border: 2px solid var(--line); object-fit: cover; }
.media-item button {
  position: absolute; top: -8px; right: -8px;
  width: 22px; height: 22px; border-radius: 2px;
  background: var(--rose); color: #2a0008; border: 2px solid var(--edge);
  cursor: pointer; font-size: 12px; line-height: 1; padding: 0;
}
.file-drop {
  display: grid; place-items: center;
  padding: 18px; margin-top: 6px;
  border: 2px dashed var(--line); border-radius: var(--r);
  color: var(--muted); font-family: var(--body); font-size: 13px; cursor: pointer;
}
.file-drop.over { border-color: var(--gold); color: var(--gold); }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.sheet-error { color: var(--rose); font-family: var(--body); font-size: 13px; min-height: 18px; margin: 6px 0 0; }

/* ───────────────── toasts & burst ───────────────── */

.toasts { position: fixed; z-index: 60; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; }
.toast {
  background: var(--panel-2); border: 2px solid var(--line); border-radius: var(--r);
  box-shadow: 0 0 0 3px var(--edge);
  padding: 11px 15px; font-family: var(--body); font-size: 14px;
  max-width: 88vw;
}
.toast.good { border-color: var(--emerald); }
.toast.bad { border-color: var(--rose); }
.toast b { font-family: var(--px); font-size: 9px; display: block; margin-bottom: 4px; color: var(--gold); }

.burst { position: fixed; z-index: 70; pointer-events: none; inset: 0; }
.xpfloat {
  position: absolute;
  font-family: var(--px); font-size: 14px; color: var(--emerald);
  text-shadow: 0 2px 0 #0b1f14;
  animation: rise 1.1s steps(11) forwards;
}
@keyframes rise {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-70px); opacity: 0; }
}
.levelup {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  pointer-events: none;
}
.levelup span {
  font-family: var(--px); font-size: clamp(18px, 6vw, 40px); color: var(--gold);
  text-shadow: 0 4px 0 #7a4e00, 0 0 30px rgba(255,194,71,.6);
  animation: pop 1.5s steps(8) forwards;
}
@keyframes pop {
  0% { transform: scale(.4); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  75% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.1); opacity: 0; }
}

.fab { display: none; }
.lanebar { display: none; }

/* ───────────────── mobile ───────────────── */

@media (max-width: 900px) {
  body { font-size: 16px; }
  #app { grid-template-columns: 1fr; padding-bottom: 86px; }

  .topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px calc(12px);
    padding-top: max(12px, env(safe-area-inset-top));
    border-bottom: 2px solid var(--line);
    background: rgba(26,17,56,.95);
    position: sticky; top: 0; z-index: 35;
    backdrop-filter: blur(6px);
  }
  .topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .topbar-brand canvas { width: 34px; height: auto; }
  .topbar-title { font-family: var(--px); font-size: 11px; color: var(--gold); }
  .topbar-sub { font-family: var(--body); font-size: 11px; color: var(--muted); margin-top: 4px; }
  .topbar-xp { flex: 1; min-width: 60px; }

  .hud {
    position: fixed; z-index: 30;
    inset: 0 0 0 0;
    max-height: none;
    border-right: 0;
    background: #180f3a;
    padding-top: calc(80px + env(safe-area-inset-top));
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
    display: none;
  }
  .hud.open { display: flex; }
  .hud .btn#signOut { margin-top: auto; }

  .filters { padding: 12px 14px 6px; flex-direction: column; align-items: stretch; gap: 10px; }
  .filters input[type=search] { max-width: none; width: 100%; }
  .filter-labels { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .filter-labels::-webkit-scrollbar { display: none; }
  .filter-labels .chip { flex: none; }

  .board { grid-template-columns: 1fr; padding: 6px 14px 24px; gap: 0; }
  .lane { display: none; background: transparent; border: 0; }
  .lane.active { display: flex; }
  .lane-head { display: none; }
  .lane-body { padding: 6px 0 0; gap: 12px; }
  .card { padding: 13px 14px; }
  .card-title { font-size: 17px; }

  .lanebar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: rgba(22,14,48,.97);
    border-top: 2px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    backdrop-filter: blur(6px);
  }
  .lanetab {
    background: none; border: 0; cursor: pointer;
    padding: 10px 4px 12px;
    display: grid; justify-items: center; gap: 5px;
    color: var(--muted); font-family: var(--px); font-size: 7px;
    border-top: 3px solid transparent;
  }
  .lanetab canvas { width: 20px; height: 20px; filter: grayscale(.8) brightness(.8); }
  .lanetab[aria-selected=true] { color: var(--gold); border-top-color: var(--gold); }
  .lanetab[aria-selected=true] canvas { filter: none; }
  .lanetab i { font-style: normal; font-family: var(--body); font-size: 10px; }

  .fab {
    display: grid; place-items: center;
    position: fixed; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom));
    z-index: 26;
    width: 60px; height: 60px;
    border-radius: 6px;
    background: var(--gold); color: #2a1a00;
    border: 2px solid #7a4e00; box-shadow: 0 4px 0 #5a3900, 0 10px 24px rgba(0,0,0,.5);
    font-size: 30px; line-height: 1; cursor: pointer;
  }
  .fab:active { transform: translateY(4px); box-shadow: 0 0 0 #5a3900; }

  .sheet {
    top: auto; bottom: 0; left: 0; transform: none;
    width: 100%; max-height: 92svh;
    border-radius: 8px 8px 0 0;
    border-bottom: 0;
  }
  .sheet-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(92px + env(safe-area-inset-bottom)); }
}

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