/* Moondar design system: shared tokens and components for every artboard.
   Fonts are loaded per artboard in <helmet> (Google Fonts css2 link). */

:root {
  /* Sky (Night theme, default) */
  --sky-0: #0B1020;          /* page ground */
  --sky-1: #121A30;          /* panels, sheets */
  --sky-2: #1A2440;          /* inputs, pressed rows, secondary buttons */
  --sky-3: #222D4D;          /* hover on sky-2 */
  --line: #2A3554;           /* decorative 1px dividers only */
  --earthshine: #1B2343;     /* unlit part of every moon */
  --rim: #44507A;            /* moon rim, open rounds, outlines that carry meaning (>=1.9:1) */
  --bone: #ECE7DA;           /* primary text 15.3:1 */
  --ink-2: #A6AEC6;          /* secondary text 8.6:1 */
  --ink-3: #8A93AD;          /* tertiary text 6.2:1 on sky-0, 5.0:1 on sky-2 */
  --moon: #EFD9A1;           /* THE accent: earned light, primary button, focus */
  --moon-hover: #F5E4B8;
  --moon-press: #E2C987;
  --moon-deep: #B89A5E;      /* dither midtone at the terminator */
  --on-moon: #0B1020;        /* text on moon fills 13.6:1 */
  --cloud: #A9C3D6;          /* forgiven and frozen days: hatch + reason */
  --sky-real: #C9D1E3;       /* the real astronomical moon: silver outline only */
  --scrim: rgba(5, 8, 18, 0.72);

  /* Default sphere template palette (user data in production; these are the template) */
  --s-soul: #6EE0D2;
  --s-work: #86BEE6;
  --s-money: #B8D45A;
  --s-reloc: #DA62A2;
  --s-venture: #EA8F53;
  --s-self: #9F7CF2;
  --s-health: #6FD487;
  --s-family: #F7A3B4;
  --s-people: #839CE2;

  /* Shape: one radius. Circles are reserved for celestial bodies. */
  --r: 4px;
  --r-xs: 2px;

  /* Type */
  --f-ui: 'Onest', sans-serif;
  --f-game: 'Handjet', sans-serif;
  --f-mono: 'Martian Mono', monospace;
  --f-brand: 'Unbounded', sans-serif;

  /* Motion (Emil Kowalski curves) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 280ms;
}

/* "День" light theme: always free, an accessibility choice, not a reward */
.theme-day {
  --sky-0: #F1F3F8; --sky-1: #FFFFFF; --sky-2: #E7EAF2; --sky-3: #DCE1EC; --line: #CDD3E1;
  --earthshine: #DCE1EC; --rim: #8C94AD; --bone: #151B30; --ink-2: #3D4663; --ink-3: #555E7A;
  --moon: #7A5C14; --moon-hover: #6A4F10; --moon-press: #5C440D; --moon-deep: #A88A4A; --on-moon: #FFFFFF;
  --cloud: #4F6C85; --sky-real: #5D6680;
}
/* Earned theme "Лес" (sphere level unlock) */
.theme-forest { --sky-0: #0E1712; --sky-1: #15231B; --sky-2: #1C2F23; --sky-3: #24392C; --line: #2B4033; --earthshine: #1A2A20; --rim: #4A6253; --bone: #ECF1E8; --ink-2: #A9BCAE; --ink-3: #8EA394; --moon: #F2B544; --moon-hover: #F6C76C; --moon-press: #E0A332; --moon-deep: #B98423; --on-moon: #0E1712; }
/* Earned theme "Пиксель" (sphere level unlock) */
.theme-pixel { --sky-0: #17122B; --sky-1: #1F1838; --sky-2: #2A2147; --sky-3: #342957; --line: #3A2E5C; --earthshine: #251D40; --rim: #5A4C88; --bone: #EDE6FF; --ink-2: #B8ABDB; --ink-3: #9C8FC4; --moon: #FFD866; --moon-hover: #FFE28C; --moon-press: #F2C94C; --moon-deep: #C9A33A; --on-moon: #17122B; }

/* ---------- Base ---------- */
.md-root {
  background: var(--sky-0);
  color: var(--bone);
  font-family: var(--f-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  box-sizing: border-box;
}
.md-root *, .md-root *::before, .md-root *::after { box-sizing: border-box; }
.md-root ::selection { background: rgba(239, 217, 161, 0.32); color: var(--bone); }
.md-root :focus-visible { outline: 2px solid var(--moon); outline-offset: 2px; }
.md-root a { color: var(--moon); text-underline-offset: 3px; }
.md-root * { scrollbar-width: thin; scrollbar-color: var(--rim) transparent; }
.md-root h1, .md-root h2, .md-root h3, .md-root h4, .md-root p { margin: 0; }
.md-root button { font-family: var(--f-ui); }

/* ---------- Typography ---------- */
.t-display { font: 700 40px/44px var(--f-ui); letter-spacing: -0.02em; text-wrap: balance; }
.t-h1 { font: 700 28px/34px var(--f-ui); letter-spacing: -0.01em; text-wrap: balance; }
.t-h2 { font: 600 22px/28px var(--f-ui); letter-spacing: -0.005em; }
.t-h3 { font: 600 17px/24px var(--f-ui); }
.t-body { font: 400 15px/24px var(--f-ui); }
.t-lead { font: 400 18px/28px var(--f-ui); color: var(--ink-2); }
.t-small { font: 400 13px/20px var(--f-ui); color: var(--ink-2); }
.t-caption { font: 500 12px/16px var(--f-ui); color: var(--ink-3); }
.t-label { font: 500 14px/20px var(--f-ui); color: var(--ink-2); }
.t-mono { font: 400 12px/18px var(--f-mono); }
.dim { color: var(--ink-2); }
.dimmer { color: var(--ink-3); }

/* Game voice: Handjet numerals and labels of 1-3 words, never below 20px.
   ELSH axis is semantic: 8 circle = moon and scores, 2 square = RPG sheet, 14 star = celebrations. */
.g { font-family: var(--f-game); font-weight: 600; line-height: 0.9; letter-spacing: 0.01em; font-variation-settings: "ELSH" 8, "ELGR" 1; }
.g-square { font-variation-settings: "ELSH" 2, "ELGR" 1; }
.g-star { font-variation-settings: "ELSH" 14, "ELGR" 1; }
.g-xl { font-size: 96px; }
.g-lg { font-size: 64px; }
.g-md { font-size: 40px; }
.g-sm { font-size: 28px; }
.g-xs { font-size: 20px; }

.brand-word { font-family: var(--f-brand); font-weight: 500; letter-spacing: -0.01em; }

/* ---------- Icons ---------- */
.ic { display: inline-block; flex: none; vertical-align: middle; }

/* ---------- Surfaces ---------- */
.panel { background: var(--sky-1); border-radius: var(--r); }
.well { background: var(--sky-2); border-radius: var(--r); }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ---------- Buttons: rectangles only, never pills ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border: 0; border-radius: var(--r);
  font: 500 15px/1 var(--f-ui); white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-2) ease, color var(--dur-2) ease, box-shadow var(--dur-2) ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--moon); color: var(--on-moon); }
.btn-primary:active { background: var(--moon-press); }
.btn-secondary { background: var(--sky-2); color: var(--bone); box-shadow: inset 0 0 0 1px var(--line); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-quiet { background: transparent; color: var(--moon); padding: 0 8px; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 14px; }
.btn-lg { height: 52px; padding: 0 24px; font-size: 16px; }
.btn-icon { width: 44px; padding: 0; }
.btn-sm.btn-icon { width: 36px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--moon-hover); }
  .btn-secondary:hover { background: var(--sky-3); }
  .btn-ghost:hover { background: var(--sky-2); color: var(--bone); }
  .btn-quiet:hover { color: var(--moon-hover); }
}

