/* =================================================== Äventyret · stil ===
   An 8-bit interface: no rounded corners anywhere, hard offset shadows
   instead of blurred ones, thick solid borders, a flat NES-ish palette and a
   monospace face throughout. Buttons physically sink when pressed.
   ======================================================================= */

:root {
  --font: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, 'Courier New', monospace;

  --bg: #efe6cf;
  --bg-alt: #e4d8bc;
  --surface: #fffaf0;
  --surface-alt: #f7eeda;
  --ink: #1d1a33;
  --muted: #5b5578;
  --subtle: #837c9e;
  --line: #171436;
  --line-soft: #cbbf9f;

  --accent: #d94a24;
  --accent-ink: #ffffff;
  --gold: #e8b32c;
  --green: #3f9c53;
  --blue: #2f7fd6;
  --purple: #7d4fc4;
  --danger: #c8321a;

  --shadow: 4px 4px 0 var(--line);
  --shadow-sm: 3px 3px 0 var(--line);
  --shadow-press: 1px 1px 0 var(--line);

  --sky-1: #1a1740;
  --sky-2: #2c2560;

  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #14112c;
  --bg-alt: #1b1740;
  --surface: #241f4d;
  --surface-alt: #2c2659;
  --ink: #f3ecd9;
  --muted: #b0a8d4;
  --subtle: #8880b0;
  --line: #0b0919;
  --line-soft: #3d3670;

  --accent: #ef7a4e;
  --accent-ink: #1d1023;
  --gold: #f5c542;
  --green: #57b364;
  --blue: #5aa8f5;
  --purple: #a077e8;
  --danger: #e35b3d;

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #14112c;
    --bg-alt: #1b1740;
    --surface: #241f4d;
    --surface-alt: #2c2659;
    --ink: #f3ecd9;
    --muted: #b0a8d4;
    --subtle: #8880b0;
    --line: #0b0919;
    --line-soft: #3d3670;

    --accent: #ef7a4e;
    --accent-ink: #1d1023;
    --gold: #f5c542;
    --green: #57b364;
    --blue: #5aa8f5;
    --purple: #a077e8;
    --danger: #e35b3d;

    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1.25;
}

h1 { font-size: 1.4rem; text-transform: uppercase; }
h2 { font-size: 1.05rem; text-transform: uppercase; }
h3 { font-size: .95rem; }
p { margin: 0; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.subtle { color: var(--subtle); font-size: .82rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }

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

::selection { background: var(--gold); color: #1d1a33; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

/* ---------------------------------------------------------- controls --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 3px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .06s steps(2), box-shadow .06s steps(2), background .1s;
}

.btn:hover:not(:disabled) { background: var(--surface-alt); }

.btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: var(--shadow-press);
}

.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: var(--shadow-press); transform: translate(2px, 2px); }

.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.secondary { background: var(--gold); color: #1d1a33; }
.btn.ghost { background: transparent; box-shadow: none; border-color: var(--line-soft); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-alt); border-color: var(--line); }
.btn.ghost:active:not(:disabled) { box-shadow: none; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger-outline:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn.small { padding: 7px 12px; font-size: .72rem; border-width: 2px; box-shadow: 2px 2px 0 var(--line); }
.btn.small:active:not(:disabled) { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--line); }

.link-btn {
  background: none;
  border: 0;
  padding: 4px 2px;
  color: var(--accent);
  font-family: var(--font);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field > span {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type='text'], input[type='email'], input[type='password'],
input[type='date'], input[type='number'], select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 3px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  font-size: .92rem;
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, .06);
}

textarea { resize: vertical; line-height: 1.6; }

input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }

input::placeholder, textarea::placeholder { color: var(--subtle); opacity: .8; }

select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: .86rem;
  cursor: pointer;
}

.checkbox input[type='checkbox'] {
  appearance: none;
  width: 20px;
  height: 20px;
  margin: 0;
  flex: none;
  border: 3px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}

.checkbox input[type='checkbox']:checked {
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--surface);
}

.segmented {
  display: inline-flex;
  border: 3px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.segmented button {
  padding: 9px 14px;
  border: 0;
  border-right: 3px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font);
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}

.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--accent); color: var(--accent-ink); }

.pixel-select {
  width: auto;
  min-width: 190px;
  max-width: 100%;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}

.pixel-select.single { pointer-events: none; background-image: none; padding-right: 12px; }

.inline-select { width: auto; padding: 6px 28px 6px 10px; font-size: .82rem; border-width: 2px; }

/* ------------------------------------------------------------- login --- */

.login-screen {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2));
  overflow: hidden;
}

