/* Kidogram review panel: fonts, tokens, base, shell and shared components (DESIGN.md §10.1).
   The quiet paper look of the app: cream page, paper cards, ink text, terracotta for the main
   action, mustard for stars and word marks. Phone first (360 px); views add their own files. */

/* ---------------------------------------------------------------- fonts (OFL, see /fonts/*.txt) */

@font-face {
  font-family: 'Fraunces';
  src: url('../fonts/Fraunces-Variable.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  src: url('../fonts/Nunito-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  src: url('../fonts/Nunito-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  src: url('../fonts/Nunito-ExtraBold.ttf') format('truetype');
  font-weight: 800 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Andika';
  src: url('../fonts/Andika-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ---------------------------------------------------------------- tokens */

:root {
  --cream: #FBF5EA;
  --paper: #FFFDF8;
  --sunken: #F5EDDF;
  --hairline: #ECE2D1;
  --hairline-strong: #D6C9B3;
  --ink: #2E2A3B;
  --ink-soft: #6B6478;
  --primary: #D9714E;
  --primary-edge: #A04B2F;
  --primary-bg: #F8E1D8;
  --secondary-edge: #E2D4BC;
  --mustard: #E6B54A;
  --word-mark: rgba(230, 181, 74, .55);
  --sage: #8FAE8B;
  --dusty-blue: #7A9CC6;
  --blush: #EFB7A6;
  --ok: #4A7346;
  --ok-bg: #E3EDE1;
  --info: #3F6694;
  --info-bg: #E2EAF4;
  --warn: #8A6200;
  --warn-bg: #F8EBC8;
  --bad: #A53F28;
  --bad-bg: #F6DED6;
  --shadow: 0 2px 10px rgba(46, 42, 59, .08);
  --shadow-pop: 0 10px 30px rgba(46, 42, 59, .16), 0 2px 6px rgba(46, 42, 59, .08);
  --r-card: 16px;
  --r-btn: 14px;
  --r-scene: 20px;
  --r-sheet: 24px;
  --gutter: 20px;

  /* Panel extras (not in the app's tokens). */
  --font-ui: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-head: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-story: 'Andika', 'Segoe UI', system-ui, sans-serif;
  --topbar-h: 56px;          /* sticky view headers sit at top: var(--topbar-h) */
  --maxw: 1200px;
  --focus: var(--info);
  --star-empty: #9C8B6E;     /* outline of an empty star: 3:1 on paper */
  --danger-edge: #74291A;
  --z-sticky: 40;            /* sticky view headers, floating buttons */
  --z-top: 50;               /* the top bar */
  --z-pop: 80;               /* popovers */
  --z-sheet: 100;            /* sheets and dialogs */
  --z-toast: 120;
}
@media (min-width: 768px) {
  :root { --gutter: 32px; }
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }
html {
  background: var(--cream);
  scrollbar-gutter: stable; /* no reflow when a sheet locks the page scroll (html.is-locked) */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html.is-locked { overflow: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--cream);
  color: var(--ink);
  font: 600 16px/22px var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
  overflow-x: clip;
}
h1, h2, h3, h4, .h1, .h2, .h3 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 600;
  font-variation-settings: "SOFT" 100, "opsz" 48;
  letter-spacing: -.2px;
  color: var(--ink);
}
h1, .h1 { font-size: 28px; line-height: 34px; }
h2, .h2 { font-size: 22px; line-height: 28px; }
h3, .h3 { font-size: 18px; line-height: 23px; }
h4 { font-size: 16px; line-height: 21px; }
@media (min-width: 768px) {
  h1, .h1 { font-size: 32px; line-height: 38px; }
  h2, .h2 { font-size: 24px; line-height: 30px; }
  h3, .h3 { font-size: 20px; line-height: 25px; }
}
p { margin: 0; }
a { color: var(--primary-edge); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }
img, svg, video { max-width: 100%; }
img { display: block; height: auto; }
strong, b { font-weight: 800; }
hr { border: 0; border-top: 1px solid var(--hairline); margin: 16px 0; }
::selection { background: var(--word-mark); color: var(--ink); }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.noscript { padding: 24px var(--gutter); text-align: center; }

/* ---------------------------------------------------------------- text and layout helpers */

.muted { color: var(--ink-soft); }
.small { font-size: 13px; line-height: 18px; }
.lead { font-size: 17px; line-height: 24px; color: var(--ink-soft); }
.strong { font-weight: 800; }
.nowrap { white-space: nowrap; }
.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;
}
.story-text { font-family: var(--font-story); font-weight: 400; font-size: 20px; line-height: 30px; }
@media (min-width: 768px) {
  .story-text { font-size: 22px; line-height: 33px; }
}

.page {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px max(var(--gutter), env(safe-area-inset-right)) 64px max(var(--gutter), env(safe-area-inset-left));
}
.page-narrow { max-width: 720px; }
.page-head { display: grid; gap: 6px; margin-bottom: 20px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-lg { gap: 12px; }
.row-end { justify-content: flex-end; }
.row-between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }

.card {
  background: var(--paper);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
@media (max-width: 479px) {
  .card-pad { padding: 16px; }
}
.card-title { margin-bottom: 12px; }
.divider { height: 1px; background: var(--hairline); border: 0; margin: 0; }

/* A message strip at the top of a view: closed, stale, a hint. */
.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--r-card);
  background: var(--info-bg); color: var(--info);
  font-weight: 700;
}
.banner .ic { flex: none; margin-top: -1px; }
.banner-text { flex: 1 1 auto; min-width: 0; }
.banner-ok { background: var(--ok-bg); color: var(--ok); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-bad { background: var(--bad-bg); color: var(--bad); }
.banner > .icon-btn { margin: -10px -8px -10px 0; color: inherit; }

/* ---------------------------------------------------------------- icons */

.ic { display: inline-block; flex: none; vertical-align: middle; overflow: visible; }
.ic .icb-f { fill: var(--ic-b, var(--ic-acc, var(--primary))); }
.ic .icb-s { stroke: var(--ic-b, var(--ic-acc, var(--primary))); }
/* The app's own accent per icon (KgIcons accent:). */
.ic-book, .ic-star, .ic-moon { --ic-acc: var(--mustard); }
.ic-lock, .ic-choose { --ic-acc: var(--sage); }
.ic-language, .ic-download { --ic-acc: var(--dusty-blue); }

/* ---------------------------------------------------------------- buttons (PressButton) */

.btn {
  --face: var(--paper);
  --edge: var(--secondary-edge);
  --fg: var(--ink);
  --border: var(--secondary-edge);
  position: relative;
  display: inline-flex;
  flex-direction: column;
  appearance: none;
  margin: 0;
  border: 0;
  padding: 0 0 4px;
  background: none;
  border-radius: var(--r-btn);
  font: 800 18px/1.1 var(--font-ui);
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  max-width: 100%;
  vertical-align: middle;
}
.btn::before {
  content: '';
  position: absolute;
  inset: 4px 0 0;
  border-radius: var(--r-btn);
  background: var(--edge);
}
.btn-face {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 22px;
  border-radius: var(--r-btn);
  background: var(--face);
  color: var(--fg);
  box-shadow: inset 0 0 0 1.5px var(--border);
  transition: transform 150ms ease-out;
}
.btn-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn:active:not(:disabled):not([aria-disabled="true"]) .btn-face { transform: translateY(3px); }
.btn:hover:not(:disabled) { color: var(--fg); }
.btn:focus-visible { outline-offset: 3px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: default; }
.btn.is-busy { opacity: .75; cursor: progress; }
.btn.is-busy .btn-face::after {
  content: '';
  width: 18px; height: 18px; flex: none;
  border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: kg-spin .8s linear infinite;
}

.btn-primary {
  --face: var(--primary);
  --edge: var(--primary-edge);
  --fg: #FFFFFF;
  --border: transparent;
  --ic-b: var(--primary-bg);
}
.btn-danger {
  --face: var(--bad);
  --edge: var(--danger-edge);
  --fg: #FFFFFF;
  --border: transparent;
  --ic-b: var(--bad-bg);
}
.btn-secondary:hover:not(:disabled) .btn-face { background: #FFFFFF; }
.btn-quiet {
  --face: transparent;
  --fg: var(--primary-edge);
  --border: transparent;
  padding: 0;
}
.btn-quiet::before { display: none; }
.btn-quiet .btn-face { min-height: 44px; min-width: 44px; padding: 0 12px; }
.btn-quiet:hover:not(:disabled) .btn-face { background: var(--sunken); }
.btn-quiet:active:not(:disabled) .btn-face { transform: none; background: var(--hairline); }
.btn-sm { font-size: 15px; }
.btn-sm .btn-face { min-height: 40px; padding: 0 16px; gap: 8px; }
.btn-quiet.btn-sm .btn-face { min-height: 44px; }
.btn-icon .btn-face { padding: 0; min-width: 48px; }
.btn-sm.btn-icon .btn-face { min-width: 40px; }
.btn-block { display: flex; width: 100%; }

.icon-btn {
  appearance: none; border: 0; margin: 0; padding: 0;
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: transparent; color: var(--ink);
  cursor: pointer; touch-action: manipulation;
}
.icon-btn:hover { background: var(--sunken); }
.icon-btn:active { background: var(--hairline); }
.icon-btn:disabled { opacity: .45; cursor: default; background: transparent; }
.icon-btn-secondary { background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--secondary-edge); }

/* ---------------------------------------------------------------- forms */

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="url"], input[type="number"], input[type="tel"], input:not([type]), select, textarea, .input {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 11px 14px;
  font: 600 16px/22px var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--hairline);
  border-radius: var(--r-btn);
  transition: border-color 150ms, box-shadow 150ms;
  appearance: none;
}
textarea { min-height: 96px; resize: vertical; }
select {
  padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 9.5 12 15l5.5-5.5' fill='none' stroke='%232E2A3B' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px 20px;
  cursor: pointer;
}
input::placeholder, textarea::placeholder { color: var(--ink-soft); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--hairline-strong); }
input:focus, select:focus, textarea:focus, .input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
[aria-invalid="true"] { border-color: var(--bad) !important; }
input[readonly], textarea[readonly] { background: var(--sunken); }
input:disabled, select:disabled, textarea:disabled { background: var(--sunken); color: var(--ink-soft); }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; accent-color: var(--primary-edge); margin: 0; }
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }

