:root {
  --paper: #f4ece0;
  --paper-2: #efe5d6;
  --card: #fbf6ec;
  --ink: #2a2420;
  --ink-soft: #6b6157;
  --line: #ddd0bd;
  --seal: #c0392b;
  --seal-deep: #9d2c20;
  --gold: #b08b3e;
  --shadow: 0 1px 0 rgba(255,255,255,.6), 0 12px 30px -18px rgba(60,45,30,.5);
  --radius: 14px;
}
/* ===== 3-way theme (Light/Dark/System) — base :root above = native LIGHT. Opposite (dark) WCAG-aware auto-generated (contrast-solving ink/accent vs worst-case surface). ===== */
:root[data-theme="dark"]{
  --paper: #1e1a15;
  --paper-2: #0e0c0a;
  --card: #353026;
  --ink: #c8beb7;
  --ink-soft: #a4998f;
  --line: rgba(255,255,255,0.12);
  --seal: #d96256;
  --seal-deep: #dc6053;
  --gold: #a4823a;
}












* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Gowun Dodum", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 80% -10%, #f8f1e6 0%, transparent 60%),
    radial-gradient(900px 600px at -10% 110%, #efe3d0 0%, transparent 55%),
    var(--paper);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .5;
  background-image: radial-gradient(rgba(120,95,60,.06) 1px, transparent 1px);
  background-size: 4px 4px;
}

/* Header */
.site-head {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 22px clamp(16px, 5vw, 48px);
  max-width: 920px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.seal {
  display: grid; place-items: center;
  width: 50px; height: 50px; border-radius: 10px;
  background: linear-gradient(160deg, var(--seal), var(--seal-deep));
  color: #fff; font-family: "Gowun Batang", serif; font-size: 28px; font-weight: 700;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18), 0 8px 20px -10px rgba(150,40,30,.7);
  transform: rotate(-3deg);
}
.brand-text h1 { font-family: "Gowun Batang", serif; font-size: 26px; letter-spacing: .04em; }
.brand-text p { font-size: 13px; color: var(--ink-soft); }

.fav-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--line);
  color: var(--ink); padding: 9px 14px; border-radius: 999px;
  font-family: inherit; font-size: 14px; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease;
}
.fav-btn:hover { transform: translateY(-1px); border-color: var(--gold); }
.fav-btn .star { color: var(--gold); }
.fav-count {
  background: var(--ink); color: var(--paper); border-radius: 999px;
  min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center;
  font-size: 12px;
}

/* Layout */
.wrap { position: relative; z-index: 1; max-width: 920px; margin: 0 auto; padding: 8px clamp(16px, 5vw, 48px) 60px; }

/* Modes */
.modes {
  display: flex; gap: 6px; background: var(--paper-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px;
  width: fit-content; margin: 6px auto 22px; box-shadow: var(--shadow);
}
.mode {
  border: 0; background: transparent; color: var(--ink-soft);
  font-family: inherit; font-size: 14px; padding: 9px 16px; border-radius: 999px;
  cursor: pointer; transition: color .15s ease;
}
.mode.is-active { background: var(--ink); color: var(--paper); }

/* Console */
.console {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
}
.panel { display: flex; flex-wrap: wrap; gap: 16px; flex: 1 1 320px; }
.panel[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 160px; }
.field-label { font-size: 13px; color: var(--ink-soft); }
.field-label em { font-style: normal; color: var(--gold); font-size: 12px; }
.field input, .field select {
  font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }

.actions { display: flex; gap: 10px; flex: 1 1 100%; justify-content: flex-end; }
.primary {
  font-family: "Gowun Batang", serif; font-weight: 700; font-size: 16px;
  background: linear-gradient(160deg, var(--seal), var(--seal-deep)); color: #fff;
  border: 0; border-radius: 11px; padding: 12px 26px; cursor: pointer; letter-spacing: .03em;
  box-shadow: 0 10px 22px -12px rgba(150,40,30,.8); transition: transform .12s ease, filter .12s ease;
}
.primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.primary:active { transform: translateY(0); }
.ghost {
  font-family: inherit; font-size: 14px; background: var(--paper-2);
  border: 1px solid var(--line); color: var(--ink-soft);
  border-radius: 11px; padding: 12px 18px; cursor: pointer; transition: border-color .12s ease;
}
.ghost:hover { border-color: var(--gold); color: var(--ink); }

/* Results */
.results {
  margin-top: 26px; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.name-card {
  position: relative; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 18px 16px; box-shadow: var(--shadow);
  animation: rise .4s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.name-card .name {
  font-family: "Gowun Batang", serif; font-size: 28px; font-weight: 700;
  letter-spacing: .02em; line-height: 1.2; word-break: keep-all;
}
.name-card .sub { margin-top: 4px; font-size: 14px; color: var(--ink-soft); word-break: keep-all; }
.name-card .meta { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--paper-2); color: var(--ink-soft); border: 1px solid var(--line);
}
.tag.ohaeng { color: #fff; border: 0; }
.card-tools { margin-top: 14px; display: flex; gap: 8px; }
.icon-btn {
  flex: 1; font-family: inherit; font-size: 13px; cursor: pointer;
  background: var(--paper); border: 1px solid var(--line); color: var(--ink-soft);
  border-radius: 9px; padding: 7px; transition: all .12s ease;
}
@media (pointer: coarse) { .icon-btn { min-height: 44px; } }
.icon-btn:hover { border-color: var(--gold); color: var(--ink); }
.icon-btn.is-fav { color: var(--gold); border-color: var(--gold); background: #fbf3df; }

.empty {
  grid-column: 1 / -1; text-align: center; color: var(--ink-soft);
  padding: 50px 20px; border: 1px dashed var(--line); border-radius: var(--radius);
  font-size: 15px;
}
.empty .big { font-family: "Gowun Batang", serif; font-size: 22px; color: var(--ink); display: block; margin-bottom: 6px; }

/* Favorites */
.fav-section { margin-top: 40px; }
.fav-section h2 { font-family: "Gowun Batang", serif; font-size: 20px; margin-bottom: 14px; }
.fav-section h2 span { color: var(--gold); }
.fav-list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.disclaimer { margin-top: 44px; text-align: center; font-size: 12.5px; color: var(--ink-soft); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 11px 20px; border-radius: 999px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 5;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .actions { justify-content: stretch; }
  .primary { flex: 1; }
  .name-card .name { font-size: 25px; }
}

/* Header right cluster: i18n switcher + favorites button */
.head-tools {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap;
  justify-content: flex-end;
}

/* i18n switcher theme override — match paper/ink/gold palette. */
.i18n-switch {
  --i18n-switch-bg: var(--card);
  --i18n-switch-border: var(--line);
  --i18n-switch-fg: var(--ink);
  --i18n-switch-active-bg: #fbf3df;
  --i18n-switch-active-fg: var(--seal-deep);
  --i18n-switch-menu-bg: var(--card);
  --i18n-switch-menu-border: var(--line);
  --i18n-switch-focus: var(--gold);
}

/* dark-mode override for hardcoded body gradient (refinement) */
:root[data-theme="dark"] body{ background: var(--bg); }
