/* ===========================================================
   THE FORGE — aurora glass design system
   ========================================================= */

:root {
  /* Surface */
  --ink:        #07070D;
  --ink-2:      #0B0D18;
  --ink-3:      #131628;

  /* Glass surfaces — used with backdrop-filter */
  --glass-1:    rgba(255, 255, 255, 0.045);
  --glass-2:    rgba(255, 255, 255, 0.075);
  --glass-3:    rgba(255, 255, 255, 0.11);

  /* Borders / hairlines */
  --line-1:     rgba(255, 255, 255, 0.08);
  --line-2:     rgba(255, 255, 255, 0.13);
  --line-3:     rgba(255, 255, 255, 0.22);

  /* The signature liquid-glass top edge */
  --lip:        rgba(255, 255, 255, 0.32);

  /* Ink text on dark */
  --text-1:     #F2EFE8;        /* warm off-white */
  --text-2:     #B0AEA8;
  --text-3:     #75736E;
  --text-4:     #4A4844;

  /* Accent — warm gold, restrained brand identity */
  --gold:       #C9A961;
  --gold-soft:  #E8CC8A;
  --gold-deep:  #8C7437;
  --gold-faint: rgba(201, 169, 97, 0.18);

  /* Aurora — colorful blurred backdrop orbs */
  --aurora-violet:  #7C5CFF;
  --aurora-magenta: #FF4FB8;
  --aurora-cyan:    #38D6FF;
  --aurora-mint:    #2BE3B5;
  --aurora-peach:   #FFB081;

  /* Glow accents (reused for colored borders/focus rings) */
  --glow-violet:    rgba(124, 92, 255, 0.55);
  --glow-magenta:   rgba(255, 79, 184, 0.45);
  --glow-cyan:      rgba(56, 214, 255, 0.45);

  /* Semantic */
  --danger:     #FF6B6B;
  --danger-soft:rgba(255, 107, 107, 0.16);

  /* Cell colors (defaults; per-cat overridden via --cat-color) */
  --cell-empty: rgba(255, 255, 255, 0.05);
  --cell-empty-strong: rgba(255, 255, 255, 0.085);

  /* Type */
  --display: 'Space Grotesk', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --body:    'Geist', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Sizing */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 32px;

  /* Backdrop-filter recipes */
  --blur-sm: blur(16px) saturate(160%);
  --blur-md: blur(28px) saturate(180%);
  --blur-lg: blur(40px) saturate(200%);

  /* Layered shadow stacks */
  --shadow-glass:
    0 1px 0 var(--lip) inset,
    0 0 0 1px rgba(255,255,255,0.04) inset,
    0 1px 2px rgba(0,0,0,0.4),
    0 24px 60px -20px rgba(0,0,0,0.55),
    0 8px 24px -16px var(--glow-violet);
  --shadow-glass-soft:
    0 1px 0 var(--lip) inset,
    0 16px 40px -20px rgba(0,0,0,0.5);

  /* Animation */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.4, 0, 0.6, 1);

  /* Safe area */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset ===== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  font-weight: 400;
  color: var(--text-1);
  background: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  letter-spacing: 0.005em;
}

button { font-family: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }

/* The `hidden` HTML attr must always win, no matter what `display` a class sets. */
[hidden] { display: none !important; }

/* ===== Aurora background ===== */

.aurora {
  position: fixed; inset: 0; z-index: -1;
  overflow: hidden; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 50% 30%, rgba(20, 18, 50, 0.45), transparent 70%),
    var(--ink);
}

.aurora-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  will-change: transform;
  transform: translateZ(0);
}