/* Log button: a practice you can tick. Rectangle, sphere glyph square, label, quota, tick square. */
.logbtn {
  display: grid; grid-template-columns: 32px 1fr auto 28px; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 8px 12px; border: 0; border-radius: var(--r);
  background: var(--sky-1); color: var(--bone); text-align: left; cursor: pointer;
  font: 500 15px/20px var(--f-ui);
  transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-2) ease;
}
.logbtn:active { transform: scale(0.98); }
.logbtn .sph { width: 32px; height: 32px; border-radius: var(--r); display: grid; place-items: center; color: var(--on-moon); }
.logbtn .tick { width: 28px; height: 28px; border-radius: var(--r); box-shadow: inset 0 0 0 2px var(--rim); display: grid; place-items: center; color: var(--on-moon); transition: background-color var(--dur-2) ease, box-shadow var(--dur-2) ease; }
.logbtn[aria-pressed="true"] { background: var(--sky-2); }
.logbtn[aria-pressed="true"] .tick { background: var(--moon); box-shadow: none; }
.logbtn .tick path { stroke-dasharray: 1; transition: stroke-dashoffset var(--dur-2) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .logbtn:hover { background: var(--sky-2); } }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font: 500 13px/18px var(--f-ui); color: var(--ink-2); }
.input {
  height: 44px; padding: 0 12px; border: 0; border-radius: var(--r); width: 100%;
  background: var(--sky-2); color: var(--bone); box-shadow: inset 0 0 0 1px var(--line);
  font: 400 15px/20px var(--f-ui);
  transition: box-shadow var(--dur-2) ease;
}
.input::placeholder { color: var(--ink-3); }
.input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--moon); }
.help { font: 400 12px/16px var(--f-ui); color: var(--ink-3); }
.help-note { font: 500 12px/16px var(--f-ui); color: var(--cloud); } /* validation note: calm, never red */

