/* =================================================================
   Medi Routine — Direction A: "Botanical Apothecary / Earthy Wellness"
   Warm, organic, calm self-care ritual. Mobile-first, local-first.
   ================================================================= */

/* Self-hosted so typography never depends on a reachable CDN.
   Pretendard keeps the full Hangul block because it renders
   user-entered medicine names. */
@font-face {
  font-family: "Pretendard Variable";
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  src: url("fonts/PretendardVariable.subset.woff2") format("woff2");
}

:root {
  /* ---- Light theme tokens ---- */
  --bg-canvas: #F7F5F0;
  --bg-surface: #FFFFFF;
  --bg-surface-2: #EFECE6;
  --bg-sunken: #F2EFE9;
  --text-primary: #232B28;
  --text-muted: #6B7770;
  --brand-primary: #2A6F62;
  --brand-primary-soft: rgba(42, 111, 98, 0.10);
  --brand-primary-ring: rgba(42, 111, 98, 0.22);
  --brand-accent: #C86D51;
  --brand-accent-soft: rgba(200, 109, 81, 0.12);
  --status-taken: #3B7A57;
  --status-taken-soft: rgba(59, 122, 87, 0.12);
  --status-skipped: #D97736;
  --status-skipped-soft: rgba(217, 119, 54, 0.14);
  --status-danger: #B4472B;
  --status-danger-soft: rgba(180, 71, 43, 0.10);
  --border-subtle: rgba(42, 111, 98, 0.14);
  --border-soft: rgba(35, 43, 40, 0.08);
  --shadow-card: 0 4px 16px rgba(35, 43, 40, 0.05);
  --shadow-float: 0 10px 30px rgba(35, 43, 40, 0.10);
  --shadow-inset: inset 0 1px 3px rgba(35, 43, 40, 0.08);

  /* ---- Shared ---- */
  --radius-card: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  --font-ui: "Pretendard Variable", "Pretendard", -apple-system, BlinkMacSystemFont,
    system-ui, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", sans-serif;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg-canvas: #141816;
  --bg-surface: #1F2623;
  --bg-surface-2: #28312D;
  --bg-sunken: #1A201D;
  --text-primary: #EDEAE4;
  --text-muted: #95A39C;
  --brand-primary: #56A090;
  --brand-primary-soft: rgba(86, 160, 144, 0.16);
  --brand-primary-ring: rgba(86, 160, 144, 0.30);
  --brand-accent: #E08569;
  --brand-accent-soft: rgba(224, 133, 105, 0.16);
  --status-taken: #4E9A71;
  --status-taken-soft: rgba(78, 154, 113, 0.18);
  --status-skipped: #E68A48;
  --status-skipped-soft: rgba(230, 138, 72, 0.18);
  --status-danger: #E68A6E;
  --status-danger-soft: rgba(230, 138, 110, 0.16);
  --border-subtle: rgba(86, 160, 144, 0.22);
  --border-soft: rgba(237, 234, 228, 0.10);
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.30);
  --shadow-float: 0 12px 34px rgba(0, 0, 0, 0.45);
  --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.35);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg-canvas);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--text-primary);
  font-family: var(--font-ui);
  letter-spacing: -0.02em;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(120% 80% at 100% 0%, var(--brand-primary-soft), transparent 55%),
    radial-gradient(90% 70% at 0% 8%, var(--brand-accent-soft), transparent 48%),
    var(--bg-canvas);
  background-attachment: fixed;
}

button,
input,
summary {
  font: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: 6px;
}

h1, h2, h3, h4, p {
  margin-top: 0;
}

.display {
  letter-spacing: -0.01em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
}

/* ---------------- Shell ---------------- */
.app-shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) calc(96px + env(safe-area-inset-bottom, 0px));
  animation: enter 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0 var(--space-5);
}

.brand {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--brand-primary-soft);
  font-size: 22px;
}

