:root {
  --paper: #efe6d0;
  --ink: #2a2016;
  --sepia: #6b5334;
  --amber: #c9942f;
  --amber-glow: rgba(201,148,47,0.35);
  --midnight: #14100b;
  --panel: #1c1610;
  --line: #3a2d1e;
}

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

body {
  font-family: 'Cormorant Garamond', Georgia, serif;
  background:
    radial-gradient(ellipse at 50% -10%, #2a2115 0%, transparent 60%),
    radial-gradient(ellipse at 50% 120%, #1a1510 0%, transparent 55%),
    var(--midnight);
  color: #d8c9ab;
  min-height: 100vh;
  padding: 0 0 2rem;
}

#app { max-width: 1080px; margin: 0 auto; padding: 0 1rem; }

/* ---------- Header ---------- */
#masthead {
  text-align: center;
  padding: 2.4rem 1rem 1.6rem;
  border-bottom: 1px solid var(--line);
  position: relative;
  animation: fadein 1.2s ease both;
}
.crest {
  font-size: 1.6rem;
  color: var(--amber);
  letter-spacing: 0.4em;
  margin-bottom: 0.5rem;
  text-shadow: 0 0 18px var(--amber-glow);
}
#masthead h1 {
  font-weight: 500;
  font-size: clamp(1.6rem, 5vw, 3rem);
  letter-spacing: 0.02em;
  color: #ead9b6;
  line-height: 1.05;
}
#masthead h1 .wing {
  display: block;
  font-size: 0.42em;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--amber);
  margin-top: 0.5rem;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 300;
}
.subtitle {
  font-style: italic;
  font-size: clamp(1rem, 2.4vw, 1.35rem);
  color: #b39c73;
  margin-top: 0.8rem;
  opacity: 0.9;
}

/* ---------- Layout ---------- */
main {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 2rem;
  padding: 2rem 0;
  align-items: start;
}
@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
}

/* ---------- Viewer ---------- */
.viewer-panel { animation: rise 0.9s 0.15s ease both; }
.plate-frame {
  position: relative;
  background: #efe6d0;
  padding: 14px;
  border-radius: 4px;
  box-shadow:
    0 0 0 1px #4a3a25,
    0 0 40px var(--amber-glow),
    0 20px 50px rgba(0,0,0,0.6);
  margin: 0 auto;
  max-width: 500px;
}
#canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
}
.plate-corner {
  position: absolute; width: 14px; height: 14px;
  border: 1.5px solid var(--sepia); opacity: 0.6;
}
.plate-corner.tl { top: 5px; left: 5px; border-right: none; border-bottom: none; }
.plate-corner.tr { top: 5px; right: 5px; border-left: none; border-bottom: none; }
.plate-corner.bl { bottom: 5px; left: 5px; border-right: none; border-top: none; }
.plate-corner.br { bottom: 5px; right: 5px; border-left: none; border-top: none; }

.address-line {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.75rem; margin-top: 1rem; flex-wrap: wrap;
}
#address {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: #cbb587;
  letter-spacing: 0.02em;
  flex: 1; min-width: 200px;
}
.odometer {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  color: #6f5c3c;
  margin-top: 0.5rem;
  letter-spacing: 0.05em;
  word-break: break-all;
}
.odometer span { color: var(--amber); }