/* Toggle: rectangular track, square knob */
.toggle { position: relative; width: 44px; height: 26px; border: 0; padding: 0; border-radius: var(--r); background: var(--sky-3); box-shadow: inset 0 0 0 1px var(--rim); cursor: pointer; transition: background-color var(--dur-2) ease; flex: none; }
.toggle::after { content: ""; position: absolute; top: 4px; left: 4px; width: 18px; height: 18px; border-radius: var(--r-xs); background: var(--ink-2); transition: transform var(--dur-2) var(--ease-out), background-color var(--dur-2) ease; }
.toggle[aria-checked="true"] { background: var(--moon); box-shadow: none; }
.toggle[aria-checked="true"]::after { transform: translateX(18px); background: var(--on-moon); }

/* Checkbox square */
.checkbox { width: 22px; height: 22px; border-radius: var(--r-xs); box-shadow: inset 0 0 0 2px var(--rim); display: inline-grid; place-items: center; flex: none; }
.checkbox.on { background: var(--moon); box-shadow: none; color: var(--on-moon); }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--sky-2); border-radius: var(--r); position: relative; }
.seg button { position: relative; z-index: 1; height: 34px; padding: 0 14px; border: 0; border-radius: var(--r-xs); background: transparent; color: var(--ink-2); font: 500 14px/1 var(--f-ui); cursor: pointer; transition: color var(--dur-2) ease, background-color var(--dur-2) ease; }
.seg button[aria-pressed="true"] { background: var(--sky-0); color: var(--bone); }

/* Tabs */
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); }
.tab { position: relative; height: 44px; padding: 0; border: 0; background: transparent; color: var(--ink-2); font: 500 15px/1 var(--f-ui); cursor: pointer; }
.tab[aria-selected="true"] { color: var(--bone); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--moon); }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r); background: var(--sky-2); color: var(--ink-2); font: 500 13px/1 var(--f-ui); white-space: nowrap; }
.chip-moon { background: rgba(239, 217, 161, 0.14); color: var(--moon); }
.chip-cloud { color: var(--cloud); background: transparent; box-shadow: inset 0 0 0 1px var(--cloud); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: var(--r-xs); flex: none; } /* sphere swatch: a square, never a dot */