.brand-text .eyebrow {
  margin: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 var(--space-1);
  color: var(--brand-primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.theme-toggle {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  background: var(--bg-surface);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-card);
  transition: transform 120ms ease-out, border-color 120ms ease-out, background-color 120ms ease-out;
}

.theme-toggle:hover {
  border-color: var(--brand-primary);
}

.theme-toggle:active {
  transform: scale(0.97);
}

.theme-toggle-icon {
  font-size: 16px;
}

/* ---------------- Views ---------------- */
.view {
  display: grid;
  gap: var(--space-4);
}

.view[hidden] {
  display: none;
}

.section-heading {
  display: flex;
  gap: var(--space-4);
  align-items: flex-end;
  justify-content: space-between;
}

.section-heading h2,
.library-header h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
}

.ghost-button {
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--brand-primary);
  background: var(--brand-primary-soft);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: transform 120ms ease-out, background-color 120ms ease-out;
}

.ghost-button:hover {
  background: var(--brand-primary-ring);
}

.ghost-button:active {
  transform: scale(0.97);
}

/* ---------------- Summary card + ring ---------------- */
.summary-card {
  display: flex;
  gap: var(--space-5);
  align-items: center;
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
}

.summary-ring {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, var(--bg-surface) 68%, transparent 69%),
    conic-gradient(var(--brand-primary) calc(var(--progress, 0) * 1%), var(--bg-surface-2) 0);
}

.summary-ring-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--brand-primary);
}

.summary-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.summary-label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-text strong {
  font-size: 30px;
  line-height: 1.15;
  font-weight: 800;
}

.summary-text span:last-child {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
}

/* ---------------- Today: slot groups ---------------- */
.today-list {
  display: grid;
  gap: var(--space-5);
}

.slot-group {
  display: grid;
  gap: var(--space-3);
}

.slot-header {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: 0 var(--space-1);
}

.slot-icon {
  font-size: 18px;
}

.slot-title {
  margin: 0;
  flex: 1;
  font-size: 18px;
  font-weight: 700;
}

.slot-progress {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  background: var(--bg-surface-2);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.dose-list {
  display: grid;
  gap: var(--space-3);
}

/* ---------------- Dose card ---------------- */
.dose-card {
  position: relative;
  display: flex;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
  transition: box-shadow 160ms ease-out, transform 160ms ease-out;
}

.dose-rail {
  flex: 0 0 4px;
  background: var(--brand-primary);
  opacity: 0.55;
}

.dose-card.status-taken .dose-rail {
  background: var(--status-taken);
  opacity: 1;
}

.dose-card.status-skipped .dose-rail {
  background: var(--status-skipped);
  opacity: 1;
}

.dose-card.status-taken {
  background: linear-gradient(180deg, var(--status-taken-soft), transparent 60%), var(--bg-surface);
}

.dose-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
}

.dose-head {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  justify-content: space-between;
}