.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-weight: 800; font-size: 15px; line-height: 20px; }
.field-opt { font-weight: 600; color: var(--ink-soft); }
.field-hint { font-size: 14px; line-height: 19px; color: var(--ink-soft); }
.field-error { font-size: 14px; line-height: 19px; font-weight: 700; color: var(--bad); }
.form-error {
  padding: 10px 14px; border-radius: 12px;
  background: var(--bad-bg); color: var(--bad); font-weight: 700;
}

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-toggle {
  position: absolute; top: 2px; right: 2px;
  appearance: none; border: 0; margin: 0; padding: 0;
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: transparent; color: var(--ink-soft); cursor: pointer;
}
.pw-toggle:hover { color: var(--ink); background: var(--sunken); }
.pw-toggle[aria-pressed="true"] { color: var(--ink); }
.pw-eye { display: grid; place-items: center; }

/* On/off switch. */
.switch {
  appearance: none; border: 0; margin: 0; padding: 0 4px;
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 44px; min-width: 44px;
  background: transparent; color: var(--ink);
  font: 700 15px/20px var(--font-ui);
  cursor: pointer; border-radius: 12px; text-align: left;
}
.switch-track {
  position: relative; flex: none;
  width: 46px; height: 28px; border-radius: 14px;
  background: var(--hairline-strong);
  transition: background 150ms;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--paper); box-shadow: 0 1px 3px rgba(46, 42, 59, .25);
  transition: transform 150ms ease-out;
}
.switch[aria-checked="true"] .switch-track { background: var(--ok); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(18px); }
.switch:disabled { opacity: .45; cursor: default; }