.orb-violet {
  width: 56vmax; height: 56vmax;
  top: -18vmax; left: -10vmax;
  opacity: 0.65;
  background: radial-gradient(closest-side, var(--aurora-violet), transparent 70%);
  animation: drift-a 28s ease-in-out infinite alternate;
}
.orb-magenta {
  width: 44vmax; height: 44vmax;
  top: 8vmax; right: -16vmax;
  opacity: 0.55;
  background: radial-gradient(closest-side, var(--aurora-magenta), transparent 70%);
  animation: drift-b 32s ease-in-out infinite alternate;
}
.orb-cyan {
  width: 50vmax; height: 50vmax;
  bottom: -14vmax; left: -12vmax;
  opacity: 0.5;
  background: radial-gradient(closest-side, var(--aurora-cyan), transparent 70%);
  animation: drift-c 30s ease-in-out infinite alternate;
}
.orb-mint {
  width: 34vmax; height: 34vmax;
  bottom: -8vmax; right: -8vmax;
  opacity: 0.45;
  background: radial-gradient(closest-side, var(--aurora-mint), transparent 70%);
  animation: drift-d 26s ease-in-out infinite alternate;
}
.orb-peach {
  width: 28vmax; height: 28vmax;
  top: 38%; left: 30%;
  opacity: 0.32;
  background: radial-gradient(closest-side, var(--aurora-peach), transparent 70%);
  animation: drift-e 24s ease-in-out infinite alternate;
}

.aurora-grain {
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='3'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.4 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.6'/></svg>");
  opacity: 0.06;
  mix-blend-mode: overlay;
  pointer-events: none;
}

@keyframes drift-a { to { transform: translate3d(8vmax, 6vmax, 0) rotate(8deg); } }
@keyframes drift-b { to { transform: translate3d(-6vmax, 8vmax, 0) rotate(-6deg); } }
@keyframes drift-c { to { transform: translate3d(10vmax, -4vmax, 0) rotate(5deg); } }
@keyframes drift-d { to { transform: translate3d(-8vmax, -6vmax, 0) rotate(-9deg); } }
@keyframes drift-e { to { transform: translate3d(6vmax, -8vmax, 0) rotate(12deg); } }

/* Static mode — toggleable from Settings; reduced-motion also forces this on. */
body.aurora-static .aurora-orb {
  animation: none !important;
  will-change: auto;
}

/* ===== Glass ===== */

.glass {
  background: linear-gradient(180deg,
    rgba(255,255,255,0.085) 0%,
    rgba(255,255,255,0.045) 50%,
    rgba(255,255,255,0.025) 100%);
  -webkit-backdrop-filter: var(--blur-md);
          backdrop-filter: var(--blur-md);
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-glass);
  position: relative;
  isolation: isolate;
}
/* The signature 1px gradient lip — wet-edge highlight on top */
.glass::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(180deg, rgba(255,255,255,0.45), rgba(255,255,255,0) 35%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  z-index: 1;
}

/* ===== Header ===== */

.app-header {
  position: sticky; top: 0; z-index: 30;
  padding: calc(var(--safe-top) + 12px) 12px 8px;
  background: transparent;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
  padding: 8px 12px 8px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,0.085), rgba(255,255,255,0.03));
  -webkit-backdrop-filter: var(--blur-md);
          backdrop-filter: var(--blur-md);
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  box-shadow: var(--shadow-glass-soft);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--gold-soft), var(--gold) 55%, var(--gold-deep) 90%);
  color: var(--ink);
  box-shadow:
    0 0 0 1px rgba(201,169,97,0.35),
    0 0 18px rgba(201,169,97,0.45),
    0 8px 22px -8px rgba(201,169,97,0.55),
    0 1px 0 rgba(255,255,255,0.45) inset;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name {
  font-family: var(--body); font-weight: 700;
  font-size: 13px; letter-spacing: 0.18em; color: var(--text-1);
}
.brand-tag {
  font-family: var(--display); font-weight: 400;
  font-size: 12px; color: var(--text-3); margin-top: 3px;
  letter-spacing: 0.01em;
}

.icon-button {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text-2);
  background: linear-gradient(180deg, rgba(255,255,255,0.085), rgba(255,255,255,0.025));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  transition: color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}
.icon-button:hover { color: var(--text-1); background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.04)); }
.icon-button:active { transform: scale(0.94); }