.dose-time {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.dose-time-icon {
  font-size: 15px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--brand-primary);
  background: var(--brand-primary-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.dose-card.status-taken .status-badge {
  color: var(--status-taken);
  background: var(--status-taken-soft);
}

.dose-card.status-skipped .status-badge {
  color: var(--status-skipped);
  background: var(--status-skipped-soft);
}

.dose-body {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  min-width: 0;
}

.dose-info {
  min-width: 0;
}

.med-name {
  margin: 0 0 2px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

.med-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.dose-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.status-button {
  min-height: 48px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 800;
  transition: transform 120ms ease-out, border-color 120ms ease-out, background-color 120ms ease-out;
}

.status-button.primary {
  color: var(--status-taken);
  border-color: var(--status-taken-soft);
  background: var(--status-taken-soft);
}

.status-button.danger {
  color: var(--status-skipped);
  border-color: var(--status-skipped-soft);
  background: var(--status-skipped-soft);
}

.status-button:hover {
  border-color: var(--brand-primary);
}

.status-button:active {
  transform: scale(0.98);
}

.dose-card.status-taken .status-button.primary,
.dose-card.status-skipped .status-button.danger {
  color: #FFFFFF;
}

.dose-card.status-taken .status-button.primary {
  background: var(--status-taken);
  border-color: var(--status-taken);
}

.dose-card.status-skipped .status-button.danger {
  background: var(--status-skipped);
  border-color: var(--status-skipped);
}

/* ---------------- Empty states ---------------- */
.empty-state {
  display: grid;
  gap: var(--space-2);
  place-items: center;
  min-height: 180px;
  padding: var(--space-8) var(--space-4);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-align: center;
  background: var(--bg-surface);
}

.empty-glyph {
  font-size: 30px;
}

.empty-state strong {
  color: var(--text-primary);
  font-size: 18px;
}

/* ---------------- Form ---------------- */
.medicine-form {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
}

.field {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.field label,
.field legend,
.switch-row strong {
  font-size: 14px;
  font-weight: 800;
}

.field legend {
  padding: 0;
  margin-bottom: var(--space-1);
}

.grouped-field,
.shape-field,
.unit-field {
  min-width: 0;
  padding: 0;
  border: 0;
}

.field input:not([type="radio"]):not([type="checkbox"]) {
  width: 100%;
  /* Grid and flex items default to min-width:auto, which refuses to shrink
     below content width. iOS renders input[type=time] as a wide native
     control ("오전 8:30"), so without this it overflows the card. */
  min-width: 0;
  max-width: 100%;
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--bg-sunken);
  color: var(--text-primary);
  transition: border-color 120ms ease-out;
}

.field input:not([type="radio"]):not([type="checkbox"]):focus {
  border-color: var(--brand-primary);
}

.field input[aria-invalid="true"] {
  border-color: var(--status-danger);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.time-field {
  align-content: start;
}

.time-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-2);
}

/* iOS draws input[type=time] as a native control that sizes itself to
   "오전 8:30" and ignores the declared width, pushing the field past the
   card. Dropping the native appearance makes it lay out like every other
   text field; tapping still opens the system time picker. */
.time-inputs input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  text-align: left;
}

.time-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: var(--space-2);
}

.add-time-button,
.remove-time-button {
  min-height: 48px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  color: var(--brand-primary);
  background: var(--brand-primary-soft);
  font-weight: 800;
  transition: transform 120ms ease-out, border-color 120ms ease-out;
}

.add-time-button {
  width: 100%;
  margin-top: var(--space-1);
}

.remove-time-button {
  color: var(--status-skipped);
  background: var(--status-skipped-soft);
  font-size: 20px;
}

.add-time-button:hover,
.remove-time-button:hover {
  border-color: var(--brand-primary);
}

/* radios: visually hidden inputs */
.tile input,
.chip input,
.unit-option input,
.shape-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---- Type tile grid (Top 5) ---- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.tile {
  position: relative;
  min-width: 0;
}

.tile-ui {
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  align-content: center;
  min-height: 92px;
  padding: var(--space-3) var(--space-2);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  text-align: center;
  transition: border-color 120ms ease-out, background-color 120ms ease-out, color 120ms ease-out;
}

.tile-label {
  font-size: 12px;
  font-weight: 800;
}

.tile-glyph {
  width: 40px;
  height: 40px;
}

.tile input:checked + .tile-ui {
  border-color: var(--brand-primary);
  background: var(--brand-primary-soft);
  color: var(--text-primary);
}

.tile input:focus-visible + .tile-ui,
.chip input:focus-visible + span,
.unit-option input:focus-visible + span,
.shape-option input:focus-visible + .shape-option-ui {
  outline: 3px solid var(--brand-primary);
  outline-offset: 2px;
}

/* ---- More options accordion ---- */
.more-options {
  margin-top: var(--space-2);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--bg-sunken);
}

.more-options > summary {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 var(--space-4);
  color: var(--brand-primary);
  font-size: 13px;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
}

.more-options > summary::-webkit-details-marker {
  display: none;
}

