:root {
  color-scheme: dark;
  --navy-950: #14191d;
  --navy-900: #20282d;
  --navy-800: #2b353a;
  --navy-700: #3b484d;
  --ink: #edf0ee;
  --muted: #c2cac9;
  --faint: #8f9b9c;
  --line: #526165;
  --steel-edge: #748287;
  --teal: #7bc6c0;
  --teal-dark: #284b4b;
  --surface: #303a3e;
  --note: #29383b;
  --focus: #ffe89a;
  font-family: Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(ellipse at 80% -10%, #3c494d 0, transparent 44rem),
    linear-gradient(135deg, #171d21, var(--navy-950) 55%, #111619);
  color: var(--ink);
  font-size: clamp(14px, .95vw, 16px);
  line-height: 1.58;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 880px);
  min-height: 100dvh;
  margin: auto;
  padding: clamp(12px, 3vw, 36px);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}

.guide-card {
  width: min(100%, 780px);
  justify-self: center;
  min-height: 0;
  max-height: calc(100dvh - clamp(40px, 8vw, 100px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(106deg, rgba(255, 255, 255, .045), transparent 16%, transparent 83%, rgba(0, 0, 0, .18)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .012) 0 1px, transparent 1px 4px),
    linear-gradient(145deg, #39454a, var(--navy-900) 24%, #1a2226 100%);
  box-shadow: 0 16px 45px rgba(0, 0, 0, .34), inset 0 1px rgba(255, 255, 255, .12);
}

.card-header, .card-footer { padding: 13px clamp(14px, 2.5vw, 22px); }
.card-header { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--steel-edge); background: linear-gradient(180deg, rgba(255, 255, 255, .055), rgba(0, 0, 0, .08)); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.eyebrow { margin: 0; color: var(--teal); font-size: .82rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.kind-label { margin-inline-start: 8px; color: var(--faint); font-weight: 600; }
.card-number { white-space: nowrap; color: var(--muted); font-weight: 750; }
.icon-button, .secondary-button, .primary-button, .flow-button {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 9px 14px;
  color: var(--ink);
  background: transparent;
  font-weight: 700;
}
.icon-button:hover, .secondary-button:hover { border-color: var(--teal); background: rgba(123, 198, 192, .1); }

.card-scroll { overflow-y: auto; overscroll-behavior: contain; padding: clamp(18px, 3vw, 30px); }
.card-scroll:focus { outline: none; }
.card-key { margin: 0 0 4px; color: var(--faint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; }
h1, h2 { line-height: 1.3; }
h1 { margin: 0 0 18px; font-size: clamp(1.4rem, 4vw, 2rem); letter-spacing: -.025em; text-wrap: balance; word-break: keep-all; }
h2 { margin: 0; font-size: 1rem; }
.card-media { position: relative; aspect-ratio: 16 / 8; margin: 0 0 20px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #1a2226; }
.card-media img { width: 100%; height: 100%; object-fit: cover; object-position: center; }
.card-media [hidden] { display: none !important; }
.steps { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { position: relative; min-height: 2.4rem; padding: 6px 6px 6px 2.8rem; counter-increment: step; text-wrap: pretty; word-break: keep-all; overflow-wrap: break-word; }
.steps li::before { content: counter(step); position: absolute; inset: 6px auto auto 0; display: grid; width: 1.9rem; height: 1.9rem; place-items: center; border: 1px solid var(--teal); border-radius: 50%; color: var(--teal); font-weight: 800; font-size: .8rem; }
.notes-panel { margin-top: 20px; border-radius: 10px; }
.notes-panel { padding: 16px 18px; border-inline-start: 4px solid var(--teal); background: linear-gradient(100deg, var(--note), rgba(41, 56, 59, .7)); }
.notes-panel ul { margin: 8px 0 0; padding-inline-start: 1.2rem; }

.card-footer { border-top: 1px solid var(--steel-edge); background: linear-gradient(180deg, rgba(0, 0, 0, .1), rgba(7, 11, 13, .33)); }
.navigation-row, .flow-actions { display: grid; gap: 8px; }
.navigation-row { grid-template-columns: repeat(3, 1fr); }
.secondary-button { min-width: 0; color: var(--muted); font-size: .86rem; }
.secondary-button:disabled { opacity: .4; cursor: not-allowed; }
.flow-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }
.flow-actions > :only-child { grid-column: span 2; }
.flow-button { width: 100%; display: flex; align-items: center; gap: 9px; border-color: #668987; background: linear-gradient(104deg, #284b4b, #203d3d); box-shadow: inset 0 1px rgba(255, 255, 255, .07); text-align: start; }
.flow-button:hover { border-color: var(--teal); background: linear-gradient(104deg, #315b5b, #294c4c); }
.flow-label { flex: 1; text-wrap: pretty; word-break: keep-all; }
.shortcut-key { min-width: 1.75rem; border: 1px solid rgba(237, 240, 238, .42); border-radius: 4px; padding: 0 4px; color: var(--muted); background: rgba(0, 0, 0, .18); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .75rem; line-height: 1.55; text-align: center; }
.flow-arrow { color: var(--teal); font-size: 1.05em; }
.browse-hint { margin: 0; color: var(--faint); text-align: center; font-size: .78rem; }

dialog { width: min(94vw, 760px); max-height: min(86dvh, 820px); padding: 0; overflow: hidden; border: 1px solid var(--steel-edge); border-radius: 16px; color: var(--ink); background: linear-gradient(145deg, #303a3f, var(--navy-900)); box-shadow: 0 20px 70px rgba(0, 0, 0, .55), inset 0 1px rgba(255, 255, 255, .1); }
dialog::backdrop { background: rgba(0, 8, 13, .72); }
.dialog-header { display: flex; justify-content: space-between; gap: 12px; padding: 20px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { font-size: 1.35rem; }
.dialog-actions { display: flex; align-items: center; gap: 8px; }
.search-label { display: block; margin: 18px 20px 6px; color: var(--muted); font-size: .85rem; font-weight: 700; }
#search-input { width: calc(100% - 40px); min-height: 46px; margin: 0 20px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; color: var(--ink); background: var(--navy-950); }
.toc-content { max-height: calc(86dvh - 190px); overflow-y: auto; padding: 12px 20px 24px; }
.toc-section { margin-top: 16px; }
.toc-section h3 { margin: 0 0 6px; color: var(--teal); font-size: .9rem; }
.toc-list { display: grid; gap: 6px; padding: 0; margin: 0; list-style: none; }
.toc-item { width: 100%; min-height: 44px; border: 0; border-radius: 8px; padding: 8px 10px; color: var(--ink); background: transparent; text-align: start; }
.toc-item:hover, .toc-item[aria-current="page"] { background: var(--surface); }
.toc-item span { display: inline-block; min-width: 2.6rem; color: var(--teal); font-family: ui-monospace, monospace; font-size: .85rem; }
.toc-empty { color: var(--muted); }
.confirm-dialog { padding: 24px; }
.confirm-dialog p { color: var(--muted); }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.primary-button { border-color: #93b4b1; background: #7ba8a4; color: #102223; }
.primary-button:hover { background: #9fc5c1; }
.error-card { margin: auto; padding: 28px; border: 1px solid #a86262; border-radius: 14px; background: #351d25; }

@media (min-width: 600px) and (max-width: 900px) {
  .app-shell { width: 100%; padding: 12px; }
  .guide-card { width: 100%; max-height: calc(100dvh - 40px); }
  .card-scroll { display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr); column-gap: 20px; align-content: start; padding: 18px 22px; }
  .card-key, .card-scroll > h1 { grid-column: 1 / -1; }
  .card-scroll > h1 { margin-bottom: 14px; }
  .card-media { grid-row: 3 / span 2; margin: 0; aspect-ratio: 16 / 9; }
  .steps { grid-column: 2; grid-row: 3; }
  .notes-panel { grid-column: 2; grid-row: 4; margin-top: 14px; }
}

@media (max-width: 480px) {
  .app-shell { padding: 0; gap: 0; }
  .guide-card { max-height: calc(100dvh - 26px); border-inline: 0; border-radius: 0; }
  .card-header, .card-footer { padding: 10px 12px; }
  .card-scroll { padding: 14px 18px; }
  h1 { margin-bottom: 12px; font-size: 1.3rem; }
  .card-media { aspect-ratio: 16 / 6; margin-bottom: 12px; }
  .steps { gap: 7px; }
  .steps li { min-height: 2.15rem; padding-block: 4px; line-height: 1.48; }
  .steps li::before { inset-block-start: 4px; }
  .notes-panel { margin-top: 14px; }
  .navigation-row { grid-template-columns: 1fr 1fr; }
  #history-back { grid-column: span 2; }
  .browse-hint { padding: 3px 10px; background: var(--navy-950); }
  .dialog-header { padding: 16px; }
  .dialog-actions .secondary-button { padding-inline: 10px; }
}