/* Status row */
.status-row {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.025));
  -webkit-backdrop-filter: var(--blur-md);
          backdrop-filter: var(--blur-md);
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  box-shadow: var(--shadow-glass-soft);
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--text-3);
}
.stat-value {
  font-family: var(--display); font-weight: 500;
  font-size: 28px; line-height: 1;
  color: var(--text-1);
  display: inline-flex; align-items: baseline; gap: 4px;
  letter-spacing: -0.01em;
}
.num {
  font-feature-settings: "tnum" 1;
  background: linear-gradient(180deg, #FFFFFF 0%, #E8CC8A 130%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}
.num-sm {
  font-family: var(--mono); font-size: 11px;
  color: var(--text-3); margin-left: 2px;
}
.stat-unit {
  font-family: var(--display); font-weight: 400;
  font-size: 15px; color: var(--text-3); margin-left: 2px;
}
.rank-text {
  font-family: var(--display); font-weight: 500;
  font-size: 20px; color: var(--gold-soft); letter-spacing: 0.005em;
}
.stat-divider { width: 1px; height: 28px; background: linear-gradient(180deg, transparent, var(--line-3), transparent); }

/* ===== Main ===== */

.forge-main {
  padding: 16px 16px 100px;
  display: flex; flex-direction: column; gap: 16px;
  min-height: calc(100vh - 130px);
}

/* ===== Grid card (the centerpiece) ===== */

.grid-card {
  padding: 18px 16px 16px;
  display: flex; flex-direction: column; gap: 14px;
  position: relative;
  min-height: 56vh;
  flex: 1 1 auto;
  border-radius: var(--r-xl);
}

.grid-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: 0 4px;
}
.eyebrow {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.28em;
  text-transform: uppercase; color: var(--text-3); display: block; margin-bottom: 4px;
}
.display {
  font-family: var(--display); font-weight: 500;
  font-size: 28px; line-height: 1.05;
  color: var(--text-1);
  letter-spacing: -0.015em;
  margin: 0;
}
h2.display { font-size: 28px; font-weight: 500; }
@media (min-width: 480px) {
  h2.display { font-size: 32px; }
}
.grid-meta {
  font-family: var(--mono); font-size: 11px; color: var(--text-3);
  white-space: nowrap; padding-bottom: 2px;
}

/* The grid stage — two-row CSS grid: top row holds the territory grids
   (all sharing one bottom baseline), bottom row holds the rotated labels. */
.grid-stage {
  flex: 1;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: min-content;
  grid-template-rows: 1fr auto;
  justify-content: center;
  column-gap: 14px;
  row-gap: 8px;
  padding: 16px 12px;
  border-radius: var(--r-md);
  background:
    linear-gradient(180deg, rgba(0,0,0,0.38), rgba(0,0,0,0.22)),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.015) 0 8px, transparent 8px 16px);
  border: 1px solid var(--line-1);
  min-height: 540px;
  overflow-x: auto; overflow-y: hidden;
  position: relative;
  z-index: 0;
}

/* One territory: spread its grid + label into the parent's two row tracks. */
.territory-col {
  display: contents;
}

.territory-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size, 8px));
  grid-template-rows:    repeat(50, var(--cell-size, 8px));
  gap: var(--cell-gap, 1px);
  padding: 5px;
  border-radius: var(--r-xs);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--cat-color, white) 5%, rgba(255,255,255,0.02)),
    color-mix(in srgb, var(--cat-color, white) 2%, rgba(255,255,255,0.01)));
  border: 1px solid color-mix(in srgb, var(--cat-color, white) 18%, var(--line-1));
  box-shadow:
    0 1px 0 rgba(255,255,255,0.06) inset,
    0 1px 2px rgba(0,0,0,0.25);
  align-self: end;             /* sit at the bottom of the grids row */
  justify-self: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .2s var(--ease);
}
.territory-col:hover  .territory-grid { transform: translateY(-2px); }
.territory-col:active .territory-grid { transform: scale(0.99); }