.more-options > summary::after {
  margin-left: auto;
  content: "＋";
  font-size: 18px;
}

.more-options[open] > summary::after {
  content: "－";
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
}

.chip {
  position: relative;
  min-width: 0;
}

.chip span {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.chip input:checked + span {
  border-color: var(--brand-primary);
  background: var(--brand-primary-soft);
  color: var(--text-primary);
}

/* ---- Unit options ---- */
.unit-options {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-2);
}

.unit-option {
  position: relative;
}

.unit-option span {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 800;
}

.unit-option input:checked + span {
  border-color: var(--brand-primary);
  color: var(--text-primary);
  background: var(--brand-primary-soft);
}

/* ---- Shape options ---- */
.shape-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3) var(--space-2);
}

.shape-options--extended {
  padding: 0 var(--space-3) var(--space-3);
}

.shape-option {
  position: relative;
  min-width: 0;
}

.shape-option-ui {
  display: grid;
  gap: var(--space-1);
  justify-items: center;
  min-height: 92px;
  padding: var(--space-2);
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  transition: border-color 120ms ease-out, background-color 120ms ease-out, color 120ms ease-out;
}

.shape-option input:checked + .shape-option-ui {
  border-color: var(--brand-primary);
  color: var(--text-primary);
  background: var(--brand-primary-soft);
}

/* ---------------- Switch row ---------------- */
.switch-row {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: var(--bg-sunken);
}

.switch-row small {
  display: block;
  margin-top: var(--space-1);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.switch-row input {
  width: 24px;
  height: 24px;
  accent-color: var(--brand-primary);
}

/* ---------------- Buttons ---------------- */
.primary-button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  color: #FFFFFF;
  background: var(--brand-primary);
  font-size: 16px;
  font-weight: 800;
  box-shadow: var(--shadow-card);
  transition: transform 120ms ease-out, background-color 120ms ease-out;
}

.primary-button:hover {
  filter: brightness(1.05);
}

.primary-button:active {
  transform: scale(0.99);
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--status-danger);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 120ms ease-out;
}

.form-error.visible {
  opacity: 1;
}

/* Invalid-field hook: JS toggles .field-error on the wrapper and
   aria-invalid on the control itself. */
.field.field-error > label,
.field.field-error > legend {
  color: var(--status-danger);
}

.field.field-error input:not([type="radio"]):not([type="checkbox"]),
.field input[aria-invalid="true"] {
  border-color: var(--status-danger);
  background: var(--status-danger-soft);
}

.field-error-text {
  margin: 0;
  color: var(--status-danger);
  font-size: 13px;
  font-weight: 700;
}

.field-optional {
  margin-left: var(--space-1);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

/* ---------------- Step wizard ---------------- */
.medicine-form.wizard {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  /* dvh-aware so the footer nav parks low on short steps without a
     second scroll container fighting the mobile keyboard. */
  min-height: min(600px, calc(100dvh - 200px));
  padding-bottom: max(var(--space-4), env(safe-area-inset-bottom, 0px));
}

.wizard-head {
  display: grid;
  gap: var(--space-3);
}

.wizard-progress-row {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.wizard-progress {
  flex: 1 1 auto;
  height: 8px;
  min-width: 0;
  appearance: none;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  overflow: hidden;
}

.wizard-progress::-webkit-progress-bar {
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
}

.wizard-progress::-webkit-progress-value {
  border-radius: var(--radius-pill);
  background: var(--brand-primary);
  transition: width 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.wizard-progress::-moz-progress-bar {
  border-radius: var(--radius-pill);
  background: var(--brand-primary);
}

.wizard-step-counter {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.wizard-breadcrumbs {
  display: flex;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.wizard-breadcrumbs > li {
  flex: 1 1 0;
  min-width: 0;
}

.wizard-crumb {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text-muted);
  background: var(--bg-sunken);
  font-size: 13px;
  font-weight: 800;
  transition: color 140ms ease-out, background-color 140ms ease-out,
    border-color 140ms ease-out;
}

.wizard-crumb-index {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  background: var(--bg-surface-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.wizard-crumb-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wizard-crumb.is-done {
  color: var(--brand-primary);
  border-color: var(--border-subtle);
  background: var(--brand-primary-soft);
}

.wizard-crumb.is-done .wizard-crumb-index {
  color: #FFFFFF;
  background: var(--brand-primary);
}

.wizard-crumb[aria-current="step"] {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
  background: var(--brand-primary-soft);
}

.wizard-crumb[aria-current="step"] .wizard-crumb-index {
  color: #FFFFFF;
  background: var(--brand-primary);
}

.wizard-crumb:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.wizard-step {
  display: grid;
  gap: var(--space-5);
  align-content: start;
  min-width: 0;
  animation: step-in 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

.wizard-step[hidden] {
  display: none;
}

.wizard-step-head {
  display: grid;
  gap: var(--space-1);
}

.wizard-step-title {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
}

.wizard-step-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ---- Step 3 review card ---- */
.wizard-review {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background: var(--bg-sunken);
}

.wizard-review-title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}

.wizard-summary {
  display: grid;
  gap: var(--space-2);
  font-size: 14px;
}

.wizard-summary:empty::before {
  color: var(--text-muted);
  content: "1·2단계에서 입력한 내용이 여기에 정리됩니다.";
}

.wizard-summary dl,
.wizard-summary ul {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.wizard-summary dt,
.wizard-summary .summary-key {
  color: var(--text-muted);
  font-weight: 700;
}

.wizard-summary dd,
.wizard-summary .summary-value {
  margin: 0;
  font-weight: 800;
  text-align: right;
}

/* ---- Draft resume banner ---- */
.draft-banner {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background: var(--brand-accent-soft);
}

.draft-banner[hidden] {
  display: none;
}

.draft-banner-text {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
}

.draft-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.draft-button {
  flex: 1 1 140px;
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  color: var(--text-primary);
  background: var(--bg-surface);
  font-size: 14px;
  font-weight: 800;
  transition: filter 120ms ease-out;
}

.draft-button--primary {
  border-color: transparent;
  color: #FFFFFF;
  background: var(--brand-accent);
}

.draft-button:hover {
  filter: brightness(1.05);
}

/* ---- Pinned footer navigation ---- */
.wizard-nav {
  position: sticky;
  /* Clears the fixed bottom pill nav plus the home-indicator inset. */
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  display: grid;
  gap: var(--space-2);
  margin: auto calc(var(--space-5) * -1)
    calc(max(var(--space-4), env(safe-area-inset-bottom, 0px)) * -1);
  padding: var(--space-3) var(--space-5) max(var(--space-3), env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-soft);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--bg-surface);
}

.wizard-nav-actions {
  display: flex;
  gap: var(--space-3);
}

.wizard-button {
  flex: 1 1 auto;
  min-height: 52px;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 800;
  transition: transform 120ms ease-out, filter 120ms ease-out;
}

.wizard-button[hidden] {
  display: none;
}

.wizard-button--ghost {
  flex: 0 1 34%;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  background: var(--bg-surface);
}

.wizard-button--primary {
  color: #FFFFFF;
  background: var(--brand-primary);
  box-shadow: var(--shadow-card);
}

.wizard-button:hover {
  filter: brightness(1.05);
}

.wizard-button:active {
  transform: scale(0.99);
}

.wizard-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  filter: none;
  transform: none;
}

/* ---------------- Library (pharmacy cabinet) ---------------- */
.library-header {
  display: flex;
  gap: var(--space-3);
  align-items: baseline;
  justify-content: space-between;
  margin-top: var(--space-2);
}

.library-header span {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

.medicine-library {
  display: grid;
  gap: var(--space-3);
}

.medicine-item {
  display: flex;
  gap: var(--space-4);
  align-items: stretch;
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, var(--brand-primary-soft), transparent 40%),
    var(--bg-surface);
  box-shadow: var(--shadow-card);
}

.medicine-thumb {
  display: grid;
  flex: 0 0 56px;
  place-items: center;
  width: 56px;
  border-radius: 14px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-soft);
}

.medicine-thumb .shape-marker {
  width: 34px;
  height: 34px;
}

.medicine-detail {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: var(--space-2);
  align-content: start;
}

.medicine-head {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  justify-content: space-between;
}

.medicine-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.medicine-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.shape-label,
.time-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 800;
}

.shape-label {
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  background: var(--bg-surface-2);
}

.time-chip {
  color: var(--brand-primary);
  background: var(--brand-primary-soft);
}

.delete-button {
  min-height: 40px;
  min-width: 56px;
  padding: 0 var(--space-3);
  border: 1px solid var(--status-danger-soft);
  border-radius: var(--radius-pill);
  color: var(--status-danger);
  background: var(--status-danger-soft);
  font-size: 13px;
  font-weight: 800;
  transition: transform 120ms ease-out, background-color 120ms ease-out;
}

.delete-button:hover {
  filter: brightness(1.05);
}

.delete-button:active {
  transform: scale(0.97);
}

/* ---------------- Bottom pill nav ---------------- */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  box-shadow: var(--shadow-float);
}

.nav-item {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  min-height: 48px;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  transition: background-color 140ms ease-out, color 140ms ease-out;
}

.nav-icon {
  font-size: 16px;
}

.nav-item.is-active {
  color: #FFFFFF;
  background: var(--brand-primary);
}

/* ---------------- Dialog ---------------- */
.modal-dialog {
  width: min(400px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-float);
}

.modal-dialog::backdrop {
  background: rgba(20, 24, 22, 0.45);
  backdrop-filter: blur(2px);
}

.modal-content {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-6);
  margin: 0;
}

.modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.modal-body {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.btn-secondary,
.btn-danger {
  min-height: 48px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
  transition: transform 120ms ease-out, filter 120ms ease-out;
}

.btn-secondary {
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  background: var(--bg-surface-2);
}

.btn-danger {
  border: 0;
  color: #FFFFFF;
  background: var(--status-danger);
}

.btn-secondary:active,
.btn-danger:active {
  transform: scale(0.98);
}

.btn-danger:hover {
  filter: brightness(1.05);
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px);
  z-index: 30;
  display: flex;
  gap: var(--space-4);
  align-items: center;
  width: min(440px, calc(100% - 32px));
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  background: var(--text-primary);
  color: var(--bg-surface);
  box-shadow: var(--shadow-float);
  opacity: 0;
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}

/* Without this the author display:flex beats the UA [hidden] rule, leaving an
   invisible fixed-position toast stretched across the wizard navigation where
   it swallows every click meant for 이전/다음. */
.toast[hidden] {
  display: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast-message {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}

.toast-undo {
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: 10px;
  color: var(--text-primary);
  background: var(--bg-surface);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

/* =================================================================
   Shape markers — recoloured for the botanical palette.
   Geometry reused across dose cards, tiles, library, and the picker.
   ================================================================= */
.shape-marker {
  position: relative;
  display: inline-block;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-surface-2);
  box-shadow: var(--shadow-inset);
}

.shape-marker--round { border-radius: 50%; }

.shape-marker--oval {
  height: 22px;
  margin-block: 3px;
  border-radius: 999px;
}

.shape-marker--oblong {
  height: 18px;
  margin-block: 5px;
  border-radius: 999px;
}

.shape-marker--capsule {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--bg-surface) 0 48%, var(--brand-primary-soft) 48% 100%);
}

