:root {
  --bg: #151312;
  --bg-elevated: #1f1c1a;
  --bg-soft: #282421;
  --border: #38312c;
  --text: #ece4d5;
  --text-muted: #a89c8e;
  --accent: #c94a38;
  --accent-soft: rgba(201, 74, 56, 0.16);
  --gold: #c89d54;
  --gold-soft: rgba(200, 157, 84, 0.15);
  --plate-bg: #efe7d6;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font-serif: "Noto Serif KR", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-sans: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --base-size: 15px;
}

:root[data-theme="light"] {
  --bg: #f4eee1;
  --bg-elevated: #fbf7ee;
  --bg-soft: #ebe2cf;
  --border: #d5c7ae;
  --text: #1f1a17;
  --text-muted: #65584d;
  --accent: #8f241e;
  --accent-soft: rgba(143, 36, 30, 0.11);
  --gold: #87632d;
  --gold-soft: rgba(135, 99, 45, 0.14);
  --plate-bg: #faf5ea;
  --shadow: 0 10px 26px rgba(45, 32, 18, 0.12);
}

:root[data-fontsize="large"] {
  --base-size: 17px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--base-size);
  line-height: 1.6;
}

.app {
  max-width: 960px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: 76px;
}

header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand-heading {
  display: flex;
  flex-direction: column;
}

.edition-tag {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  color: var(--gold);
  font-weight: 600;
}

header h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  font: inherit;
  color: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.1s ease;
}

button:hover {
  background: var(--bg-soft);
}

button:active {
  transform: scale(0.98);
}

button.primary {
  background: var(--accent);
  color: #fff8f0;
  border-color: transparent;
  font-weight: 600;
}

button.secondary {
  background: var(--bg-soft);
  font-size: 0.86rem;
}

button.help {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-weight: 700;
  color: var(--gold);
}

.ui-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

main {
  flex: 1;
  padding: 16px;
}

/* Search & Filter Controls */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
}

.search-box input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.search-box .ui-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

select.sort-select {
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
}

.category-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.category-pills::-webkit-scrollbar {
  display: none;
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  white-space: nowrap;
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.pill.active {
  background: var(--accent);
  color: #fff8f0;
  border-color: transparent;
  font-weight: 600;
}

.summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Entry List Cards */
.entry-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .entry-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

.entry-card {
  display: flex;
  gap: 14px;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.16s ease, transform 0.14s ease;
}

.entry-card:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}

.entry-thumb-wrap {
  width: 78px;
  height: 104px;
  border-radius: 8px;
  background: var(--plate-bg);
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.entry-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.entry-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.entry-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.entry-plate-no {
  font-size: 0.72rem;
  color: var(--gold);
  font-weight: 600;
}

.entry-badges {
  display: flex;
  gap: 4px;
}

.mini-badge {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--gold-soft);
  color: var(--gold);
}

.mini-badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.entry-title-ko {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.08rem;
  font-weight: 700;
}