/* Vertical label below the grid; reads bottom-to-top.
   writing-mode + 180deg rotation flips reading direction without breaking layout flow,
   so the label's box width = font cap-height (it never makes the column wider than the grid). */
.territory-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  text-orientation: mixed;
  font-family: var(--display);
  font-weight: 500;
  font-size: 17px;
  letter-spacing: 0.01em;
  color: var(--text-1);
  max-height: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 0;
  align-self: start;           /* sit at the top of the labels row, right under the grid */
  justify-self: center;
  cursor: pointer;
}

.cell {
  width: var(--cell-size, 5px);
  height: var(--cell-size, 5px);
  background: var(--cell-empty);
  border-radius: 1.5px;
  transition: background .18s var(--ease);
}
.cell.lit {
  background: var(--cat-color, var(--text-1));
  opacity: var(--lit-opacity, 0.82);
  box-shadow: 0 0 var(--glow-blur, 3px) color-mix(in srgb, var(--cat-color, white) 50%, transparent);
}
.cell.lit-2 {
  opacity: 1;
  box-shadow: 0 0 var(--glow-blur, 4px) color-mix(in srgb, var(--cat-color, white) 70%, transparent);
}
.cell.lit-3 {
  opacity: 1;
  box-shadow:
    0 0 var(--glow-blur, 5px) var(--cat-color),
    0 0 calc(var(--glow-blur, 5px) * 2) color-mix(in srgb, var(--cat-color, white) 40%, transparent);
}
/* Fresh (just-added) cells get a quick wave in */
.cell.fresh {
  animation: cellPop 480ms var(--ease) backwards;
  animation-delay: var(--d, 0ms);
}
@keyframes cellPop {
  0%   { background: var(--cell-empty); transform: scale(0.6); opacity: 0; }
  35%  { background: var(--cat-color); transform: scale(1.55); opacity: 1;
         box-shadow: 0 0 14px var(--cat-color); }
  100% { background: var(--cat-color); transform: scale(1); opacity: var(--lit-opacity, 0.82);
         box-shadow: 0 0 var(--glow-blur, 3px) color-mix(in srgb, var(--cat-color, white) 50%, transparent); }
}

/* Empty state */
.grid-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px;
  text-align: center; color: var(--text-3);
}
.grid-empty[hidden] { display: none; }
.grid-empty svg { color: var(--gold-soft); margin-bottom: 4px; }
.empty-title {
  font-family: var(--display); font-weight: 500; font-size: 22px;
  color: var(--text-1); margin: 0; letter-spacing: -0.01em;
}
.empty-sub { font-size: 13px; color: var(--text-3); max-width: 280px; margin: 0 0 8px; }

/* ===== Section header / category list ===== */

.category-section { display: flex; flex-direction: column; gap: 10px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px;
}
.text-button {
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--gold-soft); padding: 6px 10px;
  border-radius: var(--r-xs);
  transition: background .15s, color .15s;
}
.text-button:hover { background: var(--gold-faint); }
.text-button.small { font-size: 11px; }

.category-list { display: flex; flex-direction: column; gap: 10px; }

.cat-item {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center; gap: 12px;
  padding: 14px 16px 14px 18px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255,255,255,0.075), rgba(255,255,255,0.025));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  -webkit-backdrop-filter: var(--blur-sm);
          backdrop-filter: var(--blur-sm);
  box-shadow: var(--shadow-glass-soft);
  cursor: pointer;
  overflow: hidden;
  transition: transform .25s var(--ease), background .2s var(--ease), border-color .2s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.cat-item::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg,
    var(--cat-color, var(--gold)),
    color-mix(in srgb, var(--cat-color, var(--gold)) 30%, transparent));
  box-shadow: 0 0 14px var(--cat-color, var(--gold));
}
.cat-item:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.04));
  border-color: var(--line-3);
}
.cat-item:active { transform: scale(0.99); }