/* ---------------------------------------------------------------- segmented tabs, chips, badges */

.seg {
  display: inline-flex; flex-wrap: nowrap; align-items: stretch; gap: 2px;
  max-width: 100%;
  padding: 3px; border-radius: var(--r-btn);
  background: var(--sunken);
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.seg-btn {
  appearance: none; border: 0; margin: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  flex: 1 1 auto; min-width: 44px; min-height: 44px; padding: 0 14px;
  border-radius: 11px;
  background: transparent; color: var(--ink-soft);
  font: 800 15px/1.1 var(--font-ui);
  cursor: pointer; white-space: nowrap; touch-action: manipulation;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.seg-count {
  display: inline-grid; place-items: center;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--hairline); color: var(--ink);
  font: 800 12px/1 var(--font-ui);
}
.seg-btn.on .seg-count { background: var(--primary-bg); color: var(--primary-edge); }
.seg-block { display: flex; width: 100%; }

.chip {
  appearance: none; margin: 0;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1.5px solid var(--secondary-edge); border-radius: 999px;
  background: var(--paper); color: var(--ink);
  font: 700 15px/1.1 var(--font-ui);
  cursor: pointer; white-space: nowrap; touch-action: manipulation;
}
.chip:hover { border-color: var(--hairline-strong); }
.chip[aria-pressed="true"] { background: var(--primary-bg); border-color: var(--primary); color: var(--ink); }
.chip-static {
  min-height: 28px; padding: 0 10px; cursor: default;
  border-color: transparent; background: var(--sunken); color: var(--ink-soft);
  font-size: 13px; font-weight: 700;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 24px; padding: 2px 10px; border-radius: 999px;
  background: var(--sunken); color: var(--ink-soft);
  font: 800 13px/18px var(--font-ui);
  white-space: nowrap;
}
.badge .ic { width: 16px; height: 16px; }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-primary { background: var(--primary-bg); color: var(--primary-edge); }

/* ---------------------------------------------------------------- stars */

.stars { display: inline-flex; align-items: center; flex-wrap: nowrap; }
.stars .star {
  appearance: none; border: 0; margin: 0; padding: 0;
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 12px;
  background: transparent; color: var(--ink);
  cursor: pointer; touch-action: manipulation;
  --ic-b: var(--mustard);
}
.stars-lg .star { width: 52px; height: 52px; }
.stars .star .ic { transition: transform 120ms ease-out; }
.stars .star:active .ic { transform: scale(.88); }
.stars .star:not(.on) .icb-f { fill: var(--paper); }
.stars .star:not(.on) .icb-s { stroke: var(--star-empty); }
.stars .star.pre:not(.on) .icb-f { fill: var(--warn-bg); }
.stars .star:focus-visible { outline-offset: -2px; }
.stars-ro { gap: 1px; }
.stars-ro .star { width: auto; height: auto; cursor: default; border-radius: 0; }
.stars-ro .star:not(.on) .icb-f { fill: var(--sunken); }
.stars-ro .star:not(.on) .icb-s { stroke: var(--hairline-strong); }

/* ---------------------------------------------------------------- save badge, spinner, states */

.save-badge {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; color: var(--ink-soft);
  font: 700 14px/18px var(--font-ui); white-space: nowrap;
}
.save-badge[data-state="idle"] { visibility: hidden; }
.save-badge[data-state="saved"] { color: var(--ok); }
.save-badge[data-state="error"] { color: var(--bad); --ic-b: var(--bad); }

.spinner {
  display: inline-block; flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--hairline); border-top-color: var(--primary);
  animation: kg-spin .8s linear infinite;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2.5px; }