/* Forgiveness / freeze hatch ("облако"). Only on day cells, never inside a moon. */
.hatch { background-image: repeating-linear-gradient(135deg, var(--cloud) 0 1.5px, transparent 1.5px 6px); }
.hatch-half { background-image: linear-gradient(90deg, transparent 50%, var(--sky-0) 50%), repeating-linear-gradient(135deg, var(--cloud) 0 1.5px, transparent 1.5px 6px); }

/* 10-block attribute bar (Quest Log grammar) */
.blocks { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 3px; }
.blocks > span { height: 12px; border-radius: var(--r-xs); background: var(--sky-2); box-shadow: inset 0 0 0 1px var(--line); }
.blocks > span.on { box-shadow: none; }

/* Rounds ledger squares: shape-coded states */
.rnd { width: 14px; height: 14px; border-radius: var(--r-xs); flex: none; }
.rnd-won { background: var(--moon); }
.rnd-open { box-shadow: inset 0 0 0 1.5px var(--rim); }
.rnd-bonus { background: var(--moon); box-shadow: 0 0 0 2px var(--sky-0), 0 0 0 3px var(--moon); }
.rnd-cloud { box-shadow: inset 0 0 0 1.5px var(--cloud); background-image: repeating-linear-gradient(135deg, var(--cloud) 0 1px, transparent 1px 4px); }
.rnd-wait { box-shadow: inset 0 0 0 1.5px var(--ink-3); background: transparent; }

/* Stars for overflow rounds: 2x2 pixel squares in the sphere ink */
.px-star { position: absolute; width: 4px; height: 4px; }

/* Dither strip for brand surfaces (integer pixels only) */
.dither { background-image: repeating-conic-gradient(var(--moon-deep) 0 25%, transparent 0 50%); background-size: 4px 4px; }

/* Toast */
.toast { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 12px 10px 14px; border-radius: var(--r); background: var(--sky-2); color: var(--bone); box-shadow: inset 0 0 0 1px var(--rim); font: 500 14px/20px var(--f-ui); }

/* App shell */
.shell { display: flex; flex-wrap: wrap; align-items: stretch; }
.side { flex: 1 1 248px; background: var(--sky-0); border-right: 1px solid var(--line); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 32px; display: flex; flex-direction: column; gap: 24px; max-width: 1176px; width: 100%; }
.nav-item { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: var(--r); color: var(--ink-2); font: 500 14px/1 var(--f-ui); text-decoration: none; border: 0; background: transparent; width: 100%; cursor: pointer; transition: background-color var(--dur-2) ease, color var(--dur-2) ease; }
.nav-item[aria-current="page"] { background: var(--sky-1); color: var(--bone); }
.nav-item[aria-current="page"] .ic { color: var(--moon); }
@media (hover: hover) and (pointer: fine) { .nav-item:hover { color: var(--bone); background: var(--sky-1); } }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 72px; padding: 0 32px; border-bottom: 1px solid var(--line); }

/* Mobile tab bar */
.tabbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: 64px; background: var(--sky-1); border-top: 1px solid var(--line); }
.tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--ink-3); font: 500 11px/1 var(--f-ui); text-decoration: none; border: 0; background: transparent; }
.tabbar [aria-current="page"] { color: var(--moon); }

/* Skeleton loading: calm static tone, gentle opacity pulse */
.skel { background: var(--sky-2); border-radius: var(--r); animation: md-pulse 1600ms var(--ease-in-out) infinite alternate; }
@keyframes md-pulse { from { opacity: 0.55; } to { opacity: 1; } }

/* Moon terminator transition hook (scaleX on the ellipse) */
.moon-term { transform-box: fill-box; transform-origin: center; transition: transform var(--dur-3) var(--ease-in-out); }

/* XP rise label */
.xp-rise { transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  .btn:active, .logbtn:active, .day:active { transform: none; }
  .moon-term, .xp-rise, .toggle::after { transition-duration: 1ms; }
  .skel { animation: none; }
}