.cat-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--cat-color, var(--gold));
  box-shadow:
    0 0 18px var(--cat-color, var(--gold)),
    0 0 0 1px rgba(255,255,255,0.12) inset,
    0 1px 0 rgba(255,255,255,0.4) inset;
  flex-shrink: 0;
}
.cat-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-name {
  font-family: var(--display); font-weight: 500; font-size: 18px;
  color: var(--text-1); letter-spacing: -0.005em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cat-sub {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-3);
  letter-spacing: 0.02em;
}
.cat-rank {
  font-family: var(--display); font-weight: 500; font-size: 15px;
  color: var(--cat-color, var(--gold-soft));
  text-align: right; white-space: nowrap;
  letter-spacing: 0.005em;
}
.cat-rank-sub {
  font-family: var(--mono); font-size: 9.5px; color: var(--text-3);
  text-align: right; margin-top: 2px;
}
.cat-trailing { display: flex; flex-direction: column; align-items: flex-end; }

/* ===== FAB ===== */

.fab {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 18px);
  left: 50%; transform: translateX(-50%);
  z-index: 40;
  display: flex; align-items: center; gap: 8px;
  padding: 16px 26px 16px 22px;
  border-radius: 999px;
  background:
    radial-gradient(120% 100% at 30% 20%, var(--gold-soft), var(--gold) 50%, var(--gold-deep) 100%);
  color: var(--ink);
  font-weight: 700; font-size: 14px; letter-spacing: 0.04em;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.45) inset,
    0 -1px 0 rgba(0,0,0,0.25) inset,
    0 0 0 1px rgba(255,255,255,0.12),
    0 12px 30px -8px rgba(201,169,97,0.7),
    0 0 24px -4px rgba(255,79,184,0.25);
  transition: transform .2s var(--ease), filter .2s var(--ease), box-shadow .25s var(--ease);
}
.fab:hover { filter: brightness(1.06); }
.fab:active { transform: translateX(-50%) scale(0.96); }
.fab[disabled] { opacity: 0.5; pointer-events: none; }
.fab svg { stroke: var(--ink); }

/* ===== Sheets ===== */

.sheet-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px 12px calc(var(--safe-bottom) + 12px);
  animation: overlayIn .25s var(--ease);
}
.sheet-overlay.confirm { align-items: center; padding: 12px; }
.sheet-overlay[hidden] { display: none; }

@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(5,6,12,0.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.sheet {
  position: relative;
  width: 100%; max-width: 540px;
  max-height: 88vh;
  border-radius: var(--r-xl);
  display: flex; flex-direction: column;
  padding: 6px 18px 18px;
  animation: sheetIn .35s var(--ease);
  overflow: hidden;
  background: linear-gradient(180deg,
    rgba(20, 22, 38, 0.55),
    rgba(12, 14, 24, 0.65));
  -webkit-backdrop-filter: var(--blur-lg);
          backdrop-filter: var(--blur-lg);
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  box-shadow: var(--shadow-glass);
}
.sheet.tall { min-height: 60vh; }

@keyframes sheetIn {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 44px; height: 4px; border-radius: 999px;
  background: var(--line-3);
  margin: 8px auto 4px;
  cursor: pointer;
}
.sheet-header { padding: 10px 4px 14px; display: flex; flex-direction: column; gap: 2px; }
.sheet-header.detail-header { flex-direction: row; align-items: center; justify-content: space-between; }
.detail-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sheet-body {
  overflow-y: auto;
  padding: 4px 4px 16px;
  display: flex; flex-direction: column; gap: 14px;
  -webkit-overflow-scrolling: touch;
}
.sheet-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 12px 4px 0;
  border-top: 1px solid var(--line-1);
}
.sheet-footer.between { justify-content: space-between; }
.footer-spacer-h { flex: 1; }

/* ===== Form elements ===== */

.field-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--text-3);
  display: block; margin-bottom: 2px;
}
.field-label .optional {
  font-weight: 400; letter-spacing: 0.05em; text-transform: none;
  color: var(--text-4); margin-left: 4px;
}