.shape-marker--capsule::after {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 50%;
  width: 1px;
  background: var(--border-subtle);
  content: "";
}

.shape-marker--diamond {
  width: 22px;
  height: 22px;
  margin: 3px;
  border-radius: 6px;
  transform: rotate(45deg);
}

.shape-marker--patch {
  width: 22px;
  height: 22px;
  margin: 3px;
  border-radius: 6px;
  transform: rotate(45deg);
}

.shape-marker--droplet {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.shape-marker--hexagon {
  clip-path: polygon(24% 0, 76% 0, 100% 50%, 76% 100%, 24% 100%, 0 50%);
}

.shape-marker--bottle,
.shape-marker--jar {
  width: 22px;
  height: 28px;
  border-radius: 6px 6px 5px 5px;
}

.shape-marker--cup {
  border-radius: 5px 5px 12px 12px;
}

.shape-marker--tube,
.shape-marker--syringe,
.shape-marker--dropper,
.shape-marker--strip,
.shape-marker--inhaler {
  height: 18px;
  margin-block: 5px;
  border-radius: 999px;
}

.shape-marker--blister {
  border-radius: 8px;
}

.shape-marker--powder {
  border-radius: 50%;
}

/* Larger, filled treatment inside the tiles / picker */
.tile-glyph.shape-marker,
.shape-option-ui .shape-marker {
  border: 0;
  background: radial-gradient(circle at 32% 24%, var(--brand-primary), var(--brand-primary) 30%, color-mix(in srgb, var(--brand-primary) 78%, #000 22%) 100%);
  box-shadow: inset 0 -6px 14px rgba(0, 0, 0, 0.18), 0 4px 12px var(--brand-primary-soft);
  clip-path: none;
  transform: none;
  display: grid;
  place-items: center;
}

.shape-option-ui .shape-marker {
  width: 52px;
  height: 52px;
  margin: 0;
  border-radius: 50%;
}

.tile-glyph.shape-marker::after,
.shape-option-ui .shape-marker::after {
  content: none;
}

.tile-glyph.shape-marker::before,
.shape-option-ui .shape-marker::before {
  display: block;
  width: 24px;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--bg-surface), var(--bg-surface-2));
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.22);
  content: "";
}