.starfield { position: absolute; inset: 0; pointer-events: none; }

.starfield i {
  position: absolute;
  background: #fdf6e3;
  opacity: .8;
  animation: twinkle 4s steps(2, end) infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: .85; }
  50% { opacity: .2; }
}

.login-main { position: relative; width: 100%; max-width: 430px; }

.login-card {
  border: 4px solid #0b0919;
  background: var(--surface);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, .45);
  padding: 30px 26px 26px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-big {
  flex-direction: column;
  gap: 6px;
  text-align: center;
  margin-bottom: 22px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border: 3px solid var(--line);
  flex: none;
}

.brand-mark.small { width: 32px; height: 32px; border-width: 2px; }

.brand-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink);
}

.brand-big .brand-title { font-size: 1.7rem; }

.brand-sub {
  font-size: .68rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--subtle);
}

.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-text .brand-title { font-size: 1rem; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.auth-head { margin-bottom: 2px; }
.auth-head h1 { font-size: 1.15rem; margin-bottom: 6px; }
.auth-head p { color: var(--muted); font-size: .86rem; }

.auth-message {
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 3px solid var(--line);
  font-size: .84rem;
  white-space: pre-line;
}

.auth-message.error { background: var(--danger); color: #fff; }
.auth-message.ok { background: var(--green); color: #fff; }

.auth-foot { display: flex; justify-content: center; }

.auth-note, .password-hint {
  font-size: .76rem;
  line-height: 1.6;
  color: var(--subtle);
  border-top: 3px solid var(--line-soft);
  padding-top: 12px;
}

.password-hint { border: 0; padding: 0; }

/* --------------------------------------------------------- app shell --- */

.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 4px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}

.top-nav { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }

.nav-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}

.nav-item:hover { color: var(--ink); border-color: var(--line-soft); }

.nav-item.active {
  background: var(--accent);
  border-color: var(--line);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

.nav-glyph { font-size: .9rem; line-height: 1; }

.topbar-user { display: flex; align-items: center; gap: 8px; }

.avatar-canvas {
  width: 28px;
  height: 32px;
  flex: none;
}

.user-name {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.content {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 18px 60px;
  padding-bottom: max(60px, calc(40px + env(safe-area-inset-bottom)));
}

.view { display: none; }
.view.active-view { display: block; animation: fade-in .18s steps(3, end); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.view-head { margin-bottom: 20px; }
.view-head h1 { margin-bottom: 6px; }
.view-head p { color: var(--muted); font-size: .88rem; }

/* --------------------------------------------------------------- map --- */

.map-wrap { display: flex; flex-direction: column; gap: 14px; }

.map-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.map-title { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.map-meta { font-size: .8rem; color: var(--muted); letter-spacing: .02em; }

.map-stats { display: flex; gap: 8px; }

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 62px;
  padding: 7px 10px;
  border: 3px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat.presence { background: var(--gold); }
.stat-value { font-size: 1.15rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat.presence .stat-value { color: #1d1a33; }

.stat-label {
  font-size: .6rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 3px;
}

.stat.presence .stat-label { color: #4a3a12; }

/* --map-scale is the canvas zoom, read by map.js. It lives here so the map
   size is a design decision per breakpoint rather than a JS guess, and it must
   stay a whole number. The map is 132 logical pixels tall, so scale 3 renders
   a 396 px canvas. No height on this box: the canvas provides it. */
.map-stage {
  --map-scale: 3;
  position: relative;
  border: 4px solid var(--line);
  background: #1a1740;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

@media (max-width: 900px), (max-height: 720px) {
  .map-stage { --map-scale: 2; }
}

@media (min-width: 1500px) and (min-height: 1000px) {
  .map-stage { --map-scale: 4; }
}

.map-canvas { display: block; max-width: 100%; touch-action: manipulation; }
.map-canvas:focus-visible { outline: 3px solid var(--gold); outline-offset: -3px; }

.map-canvas.shake { animation: shake .36s steps(2, end); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.map-controls {
  display: flex;
  gap: 8px;
  padding: 10px;
  width: 100%;
  justify-content: center;
  background: rgba(11, 9, 25, .55);
  border-top: 3px solid var(--line);
}

.pad-btn {
  min-width: 52px;
  padding: 11px 14px;
  border: 3px solid #0b0919;
  background: #f3ecd9;
  color: #1d1a33;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 3px 3px 0 #0b0919;
}

.pad-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #0b0919; }
.pad-btn.wide-pad { min-width: 120px; background: var(--gold); }

.level-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  scrollbar-width: thin;
}

.level-chip {
  flex: none;
  width: 92px;
  padding: 9px 8px;
  border: 3px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.level-chip:active { transform: translate(2px, 2px); box-shadow: var(--shadow-press); }
.level-chip.selected { background: var(--accent); color: var(--accent-ink); }
.level-chip.today { border-color: var(--gold); box-shadow: 3px 3px 0 var(--gold); }
.level-chip.opened .chip-day::after { content: ' ★'; color: var(--gold); }
.level-chip.locked { opacity: .62; }

/* Not walked past yet. Still clickable — the chip is how you set off towards
   it — but it gives nothing away. */
.level-chip.undiscovered {
  border-style: dashed;
  color: var(--subtle);
  background: var(--bg-alt);
  box-shadow: none;
}

.level-chip.undiscovered .chip-day { opacity: .7; }
.level-chip.undiscovered .chip-day::after { content: none; }

/* A padlock drawn from a border rather than an emoji, which would render in
   full colour and break the pixel palette. */
.level-chip.locked .chip-day::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 9px;
  margin-left: 5px;
  border: 2px solid currentColor;
  border-top-width: 5px;
  vertical-align: 1px;
}

.chip-day { font-size: 1rem; font-weight: 700; line-height: 1.1; }
.chip-date { font-size: .64rem; letter-spacing: .06em; text-transform: uppercase; opacity: .75; }

.chip-title {
  font-size: .68rem;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  min-height: 1.7em;
}

/* ------------------------------------------------------------ panels --- */

.panel {
  border: 4px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 22px;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 3px solid var(--line-soft);
}

.panel-head h2 { margin-bottom: 5px; }
.panel-head p { color: var(--muted); font-size: .82rem; max-width: 60ch; }

.danger-zone { border-color: var(--danger); box-shadow: 4px 4px 0 var(--danger); }
.danger-zone .panel-head { border-bottom-color: var(--danger); }

.setting-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 2px dashed var(--line-soft);
}

.setting-row:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-text { min-width: 0; flex: 1 1 260px; }
.setting-text h3 { margin-bottom: 3px; }
.setting-text p { font-size: .8rem; color: var(--muted); }
.setting-control { flex: 0 1 320px; min-width: 200px; }
.setting-control.inline { display: flex; gap: 8px; }
.setting-control.narrow { flex: 0 0 auto; min-width: 0; }

.invite-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  align-items: end;
}

.invite-form.two-col { grid-template-columns: minmax(200px, 1fr) auto; }
.invite-extras { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin-top: 14px; }

.empty {
  border: 4px dashed var(--line-soft);
  padding: 40px 24px;
  text-align: center;
}

.empty h3 { margin-bottom: 8px; font-size: 1.05rem; text-transform: uppercase; letter-spacing: .08em; }
.empty p { color: var(--muted); font-size: .88rem; margin-bottom: 18px; }

/* -------------------------------------------------------------- plan --- */

.plan-list { display: flex; flex-direction: column; gap: 8px; }

.plan-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px 12px;
  border: 3px solid var(--line-soft);
  background: var(--surface-alt);
  color: var(--ink);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
}

.plan-row:hover { border-color: var(--line); background: var(--surface); }
.plan-row.filled { border-left: 8px solid var(--green); }
.plan-tile { width: 48px; height: 48px; flex: none; border: 2px solid var(--line); }
.plan-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }

.plan-day {
  font-size: .66rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.plan-title { font-size: .95rem; font-weight: 700; }
.plan-row:not(.filled) .plan-title { color: var(--subtle); font-weight: 400; font-style: italic; }

.plan-body {
  font-size: .78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-edit { font-size: 1.1rem; color: var(--muted); flex: none; }

/* ------------------------------------------------------------ family --- */

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.member-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 3px solid var(--line-soft);
  background: var(--surface-alt);
}

.member-card.here { border-color: var(--green); box-shadow: 3px 3px 0 var(--green); }
.member-avatar { width: 56px; height: 64px; flex: none; }
.member-body { min-width: 0; flex: 1; }
.member-body h3 { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; }

.member-mail {
  font-size: .72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.member-head { display: flex; align-items: center; gap: 14px; margin: 16px 0 20px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border: 2px solid var(--line);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.ok { background: var(--green); color: #fff; }
.badge.admin { background: var(--purple); color: #fff; }
.badge.pending { background: var(--gold); color: #1d1a33; }
.badge.bad { background: var(--danger); color: #fff; }
.badge.off { background: var(--bg-alt); color: var(--muted); }

.event-list { display: flex; flex-direction: column; gap: 8px; }

.event-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 3px solid var(--line-soft);
  background: var(--surface-alt);
  font-size: .82rem;
}

.event-mail { flex: 1; min-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.event-time { font-size: .72rem; color: var(--subtle); white-space: nowrap; }
.event-diag { font-size: .72rem; color: var(--danger); flex-basis: 100%; }

/* ---------------------------------------------------------- settings --- */

.avatar-preview {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px;
  margin-bottom: 18px;
  border: 3px solid var(--line);
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2));
  color: #f3ecd9;
}

.avatar-preview canvas { width: 112px; height: 128px; flex: none; }
.avatar-preview h3 { font-size: 1.1rem; text-transform: uppercase; letter-spacing: .1em; color: var(--gold); }
.avatar-preview p { color: #b0a8d4; }

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.avatar-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 6px 8px;
  border: 3px solid var(--line-soft);
  background: var(--surface-alt);
  color: var(--muted);
  font-family: var(--font);
  font-size: .62rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
}

.avatar-option canvas { width: 56px; height: 64px; }
.avatar-option:hover { border-color: var(--line); }

.avatar-option.active {
  border-color: var(--line);
  background: var(--gold);
  color: #1d1a33;
  box-shadow: var(--shadow-sm);
}

.color-grid { display: flex; flex-wrap: wrap; gap: 10px; }

.color-option {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 3px solid var(--line);
  background: linear-gradient(135deg, var(--swatch) 0 55%, var(--swatch-dark) 55% 100%);
  cursor: pointer;
}

.color-option.active { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--gold); }

.app-foot {
  text-align: center;
  font-size: .72rem;
  letter-spacing: .06em;
  color: var(--subtle);
  padding-top: 8px;
}

/* ------------------------------------------------------------- admin --- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.kpi {
  border: 3px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 14px;
}

.kpi-label {
  font-size: .62rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi-value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-hint { font-size: .7rem; color: var(--subtle); }

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: .82rem; }

table.data th {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 3px solid var(--line);
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

table.data td { padding: 10px; border-bottom: 2px dashed var(--line-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }

.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-stack { display: flex; flex-direction: column; min-width: 0; }
.cell-name { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.cell-mail { display: block; font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 2px solid var(--line);
  background: var(--purple);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
}

.avatar.big { width: 48px; height: 48px; font-size: .95rem; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 110px;
  padding: 10px;
  border: 3px solid var(--line-soft);
  background: var(--surface-alt);
}

.chart-bar { flex: 1; background: var(--line-soft); min-height: 2px; }
.chart-bar[data-has-data='true'] { background: var(--accent); }

.chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: .68rem;
  color: var(--subtle);
  margin-top: 6px;
}

/* ------------------------------------------------------------ modals --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(11, 9, 25, .74);
  animation: fade-in .12s steps(2, end);
  overflow-y: auto;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  padding: 24px;
  border: 4px solid var(--line);
  background: var(--surface);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, .5);
  animation: pop-in .16s steps(3, end);
}

@keyframes pop-in {
  from { transform: translateY(10px) scale(.97); }
  to { transform: translateY(0) scale(1); }
}

.modal h2 { margin-bottom: 10px; }
.modal > p { color: var(--muted); font-size: .88rem; }
.modal .field { margin-top: 16px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 3px solid var(--line-soft);
}

.modal-actions.spread { justify-content: flex-start; }
.stack { display: grid; gap: 8px; }

.editor { max-width: 560px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }

.terrain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 3px solid var(--line-soft);
  background: var(--surface-alt);
}

.terrain-option {
  display: grid;
  place-items: center;
  padding: 4px;
  border: 3px solid transparent;
  background: transparent;
  cursor: pointer;
}

.terrain-option canvas { width: 40px; height: 40px; }
.terrain-option:hover { border-color: var(--line-soft); }
.terrain-option.active { border-color: var(--accent); background: var(--surface); }

/* ------------------------------------------------- the level dialogue --- */

.dialog-box { max-width: 520px; padding: 0; overflow: hidden; }

.dialog-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2));
  border-bottom: 4px solid var(--line);
}

.dialog-tile { width: 96px; height: 96px; flex: none; border: 3px solid #0b0919; }
.dialog-heading { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.dialog-day {
  font-size: .68rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}

/* "torsdag 30 oktober" -> "Torsdag 30 oktober". capitalize would also raise
   the month, which is wrong in Swedish. */
.dialog-date { font-size: .95rem; color: #f3ecd9; }
.dialog-date::first-letter { text-transform: uppercase; }

.dialog-body { padding: 22px; min-height: 90px; }

.dialog-title {
  font-size: 1.15rem;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: .01em;
  margin-bottom: 12px;
  min-height: 1.35em;
}

.dialog-text { font-size: .92rem; line-height: 1.7; color: var(--muted); white-space: pre-line; }
.dialog-empty { font-size: .92rem; color: var(--subtle); font-style: italic; }

/* A blinking block cursor while the text types itself out. */
.typing::after {
  content: '';
  display: inline-block;
  width: .5em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -.15em;
  background: var(--accent);
  animation: blink .5s steps(1, end) infinite;
}

@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.dialog-facts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.fact {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 11px;
  border: 3px solid var(--line-soft);
  background: var(--surface-alt);
  font-size: .84rem;
}

.fact b {
  font-size: .62rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.dialog-box .modal-actions { margin: 0; padding: 16px 22px; background: var(--surface-alt); }

/* ------------------------------------------------------------ toasts --- */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 12px 16px;
  border: 3px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: .84rem;
  line-height: 1.5;
  white-space: pre-line;
  box-shadow: var(--shadow);
  transition: opacity .25s, transform .25s;
  animation: toast-in .18s steps(3, end);
}

.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--green); color: #fff; }

@keyframes toast-in {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ------------------------------------------------------------ mobile --- */

@media (max-width: 760px) {
  body { font-size: 14px; }

  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .top-nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item { padding: 7px 10px; font-size: .68rem; flex: none; }
  .nav-item span:not(.nav-glyph) { display: inline; }

  .content { padding: 16px 12px 48px; }
  .panel { padding: 16px 14px; }
  .map-head { align-items: stretch; }
  .map-stats { justify-content: flex-start; }
  .pixel-select { min-width: 0; width: 100%; font-size: .92rem; }
  .setting-control { flex: 1 1 100%; }
  .setting-control.narrow { flex: 0 0 auto; }
  .field-row { grid-template-columns: 1fr; }
  .avatar-preview { flex-direction: column; text-align: center; gap: 12px; }
  .modal { padding: 18px; }
  .dialog-box { padding: 0; }
  .dialog-head { flex-direction: column; text-align: center; padding: 16px; }
  .dialog-body { padding: 18px; }
  .dialog-box .modal-actions { padding: 14px 18px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; }
  .member-grid { grid-template-columns: 1fr; }
  .toast-stack { bottom: max(16px, env(safe-area-inset-bottom)); }
}

@media (max-width: 460px) {
  .brand-text .brand-title { font-size: .88rem; }
  .user-name { display: none; }
  .pad-btn { min-width: 46px; padding: 10px; }
  .pad-btn.wide-pad { min-width: 96px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Respect a reduced-motion preference: the map still animates, because it is
   the content, but nothing else jumps around. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