input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  font-size: 15px;
  color: var(--text-1);
  outline: 0;
  transition: border-color .2s var(--ease), background .2s var(--ease), box-shadow .2s var(--ease);
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
  border-color: var(--gold-soft);
  background: rgba(0, 0, 0, 0.32);
  box-shadow:
    0 0 0 3px rgba(201,169,97,0.18),
    0 0 24px -4px rgba(201,169,97,0.35);
}
input::placeholder, textarea::placeholder { color: var(--text-4); }
textarea { resize: none; min-height: 60px; }

/* Minutes stepper */
.minutes-input {
  display: grid; grid-template-columns: 56px 1fr 56px;
  gap: 8px;
}
.minutes-input input {
  text-align: center; font-family: var(--display); font-size: 32px;
  font-weight: 400; letter-spacing: 0;
  padding: 14px 0;
  -moz-appearance: textfield;
}
.minutes-input input::-webkit-outer-spin-button,
.minutes-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step-btn {
  border-radius: var(--r-sm);
  background: linear-gradient(180deg, rgba(255,255,255,0.085), rgba(255,255,255,0.025));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  font-size: 22px; font-weight: 300; color: var(--text-2);
  transition: background .15s, color .15s, transform .12s var(--ease);
  box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset, 0 2px 6px rgba(0,0,0,0.2);
}
.step-btn:hover { color: var(--text-1); }
.step-btn:active { transform: scale(0.94); background: rgba(255,255,255,0.12); color: var(--text-1); }

.quick-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-chip {
  padding: 9px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.025));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  font-family: var(--mono); font-size: 12px;
  color: var(--text-2);
  transition: all .15s var(--ease);
  box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset, 0 2px 6px rgba(0,0,0,0.2);
}
.quick-chip:hover { background: linear-gradient(180deg, rgba(255,255,255,0.11), rgba(255,255,255,0.04)); color: var(--text-1); }
.quick-chip.active {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold) 80%, var(--gold-deep));
  color: var(--ink);
  border-color: rgba(201,169,97,0.55);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.4) inset,
    0 0 0 3px rgba(201,169,97,0.18),
    0 6px 16px -6px rgba(201,169,97,0.6);
}

/* Chip row (category select) */
.chip-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 120px; overflow-y: auto;
  padding: 2px;
}
.cat-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px 9px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.025));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  font-size: 13px; color: var(--text-2);
  transition: all .15s var(--ease);
}
.cat-chip .chip-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cat-color, var(--gold));
  box-shadow: 0 0 10px var(--cat-color, var(--gold)),
              0 1px 0 rgba(255,255,255,0.4) inset;
}
.cat-chip:hover { color: var(--text-1); background: linear-gradient(180deg, rgba(255,255,255,0.11), rgba(255,255,255,0.04)); }
.cat-chip.active {
  color: var(--text-1);
  background: color-mix(in srgb, var(--cat-color) 18%, rgba(255,255,255,0.05));
  border-color: color-mix(in srgb, var(--cat-color) 55%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--cat-color) 22%, transparent),
              0 1px 0 rgba(255,255,255,0.18) inset;
}
.cat-chip-empty {
  font-size: 12px; color: var(--text-3); padding: 8px 4px;
}

/* Color picker */
.color-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px;
}
.color-swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--cat-color);
  border: 2px solid transparent;
  box-shadow:
    0 0 18px var(--cat-color),
    0 0 0 1px rgba(255,255,255,0.12) inset,
    0 1px 0 rgba(255,255,255,0.4) inset;
  transition: transform .15s, border-color .15s, box-shadow .2s;
}
.color-swatch:active { transform: scale(0.92); }
.color-swatch.active {
  border-color: #FFF;
  transform: scale(1.06);
  box-shadow:
    0 0 24px var(--cat-color),
    0 0 0 2px rgba(255,255,255,0.4),
    0 0 0 5px color-mix(in srgb, var(--cat-color) 35%, transparent),
    0 1px 0 rgba(255,255,255,0.5) inset;
}
.color-swatch:focus-visible {
  outline: 2px solid var(--cat-color);
  outline-offset: 3px;
}
.custom-color-label { margin-top: 4px; }
.custom-color-row {
  display: grid; grid-template-columns: 56px 1fr; gap: 8px; align-items: center;
}
.custom-color-row input[type="color"] {
  width: 56px; height: 44px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: transparent; padding: 0; cursor: pointer;
}
.custom-color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 4px; }
.custom-color-row input[type="color"]::-webkit-color-swatch { border-radius: 6px; border: 0; }
.custom-color-row input[type="text"] { font-family: var(--mono); text-transform: uppercase; }