@keyframes kg-spin { to { transform: rotate(360deg); } }
.loading-block { display: grid; place-items: center; padding: 72px 16px; }

.empty {
  display: grid; justify-items: center; gap: 12px;
  padding: 40px 16px; text-align: center; color: var(--ink-soft);
}
.empty .ic { color: var(--hairline-strong); }
.empty-text { max-width: 420px; }

.error-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 16px; border-radius: var(--r-card);
  background: var(--bad-bg); color: var(--bad); font-weight: 700;
  --ic-b: var(--bad);
}
.error-text { flex: 1 1 200px; min-width: 0; }

/* ---------------------------------------------------------------- shell: skip link, top bar */

.skip {
  position: fixed; left: 8px; top: -120px; z-index: 200;
  appearance: none; border: 0;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  background: var(--ink); color: var(--paper);
  font: 800 15px var(--font-ui); cursor: pointer;
}
.skip:focus, .skip:focus-visible { top: 8px; }

.topbar {
  position: sticky; top: 0; z-index: var(--z-top);
  height: var(--topbar-h);
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
}
.topbar-in {
  height: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  min-height: 44px; color: var(--ink); text-decoration: none;
}
.brand:hover { color: var(--ink); }
.brand-name {
  font-family: var(--font-head); font-weight: 600;
  font-variation-settings: "SOFT" 100, "opsz" 48;
  font-size: 22px; line-height: 1; letter-spacing: -.2px;
}
.brand-tag {
  display: inline-block;
  padding: 4px 8px; border-radius: 999px;
  background: var(--primary-bg); color: var(--primary-edge);
  font: 800 12px/1 var(--font-ui);
}
.nav { display: flex; align-items: center; gap: 4px; margin-left: 12px; min-width: 0; }
.nav-link {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 12px; border-radius: 12px;
  color: var(--ink-soft); text-decoration: none;
  font: 800 15px/1.1 var(--font-ui); white-space: nowrap;
}
.nav-link:hover { color: var(--ink); background: var(--sunken); }
.nav-link[aria-current="page"] { color: var(--ink); background: var(--primary-bg); }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }
.me-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--sunken); color: var(--ink);
}
.me-btn:hover { color: var(--ink); background: var(--hairline); }
.me-btn[aria-current="page"] { background: var(--primary-bg); box-shadow: inset 0 0 0 2px var(--primary); }
.lang-switch-compact .seg-btn { padding: 0 8px; font-size: 14px; }