.entry-title-fr {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.entry-rank-line {
  font-size: 0.78rem;
  color: var(--gold);
  font-weight: 500;
}

.entry-summary {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Gallery Grid */
.plate-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 540px) {
  .plate-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.plate-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.16s ease, transform 0.14s ease;
}

.plate-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.plate-frame {
  aspect-ratio: 3 / 4;
  background: var(--plate-bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.plate-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.plate-caption {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.plate-caption strong {
  font-family: var(--font-serif);
  font-size: 0.95rem;
}

.plate-caption span {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Daily Grimoire Card */
.daily-hero {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.daily-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.daily-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: stretch;
}

.daily-plate {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  background: var(--plate-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.daily-plate img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.daily-details {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.daily-details h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.5rem;
}

.domain-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0;
}

.domain-tag {
  font-size: 0.76rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.quote-box {
  margin: 8px 0 0;
  padding: 12px 14px;
  border-left: 3px solid var(--gold);
  background: var(--bg-soft);
  border-radius: 0 8px 8px 0;
  font-family: var(--font-serif);
  font-size: 0.88rem;
  font-style: italic;
  color: var(--text-muted);
}

/* Settings & Library Panels */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}

.panel h2, .panel h3 {
  margin: 0 0 10px;
  font-family: var(--font-serif);
  font-size: 1.08rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-label {
  display: flex;
  flex-direction: column;
}

.setting-label span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.segmented {
  display: inline-flex;
  background: var(--bg-soft);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.segmented button {
  border: none;
  background: transparent;
  padding: 5px 10px;
  font-size: 0.82rem;
  border-radius: 7px;
}

.segmented button.active {
  background: var(--accent);
  color: #fff8f0;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: 14px;
}

/* Bottom Navigation */
nav[aria-label="주 메뉴"] {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg-elevated) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}

nav[aria-label="주 메뉴"] button {
  flex-direction: column;
  gap: 3px;
  border: none;
  background: transparent;
  padding: 6px 2px;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-radius: 8px;
}

nav[aria-label="주 메뉴"] button.active {
  color: var(--gold);
  font-weight: 600;
}

/* Modal Dialog */
dialog#modal {
  width: min(94vw, 640px);
  max-height: 88dvh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog#modal::backdrop {
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(3px);
}

.modal-inner {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 88dvh;
  overflow-y: auto;
}

.modal-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.modal-top h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
}

.modal-detail-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 520px) {
  .modal-detail-grid {
    flex-direction: row;
    align-items: flex-start;
  }
}

.modal-plate-box {
  width: 170px;
  height: 225px;
  margin: 0 auto;
  background: var(--plate-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-plate-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.note-editor {
  width: 100%;
  min-height: 86px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Full-Page Entry Detail View */
.entry-detail-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 4px;
}

.detail-back-btn {
  font-weight: 600;
  color: var(--gold);
  border-color: var(--gold);
  background: var(--bg-elevated);
  padding: 8px 14px;
}

.detail-top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: var(--shadow);
}

@media (min-width: 680px) {
  .detail-card {
    padding: 32px 34px;
  }
}

.detail-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.detail-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.detail-title-ko {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.25;
}

@media (min-width: 680px) {
  .detail-title-ko {
    font-size: 2.2rem;
  }
}

.detail-title-fr {
  font-size: 0.94rem;
  color: var(--text-muted);
}

.detail-rank-line {
  font-size: 0.96rem;
  color: var(--gold);
  font-weight: 600;
}

.detail-plate-showcase {
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.detail-plate-frame {
  width: 100%;
  max-width: 540px;
  max-height: 640px;
  aspect-ratio: 3 / 4;
  background: var(--plate-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.detail-plate-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.detail-plate-showcase figcaption {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.detail-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.detail-appearance-box {
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.detail-appearance-box strong {
  display: block;
  font-size: 0.84rem;
  color: var(--gold);
  margin-bottom: 4px;
}

.detail-appearance-box p {
  margin: 0;
  font-size: 0.95rem;
}

.detail-translation {
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 1.06rem;
  line-height: 1.85;
  letter-spacing: -0.005em;
}

.detail-paragraph {
  margin: 0;
  word-break: keep-all;
}

.detail-french-box {
  margin: 4px 0 0;
  padding: 16px 18px;
  border-left: 4px solid var(--gold);
  background: var(--bg-soft);
  border-radius: 0 12px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-french-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.84rem;
  color: var(--gold);
}

.detail-french-box p {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.7;
  font-style: italic;
  color: var(--text);
}

.detail-french-box footer {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.detail-note-box {
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-note-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

.detail-note-header label {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 700;
}

.detail-note-header span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.detail-note-actions {
  display: flex;
  justify-content: flex-end;
}

.detail-prev-next {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

@media (min-width: 560px) {
  .detail-prev-next {
    grid-template-columns: 1fr 1fr;
  }
}

.prev-next-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  text-align: left;
}

.prev-next-btn.next {
  align-items: flex-end;
  text-align: right;
}

.prev-next-btn:hover {
  border-color: var(--gold);
}

.pn-dir {
  font-size: 0.76rem;
  color: var(--gold);
  font-weight: 600;
}

.prev-next-btn strong {
  font-family: var(--font-serif);
  font-size: 0.96rem;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#toast.show {
  opacity: 1;
}

/* A-Z Alphabet Index Bar & Monogram Badge */
.letter-pills {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.letter-pills::-webkit-scrollbar {
  display: none;
}

.letter-pill {
  min-width: 32px;
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-family: var(--font-serif);
  font-weight: 700;
  white-space: nowrap;
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.letter-pill.active {
  background: var(--gold);
  color: #181411;
  border-color: transparent;
}

.entry-monogram-wrap {
  flex-direction: column;
  background: linear-gradient(145deg, var(--bg-soft), var(--bg-elevated));
  color: var(--gold);
  gap: 2px;
}

.entry-monogram-letter {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.1;
}

.entry-monogram-page {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.load-more-btn {
  width: 100%;
  max-width: 360px;
  padding: 11px 18px;
  font-weight: 600;
  border-color: var(--gold);
  color: var(--gold);
}