/* ===== Buttons ===== */
.btn {
  padding: 12px 18px;
  border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600; letter-spacing: 0.02em;
  transition: transform .15s var(--ease), background .2s var(--ease),
              border-color .2s var(--ease), color .2s var(--ease), filter .2s var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: radial-gradient(120% 100% at 30% 20%, var(--gold-soft), var(--gold) 55%, var(--gold-deep));
  color: var(--ink);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.4) inset,
    0 -1px 0 rgba(0,0,0,0.2) inset,
    0 0 0 1px rgba(255,255,255,0.1),
    0 8px 22px -10px rgba(201,169,97,0.7);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  color: var(--text-2);
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
}
.btn.ghost:hover { color: var(--text-1); background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.035)); }
.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); filter: brightness(1.05); }

.row-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  color: var(--text-1);
  font-size: 14px;
  transition: background .15s var(--ease), border-color .15s var(--ease);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset;
}
.row-btn:hover { background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.035)); border-color: var(--line-3); }
.row-btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.row-hint {
  font-family: var(--mono); font-size: 10px;
  color: var(--text-3); letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ===== Auth / sync block ===== */
.auth-block {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset;
}
.auth-block[hidden] { display: none; }
.auth-header { display: flex; flex-direction: column; gap: 4px; }
.auth-actions { display: flex; gap: 8px; justify-content: flex-end; }
.auth-actions .btn { flex: 1; }
.sync-status {
  font-family: var(--mono); font-size: 10px; padding: 1px 6px;
  border-radius: 6px; margin-left: 6px; color: var(--text-3);
}
.sync-status[data-state="syncing"] { color: var(--gold-soft); }
.sync-status[data-state="ok"]      { color: var(--aurora-mint); }
.sync-status[data-state="err"]     { color: var(--danger); }

/* ===== Setting row (toggle) ===== */
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset;
}
.setting-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.setting-label {
  font-size: 14px; color: var(--text-1); font-weight: 500;
}
.setting-hint {
  font-family: var(--mono); font-size: 10px; color: var(--text-3);
  letter-spacing: 0.04em;
}

/* Pill switch */
.switch {
  position: relative; flex-shrink: 0;
  display: inline-block;
  width: 48px; height: 28px;
  cursor: pointer;
}
.switch input {
  position: absolute; opacity: 0;
  width: 100%; height: 100%; margin: 0;
  cursor: pointer; z-index: 1;
}
.slider {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  transition: background .25s var(--ease), border-color .25s var(--ease);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
}
.slider::before {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(180deg, #FFF, #D6D2C8);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.5) inset,
    0 2px 6px rgba(0,0,0,0.4);
  transition: transform .25s var(--ease), background .25s var(--ease);
}
.switch input:checked + .slider {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold) 70%, var(--gold-deep));
  border-color: rgba(201,169,97,0.55);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.35),
    0 0 0 3px rgba(201,169,97,0.18),
    0 6px 16px -6px rgba(201,169,97,0.6);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}
.switch input:focus-visible + .slider {
  outline: 2px solid var(--gold-soft);
  outline-offset: 3px;
}

/* ===== Detail sheet ===== */
.detail-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 16px 14px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset;
}
.detail-stat { display: flex; flex-direction: column; gap: 4px; align-items: center; }