/* Phones and small tablets: the nav shows icons over short labels; nothing hides behind a menu.
   (Full-width labels need about 680 px with the owner's two links, so this goes up to 767 px.) */
@media (max-width: 767px) {
  .topbar-in {
    gap: 2px;
    padding: 0 max(8px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  }
  .brand { gap: 6px; }
  .brand-name { font-size: 19px; }
  .nav { margin-left: 2px; gap: 0; }
  .nav-link {
    flex-direction: column; justify-content: center; gap: 1px;
    min-width: 48px; padding: 3px 5px;
    font-size: 11px; line-height: 13px;
  }
  .nav-link .ic { width: 22px; height: 22px; }
  .topbar-end { gap: 4px; }
  .lang-switch-compact { padding: 2px; gap: 0; }
  .lang-switch-compact .seg-btn { min-width: 44px; min-height: 44px; padding: 0 4px; font-size: 13px; }
}
@media (max-width: 399px) {
  .topbar .brand-tag { display: none; }
}
/* Below the 360 px design width the nav labels go (still read out), so nothing overflows. */
@media (max-width: 352px) {
  .nav-label {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}

/* Short screens (landscape phones, a phone with its keyboard up): the top bar scrolls away, so the
   text keeps the room (review.css does the same for the review header). */
@media (max-height: 520px) {
  .topbar { position: static; }
}

.main { display: block; min-height: calc(100vh - var(--topbar-h)); outline: none; }
.is-bare .main { min-height: 100vh; }
.view { display: block; }
/* The waiting block after a view's root: shown after 150 ms, gone once the view draws anything. */
.view:not(:empty) + .view-wait { display: none; }
.view-wait { animation: kg-wait 0s linear 150ms both; }
@keyframes kg-wait { from { visibility: hidden; } to { visibility: visible; } }

/* ---------------------------------------------------------------- sheets and dialogs */

.layer { position: fixed; inset: 0; z-index: var(--z-sheet); display: flex; }
.layer-free { pointer-events: none; }
.layer-free .sheet { pointer-events: auto; }
.sheet-scrim {
  position: absolute; inset: 0;
  background: rgba(46, 42, 59, .38);
  opacity: 0; transition: opacity 200ms ease-out;
}
.layer.open .sheet-scrim { opacity: 1; }
.sheet {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--paper);
  box-shadow: var(--shadow-pop);
  outline: none;
}
.sheet-bottom {
  position: absolute; left: 0; right: 0;
  bottom: var(--kb, 0px);
  width: 100%; max-width: 720px; margin: 0 auto;
  max-height: min(85vh, calc(var(--vvh, 100vh) - 16px));
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(105%);
  transition: transform 240ms cubic-bezier(.2, .8, .2, 1);
}
.sheet-bottom.sheet-free { max-height: min(60vh, calc(var(--vvh, 100vh) - 16px)); border-top: 1px solid var(--hairline); }
.layer.open .sheet-bottom { transform: none; }
.layer.closing .sheet-bottom { transform: translateY(105%); transition-duration: 200ms; }
.sheet-center {
  margin: auto;
  width: min(480px, calc(100vw - 48px));
  max-height: min(85vh, 760px);
  border-radius: var(--r-sheet);
  opacity: 0; transform: translateY(8px) scale(.98);
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}
.sheet-center.sheet-wide { width: min(720px, calc(100vw - 48px)); }
.sheet-center.sheet-free { position: absolute; right: 24px; bottom: 24px; margin: 0; }
.layer.open .sheet-center { opacity: 1; transform: none; }
.layer.closing .sheet-center { opacity: 0; }
.layer.closing .sheet-scrim { opacity: 0; }
.sheet-handle {
  flex: none; width: 40px; height: 5px; margin: 8px auto 0;
  border-radius: 3px; background: var(--hairline-strong);
}
.sheet-head {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 4px 20px; min-height: 52px;
}
.sheet-center .sheet-head { padding-top: 12px; }
.sheet-title { flex: 1 1 auto; min-width: 0; font-size: 20px; line-height: 25px; }
.sheet-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 20px 20px;
}
.sheet-foot {
  flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--hairline);
}
@media (max-width: 1023px) {
  .sheet-foot .btn { flex: 1 1 0; min-width: 120px; }
}
.confirm-body { color: var(--ink-soft); }

