/* Final Chapter — base elements and reusable components. Colours come only from themes.css tokens. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font: 400 15px/1.5 var(--font-body);
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--grain), var(--pattern);
  background-size: 180px 180px, var(--pattern-size);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s ease, color .3s ease;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--c1); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

h1, h2, h3, .h { font-family: var(--font-head); font-weight: var(--head-weight); line-height: 1.15; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hand { font-family: var(--font-hand); font-size: 1.25em; line-height: 1.1; }
.stack > * + * { margin-top: var(--gap, 14px); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.card--accent { background: var(--surface-2); }
.card { border-color: color-mix(in srgb, var(--c1) 6%, transparent); }
/* ink card: the theme's darkest colour, light text; tokens flip so everything inside follows */
.card--ink {
  --text: var(--c4); --muted: color-mix(in srgb, var(--c4) 72%, transparent);
  --primary: var(--c3); --on-primary: var(--c1);
  --surface: color-mix(in srgb, var(--c4) 14%, var(--c1)); --surface-2: color-mix(in srgb, var(--c4) 10%, var(--c1));
  --line: color-mix(in srgb, var(--c4) 16%, transparent); --line-strong: color-mix(in srgb, var(--c4) 35%, transparent);
  background: var(--c1); color: var(--text); border-color: transparent;
}
.card-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.card-title .h { font-size: 1.05rem; }
.card-title .hand { color: var(--muted); }

/* washi tape strip for decorated cards */
.tape {
  position: absolute; top: -10px; left: 50%; width: 92px; height: 22px;
  transform: translateX(-50%) rotate(-3deg);
  background: color-mix(in srgb, var(--c3) 80%, transparent);
  background-image: repeating-linear-gradient(90deg, transparent 0 6px, color-mix(in srgb, #fff 30%, transparent) 6px 9px);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--c1) 12%, transparent);
  pointer-events: none;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--primary); color: var(--on-primary);
  font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform .12s ease, background-color .2s ease, opacity .2s ease;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn--soft { background: var(--accent); color: var(--on-accent); }
.btn--sm { min-height: 34px; padding: 0 14px; font-size: .88rem; }
.btn--block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--line); }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: .85rem; font-weight: 500; cursor: pointer; user-select: none;
}
.chip[aria-pressed="true"], .chip.is-on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot, var(--c2)); flex: none; }

/* ---------- form fields ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--muted); }
.input {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: 14px;
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--c1); }

/* ---------- progress bar ---------- */
.bar { position: relative; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; width: var(--p, 0%); background: var(--bar, var(--c1)); border-radius: inherit; transition: width .4s ease; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in srgb, var(--c1) 40%, transparent);
  animation: fade-in .18s ease;
}
.sheet {
  position: fixed; z-index: 61; left: 0; right: 0; bottom: 0;
  max-height: 88dvh; overflow: auto;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  background: var(--bg); background-image: var(--grain);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px -10px color-mix(in srgb, var(--c1) 40%, transparent);
  animation: sheet-up .24s cubic-bezier(.2, .9, .3, 1.05);
}
.sheet-grip { width: 42px; height: 5px; border-radius: 9px; background: var(--line-strong); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head .h { font-size: 1.15rem; flex: 1; }
@media (min-width: 900px) {
  .sheet { left: 50%; right: auto; bottom: 50%; width: min(520px, 92vw); transform: translate(-50%, 50%); border-radius: 22px; animation: fade-in .18s ease; }
  .sheet-grip { display: none; }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 80; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 16px; border-radius: 14px;
  background: var(--primary); color: var(--on-primary); font-weight: 500; text-align: center;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { .toast { bottom: 28px; } }

/* ---------- needs bars (character) ---------- */
.needs { display: grid; gap: 4px; }
.need { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 6px; font-size: .78rem; }
.need .bar { height: 6px; }
.need--low .bar > i { background: #C2413B; }
.needs--mini { width: 54px; gap: 3px; }
.needs--mini .need { grid-template-columns: 1fr; }
.needs--mini .need-ico { display: none; }
.needs--mini .bar { height: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