.rank-progress { display: flex; flex-direction: column; gap: 6px; }
.rank-progress-row { display: flex; justify-content: space-between; font-size: 11px; }
.rank-from { color: var(--text-3); font-family: var(--display); font-weight: 500; }
.rank-to   { color: var(--gold-soft); font-family: var(--display); font-weight: 500; }
.rank-bar {
  height: 8px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-1);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
}
.rank-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--cat-color, var(--gold)) 55%, transparent),
    var(--cat-color, var(--gold)));
  box-shadow:
    0 0 16px var(--cat-color, var(--gold)),
    0 1px 0 rgba(255,255,255,0.15) inset;
  transition: width .8s var(--ease);
}
.rank-progress-meta {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-3);
  text-align: right;
}

.session-history { display: flex; flex-direction: column; gap: 8px; }
.history-title {
  font-size: 10px; font-weight: 700; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--text-3);
  margin: 8px 0 2px;
}
.history-list { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.history-item {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.018));
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  align-items: center;
}
.history-date {
  font-family: var(--mono); font-size: 11px; color: var(--text-2);
}
.history-mins {
  font-family: var(--display); font-size: 15px; color: var(--text-1);
  font-weight: 500;
}
.history-mins .unit { font-size: 10px; color: var(--text-3); margin-left: 2px; }
.history-del {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center; color: var(--text-3);
  transition: color .15s, background .15s;
}
.history-del:hover { color: var(--danger); background: var(--danger-soft); }
.history-note {
  grid-column: 1 / -1;
  font-size: 13px; color: var(--text-3);
  font-family: var(--display); padding-top: 4px; border-top: 1px solid var(--line-1);
  margin-top: 4px;
}

/* ===== Legend ===== */
.rank-legend { padding-top: 4px; border-top: 1px solid var(--line-1); margin-top: 8px; }
.legend-list { display: flex; flex-direction: column; gap: 4px; padding: 4px 0 8px; }
.legend-list li {
  display: flex; justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--r-xs);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.018));
  border: 1px solid var(--line-1);
  font-family: var(--display); font-weight: 500; font-size: 15px;
  color: var(--text-1);
}
.legend-note {
  font-size: 13px; color: var(--text-3); font-family: var(--display);
  line-height: 1.5;
  padding: 4px 4px 0;
}

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 92px);
  transform: translateX(-50%) translateY(20px);
  padding: 14px 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(28, 32, 48, 0.7), rgba(18, 22, 36, 0.7));
  -webkit-backdrop-filter: var(--blur-md);
          backdrop-filter: var(--blur-md);
  border: 1px solid var(--line-2);
  border-top-color: var(--lip);
  color: var(--text-1);
  font-size: 13px; font-weight: 500; letter-spacing: 0.02em;
  opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
  z-index: 80;
  max-width: 84vw; text-align: center;
  box-shadow: var(--shadow-glass-soft);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Confirm dialog ===== */
.confirm-card {
  padding: 24px;
  width: calc(100% - 40px); max-width: 380px;
  border-radius: var(--r-xl);
  display: flex; flex-direction: column; gap: 10px;
  position: relative;
  animation: sheetIn .3s var(--ease);
}
.confirm-msg { font-family: var(--display); font-weight: 400; color: var(--text-2); margin: 0; font-size: 14px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }

/* ===== Misc ===== */
.footer-spacer { height: 30px; }

/* Wider screens */
@media (min-width: 720px) {
  .forge-main { max-width: 720px; margin: 0 auto; }
  .app-header { padding-left: max(12px, calc(50vw - 360px)); padding-right: max(12px, calc(50vw - 360px)); }
  .header-inner, .status-row { max-width: 720px; margin-left: auto; margin-right: auto; }
  .grid-card { min-height: 60vh; }
  .display { font-size: 28px; }
  h2.display { font-size: 30px; }
  .stat-value { font-size: 28px; }
}
@media (min-width: 1100px) {
  .forge-main { max-width: 880px; }
  .grid-card { min-height: 64vh; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.05ms !important;
  }
  .cell.fresh, .aurora-orb { animation: none !important; }
}

/* Visually hidden helper (a11y) */
.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