/* Popover (wide screens only; narrow screens get a sheet). */
.layer-pop { position: absolute; top: 0; left: 0; width: 0; height: 0; z-index: var(--z-pop); }
.popover {
  position: absolute; top: 0; left: 0;
  width: min(360px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-pop);
  outline: none;
  opacity: 0; transform: translateY(4px);
  transition: opacity 140ms ease-out, transform 140ms ease-out;
}
.popover.open { opacity: 1; transform: none; }
.popover-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 6px 0 16px; min-height: 48px; }
.popover-title { flex: 1 1 auto; min-width: 0; font-size: 18px; line-height: 23px; }
.popover-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 16px 16px; }
.popover-foot {
  flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px;
  padding: 10px 16px 14px; border-top: 1px solid var(--hairline);
}

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed; left: 50%; z-index: var(--z-toast);
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(480px, calc(100vw - 32px));
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-btn);
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-pop);
  font-weight: 700; cursor: pointer;
  opacity: 0; transform: translateY(8px);
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}
.toast.in { opacity: 1; transform: none; }
.toast-text { flex: 1 1 auto; min-width: 0; }
.toast-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; --ic-b: var(--ok); }
.toast-bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; --ic-b: var(--bad); }

/* ---------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .spinner, .btn.is-busy .btn-face::after { animation: kg-spin 1.6s linear infinite !important; }
}
