:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --fg: #101010;
  --muted: #6a6a64;
  --line: #d9d8d1;
  --panel: #ffffff;
  --soft: #ededeb;
  --accent: #0f0f0f;
  --ok: #147a45;
  --warn: #9b5d00;
  --bad: #a12626;
  --radius: 7px;
  --shadow: 0 18px 50px rgb(16 16 16 / 8%);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080808;
  --fg: #f4f4f0;
  --muted: #a9a9a2;
  --line: #2d2d2a;
  --panel: #111111;
  --soft: #1c1c1a;
  --accent: #f4f4f0;
  --ok: #64c18c;
  --warn: #e4a53e;
  --bad: #ee7777;
  --shadow: 0 18px 50px rgb(0 0 0 / 28%);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--fg);
  font: inherit;
}

input[type="range"] {
  accent-color: var(--accent);
  padding: 0;
}

button {
  min-height: 40px;
  padding: 0 16px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.ghost, .theme-toggle {
  background: transparent;
  color: var(--fg);
  border-color: var(--line);
}

button.primary {
  min-width: 128px;
  font-weight: 700;
}

input, select {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
}

.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(22px, 3vw, 34px); line-height: 1.1; }
h2 { font-size: 22px; line-height: 1.2; }
h3 { font-size: 18px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 18px clamp(18px, 4vw, 48px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.top-actions, .split, .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar .top-actions {
  justify-content: flex-end;
}

.nav {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-self: center;
}

.nav a {
  min-height: 44px;
  min-width: 82px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
}

.nav a.active, .nav a:hover {
  border-color: var(--accent);
  color: var(--fg);
  background: var(--panel);
}

.layout {
  display: grid;
  gap: 28px;
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 56px;
}

.layout.narrow {
  width: min(980px, calc(100% - 32px));
}

.auth-layout {
  min-height: 100vh;
  align-content: center;
  margin-block: 0;
}

.auth-theme {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 10;
}

.auth-head {
  display: grid;
  gap: 8px;
}

.auth-head h1 {
  font-size: 30px;
}

.hero.compact.login-hero {
  min-height: 620px;
}

.login-panel {
  align-self: center;
}

.login-fields {
  display: grid;
  gap: 16px;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.code-row button {
  min-width: 96px;
  padding-inline: 12px;
  white-space: nowrap;
}

.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.auth-links.single {
  justify-content: center;
}

.auth-links a {
  color: var(--fg);
  text-decoration-color: var(--line);
  text-underline-offset: 4px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: end;
  min-height: 300px;
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--panel), var(--soft));
  box-shadow: var(--shadow);
}

.hero.compact {
  min-height: 420px;
}

.hero h2 { max-width: 760px; font-size: clamp(30px, 6vw, 66px); letter-spacing: 0; }
.auth-panel, .panel {
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.grid, .two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.cards, .plans {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.card {
  display: grid;
  gap: 14px;
  min-height: 220px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.metric { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; }
.metric strong { font-size: 38px; line-height: 1; }
.checkin-button { width: fit-content; min-width: 128px; }
.eyebrow { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
.muted { color: var(--muted); }
.status { width: fit-content; padding: 4px 8px; border: 1px solid var(--line); font-size: 12px; }
.status, .notice { border-radius: var(--radius); }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }

.notice-strip {
  display: grid;
  gap: 8px;
}

.notice {
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: var(--panel);
}

.table { display: grid; gap: 10px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.pager button {
  min-width: 76px;
}

button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.instance-actions, .buy-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

[data-form="redeem"] {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

[data-form="redeem"] button {
  min-width: 96px;
}

.panel > .cards {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel > .cards:empty {
  display: none;
}

.panel .card {
  background: var(--soft);
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 220px;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

dialog { border: 0; padding: 0; background: transparent; color: var(--fg); }
.dialog-card { width: min(420px, calc(100vw - 32px)); display: grid; gap: 14px; padding: 22px; background: var(--panel); border: 1px solid var(--line); }
.dialog-card { border-radius: var(--radius); box-shadow: var(--shadow); }
.dialog-card.wide { width: min(860px, calc(100vw - 32px)); }

.create-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
}

.tier-list, .detail-panel {
  display: grid;
  align-content: start;
  gap: 10px;
}

.tier-option {
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  color: var(--fg);
  border-color: var(--line);
  border-radius: var(--radius);
}

.tier-option:hover {
  border-color: var(--accent);
}

.tier-option.selected {
  border-color: var(--accent);
  background: var(--soft);
}

.range-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.range-field input {
  grid-column: 1 / -1;
}

.discount-hint {
  position: relative;
  color: var(--muted);
}

.discount-hint span {
  color: var(--fg);
  cursor: help;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 4px;
}

.discount-popover {
  position: absolute;
  right: 28px;
  bottom: 78px;
  z-index: 5;
  min-width: 220px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .15s ease, transform .15s ease;
}

.discount-hint:has(span:hover) + .discount-popover,
.discount-hint:has(span:focus) + .discount-popover,
.discount-popover:hover {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.discount-popover table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.discount-popover th,
.discount-popover td {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.discount-popover tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 860px) {
  .hero, .grid, .two-col, .cards, .plans, .create-layout, .topbar, [data-form="redeem"] { grid-template-columns: 1fr; }
  .topbar, .section-head { align-items: flex-start; }
  .nav { justify-self: stretch; overflow-x: auto; }
  .topbar .top-actions, .top-actions, .split, .instance-actions, .buy-form { width: 100%; grid-template-columns: 1fr; flex-direction: column; align-items: stretch; }
  .checkin-button { width: 100%; }
  .pager { justify-content: space-between; }
  .auth-layout { min-height: auto; margin-block: 72px 56px; }
}