.shape-option-ui .shape-marker--round::before,
.shape-option-ui .shape-marker--powder::before {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.shape-option-ui .shape-marker--oval::before {
  width: 30px;
  height: 18px;
}

.shape-option-ui .shape-marker--capsule::before {
  background: linear-gradient(90deg, var(--bg-surface) 0 48%, var(--bg-surface-2) 48% 100%);
}

.shape-option-ui .shape-marker--bottle::before,
.shape-option-ui .shape-marker--jar::before {
  width: 22px;
  height: 30px;
  border-radius: 6px;
}

.shape-option-ui .shape-marker--cup::before {
  width: 28px;
  height: 22px;
  border-radius: 4px 4px 11px 11px;
}

.shape-option-ui .shape-marker--tube::before,
.shape-option-ui .shape-marker--syringe::before,
.shape-option-ui .shape-marker--dropper::before,
.shape-option-ui .shape-marker--strip::before,
.shape-option-ui .shape-marker--inhaler::before {
  width: 32px;
  height: 12px;
}

.shape-option-ui .shape-marker--diamond::before,
.shape-option-ui .shape-marker--patch::before {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  transform: rotate(45deg);
}

.shape-option-ui .shape-marker--droplet::before {
  width: 26px;
  height: 26px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.shape-option-ui .shape-marker--hexagon::before {
  width: 26px;
  height: 22px;
  clip-path: polygon(24% 0, 76% 0, 100% 50%, 76% 100%, 24% 100%, 0 50%);
}

.shape-option-ui .shape-marker--blister::before {
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

/* ---------------- Responsive ---------------- */
@media (min-width: 640px) {
  .app-shell {
    padding: var(--space-8) var(--space-6) calc(100px + env(safe-area-inset-bottom, 0px));
  }

  .field-row {
    grid-template-columns: 1fr 200px;
  }

  .tile-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .wizard-crumb {
    font-size: 14px;
  }

  .wizard-nav {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------------- Reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .wizard-step {
    animation: none !important;
  }

  .wizard-progress::-webkit-progress-value {
    transition: none !important;
  }
}

@keyframes step-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