/* ---------- Catalog card ---------- */
.catalog-card {
  margin-top: 1.2rem;
  padding: 1.2rem 1.3rem;
  background: linear-gradient(180deg, rgba(40,32,22,0.85), rgba(26,20,13,0.85));
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: 3px;
  min-height: 120px;
}
.catalog-loading { font-style: italic; color: #8a7550; }
.card-pattern {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--amber); margin-bottom: 0.6rem;
}
.card-body { font-size: 1.15rem; line-height: 1.4; color: #dcccab; }
.card-body strong { color: var(--amber); }
.card-filed { margin-top: 0.6rem; font-size: 1.05rem; color: #b09a72; }
.card-filed em { color: #d8c9ab; }
.card-ai {
  margin-top: 0.9rem; padding-top: 0.7rem;
  border-top: 1px dashed var(--line);
  font-style: italic; font-size: 1.1rem; color: #cbb98f;
}
.card-resolve {
  margin-bottom: 0.7rem; font-size: 1.1rem; color: var(--amber);
  font-style: italic;
}
.card-error { color: #d98b6a; font-style: italic; }

/* ---------- Controls ---------- */
.controls-panel { animation: rise 0.9s 0.3s ease both; }
.control-block {
  background: rgba(28,22,16,0.6);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem 1.1rem;
  margin-bottom: 1.1rem;
}
.block-label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: #a78955; margin-bottom: 0.7rem;
}
.nav-row { display: flex; gap: 0.6rem; margin-bottom: 0.7rem; }
.nav-btn {
  flex: 1;
  background: transparent; color: #d8c9ab;
  border: 1px solid var(--line);
  padding: 0.55rem; border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace; font-size: 0.75rem;
  cursor: pointer; transition: all 0.2s;
}
.nav-btn:hover { border-color: var(--amber); color: var(--amber); }

.big-btn {
  width: 100%;
  background: linear-gradient(180deg, #c9942f, #9a6f1f);
  color: #14100b;
  border: none; padding: 0.8rem; border-radius: 3px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.15rem; font-weight: 600; letter-spacing: 0.02em;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 18px rgba(201,148,47,0.25);
}
.big-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(201,148,47,0.4); }
.big-btn:active { transform: translateY(0); }

input[type=text] {
  width: 100%;
  background: #100c08;
  border: 1px solid var(--line);
  color: #ead9b6;
  padding: 0.6rem 0.7rem;
  border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  margin-bottom: 0.65rem;
}
input[type=text]:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber-glow); }
input::placeholder { color: #6a583b; font-family: 'Cormorant Garamond', serif; font-style: italic; font-size: 1rem; }

.minor-btn {
  width: 100%;
  background: transparent; color: #cbb587;
  border: 1px solid var(--sepia);
  padding: 0.55rem; border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace; font-size: 0.72rem;
  letter-spacing: 0.05em; cursor: pointer; transition: all 0.2s;
}
.minor-btn:hover { background: rgba(201,148,47,0.12); border-color: var(--amber); color: var(--amber); }
.minor-btn.preserve.active { background: rgba(201,148,47,0.18); color: var(--amber); border-color: var(--amber); }

.ghost-btn {
  background: transparent; border: 1px solid var(--line);
  color: #b09a72; padding: 0.35rem 0.6rem; border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace; font-size: 0.62rem;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.ghost-btn:hover { border-color: var(--amber); color: var(--amber); }

.ritual { border-left: 3px solid var(--amber); }
.ritual-hint { font-style: italic; font-size: 0.95rem; color: #9c8760; margin-bottom: 0.7rem; line-height: 1.3; }

/* ---------- Cabinet ---------- */
.cabinet { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 0.85rem; }
.cab-empty { font-style: italic; font-size: 0.9rem; color: #6a583b; }
.cab-thumb {
  width: 48px; height: 48px; border-radius: 2px;
  border: 1px solid var(--line); cursor: pointer;
  transition: all 0.2s; image-rendering: auto;
}
.cab-thumb:hover { border-color: var(--amber); transform: scale(1.08); box-shadow: 0 0 10px var(--amber-glow); }

/* ---------- Lore ---------- */
.lore {
  background: rgba(28,22,16,0.4);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.9rem 1.1rem;
}
.lore summary {
  cursor: pointer; font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem; letter-spacing: 0.15em; text-transform: uppercase;
  color: #a78955; outline: none;
}
.lore p { margin-top: 0.8rem; font-size: 1.05rem; line-height: 1.5; color: #b39c73; }
.lore strong { color: var(--amber); }
.lore .epigraph { font-style: italic; color: #8a7550; font-size: 0.98rem; border-top: 1px dashed var(--line); padding-top: 0.6rem; }

/* ---------- Footer ---------- */
footer {
  text-align: center; padding: 2rem 1rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.85rem; color: #6f5c3c; font-style: italic;
  display: flex; flex-direction: column; gap: 0.6rem; align-items: center;
}
footer a {
  color: var(--amber); text-decoration: none;
  font-family: 'IBM Plex Mono', monospace; font-size: 0.7rem;
  letter-spacing: 0.1em; border-bottom: 1px dotted var(--amber);
}
footer a:hover { color: #ead9b6; }

/* ---------- Animations ---------- */
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }