/* ============================================================================
   Akhet — pyramid simulator UI. Gold-light diorama, parchment panels,
   engraved serif display, fine hairlines, hieroglyphic accents.
   ========================================================================== */

@font-face {
  font-family: 'Cormorant Garamond';
  src: url('../fonts/cormorant-garamond-latin-500-normal.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Cormorant Garamond';
  src: url('../fonts/cormorant-garamond-latin-600-normal.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  --sand: #e8d5a8;
  --papyrus: #f0e2bc;
  --gold: #c9962e;
  --gold-bright: #e8b94a;
  --lapis: #1d3a5f;
  --teal: #2e6f6f;
  --ink: #2b2620;
  --ink2: #4a3f2e;
  --bad: #a33b2a;
  --panel: rgba(28, 22, 14, 0.82);
  --panel2: rgba(40, 32, 20, 0.92);
  --hairline: rgba(201, 150, 46, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--papyrus);
  background: #1a140c;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#scene-root { position: fixed; inset: 0; }
#scene-root.dim { filter: brightness(0.35) sepia(0.4); }
#scene-root canvas { display: block; }

/* ---------------------------------------------------------------- HUD top */
#hud-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(20,15,8,0.92), rgba(20,15,8,0.72));
  border-bottom: 1px solid var(--hairline);
  backdrop-filter: blur(6px);
}
.cartouche { display: flex; align-items: center; gap: 8px; padding: 2px 12px 2px 6px; border-right: 1px solid var(--hairline); }
.cartouche .glyph { font-size: 20px; color: var(--gold-bright); }
.cartouche .king { font-family: 'Cormorant Garamond', serif; font-size: 19px; font-weight: 600; letter-spacing: 0.06em; color: #f2e3ba; line-height: 1; }
.cartouche .era { font-size: 10px; color: rgba(240,226,188,0.55); }
.reign { display: flex; gap: 10px; align-items: baseline; font-size: 12.5px; }
.reign #r-year { font-family: 'Cormorant Garamond', serif; font-size: 16px; font-weight: 600; color: var(--gold-bright); }
.reign #r-season { color: rgba(240,226,188,0.8); }
.reign #r-decan { color: rgba(240,226,188,0.55); font-size: 11px; }
.reign #r-health { font-size: 11px; color: #9fd29f; }
.reign #r-health.aging { color: #e8c060; }
.reign #r-health.frail { color: #e08060; }

.chips { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; justify-content: center; }
.chip {
  font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: rgba(240,226,188,0.08); border: 1px solid rgba(240,226,188,0.14);
  color: rgba(240,226,188,0.8); white-space: nowrap;
}
.chip b { color: #f2e3ba; font-weight: 600; }
.chip.gold { border-color: var(--hairline); }
.chip.bad { border-color: var(--bad); color: #e8a090; }
.chip.bad b { color: #e88a70; }
.chip.granite b { color: #d88a6a; }

.controls { display: flex; gap: 4px; align-items: center; }
.controls .sep { width: 1px; height: 18px; background: var(--hairline); margin: 0 4px; }

.btn {
  font: inherit; font-size: 12px; cursor: pointer;
  background: rgba(240,226,188,0.08); color: var(--papyrus);
  border: 1px solid rgba(240,226,188,0.2); border-radius: 4px;
  padding: 5px 12px; transition: all 0.15s;
}
.btn:hover { background: rgba(240,226,188,0.16); border-color: var(--gold); }
.btn.sel { background: rgba(201,150,46,0.3); border-color: var(--gold); color: #ffe9b0; }
.btn.sm { padding: 3px 9px; font-size: 11.5px; }
.btn.primary { background: var(--gold); color: #241a08; border-color: var(--gold); font-weight: 600; }
.btn.primary:hover { background: var(--gold-bright); }
.btn.gold { background: linear-gradient(180deg, #e0b04a, #c9962e); }
.btn.warn { border-color: rgba(216,138,106,0.5); }
.btn.flash { animation: flash 0.3s; }
@keyframes flash { 50% { background: var(--bad); } }

/* ------------------------------------------------------------- side panels */
.panel {
  position: fixed; top: 52px; bottom: 120px; z-index: 15;
  width: 292px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--hairline);
  border-radius: 0 8px 8px 0; padding: 10px 12px 14px;
  backdrop-filter: blur(8px);
  scrollbar-width: thin; scrollbar-color: rgba(201,150,46,0.4) transparent;
}
#panel-left { left: 0; }
#panel-right { right: 0; border-radius: 8px 0 0 8px; }

.panel-h {
  font-family: 'Cormorant Garamond', serif; font-size: 16px; font-weight: 600;
  letter-spacing: 0.08em; color: var(--gold-bright);
  border-bottom: 1px solid var(--hairline); padding-bottom: 4px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.panel-h .pop, .panel-h .hint { font-size: 10.5px; font-family: system-ui; color: rgba(240,226,188,0.5); letter-spacing: 0; }

.workforce { display: flex; gap: 8px; font-size: 11.5px; margin-bottom: 10px; }
.workforce > div { flex: 1; background: rgba(240,226,188,0.06); border-radius: 5px; padding: 5px 7px; }
.workforce b { display: block; font-size: 13.5px; color: #ffe9b0; }

.slider-row { margin-bottom: 9px; }
.sl-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 2px; }
.sl-head b { color: var(--gold-bright); }
.sl-sub { font-size: 10px; color: rgba(240,226,188,0.45); }
input[type="range"] {
  width: 100%; height: 14px; -webkit-appearance: none; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; background: rgba(240,226,188,0.2); border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; margin-top: -5px;
  border-radius: 50%; background: var(--gold); border: 2px solid #f4e3b0;
}
input[type="range"]::-moz-range-track { height: 3px; background: rgba(240,226,188,0.2); border-radius: 2px; }
input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: var(--gold); border: 2px solid #f4e3b0; }

.gang {
  font-size: 12px; padding: 4px 6px; border-radius: 4px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.gang:hover { background: rgba(240,226,188,0.08); }
.gang .gm { font-size: 9px; color: var(--gold-bright); }
.gang .mark { margin-left: auto; font-size: 10px; color: rgba(240,226,188,0.4); font-style: italic; }

.mon-block { font-size: 12.5px; line-height: 1.5; }
.mon-stats .kv, .mon-block .kv, .card .kv {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 11.5px;
}
.kv span { color: rgba(240,226,188,0.55); }
.kv b { color: #ffe9b0; font-weight: 600; }

.meter { height: 7px; background: rgba(240,226,188,0.12); border-radius: 4px; overflow: hidden; margin: 6px 0 8px; }
.meter .fill { height: 100%; background: linear-gradient(90deg, #b08a3a, var(--gold-bright)); transition: width 0.4s; }

.chamber { display: flex; justify-content: space-between; font-size: 11.5px; padding: 3px 6px; border-radius: 4px; color: rgba(240,226,188,0.6); }
.chamber.wip { color: #f0e2bc; background: rgba(201,150,46,0.12); }
.chamber.done { color: #a8d8a0; }
.chamber b { font-weight: 600; }

.card {
  margin-top: 8px; background: var(--panel2); border: 1px solid var(--hairline);
  border-radius: 6px; padding: 10px 12px; font-size: 12px;
}
.card h4 { margin: 0 0 6px; font-family: 'Cormorant Garamond', serif; font-size: 15px; color: var(--gold-bright); }
.card .mark { font-size: 11px; color: rgba(240,226,188,0.45); font-style: italic; }
.card p { margin: 4px 0 8px; color: rgba(240,226,188,0.8); line-height: 1.45; }
.wip-note { color: #e8b94a !important; font-style: italic; }

/* ------------------------------------------------------------ bottom bar */
#hud-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: linear-gradient(0deg, rgba(20,15,8,0.94), rgba(20,15,8,0.7));
  border-top: 1px solid var(--hairline);
  max-height: 118px;
}
#forecast {
  font-size: 11px; color: rgba(240,226,188,0.55); padding: 4px 14px 2px;
  border-bottom: 1px solid rgba(201,150,46,0.15);
}
#chronicle { flex: 1; overflow: hidden; padding: 4px 14px 8px; }
.chron-title { font-family: 'Cormorant Garamond', serif; font-size: 13px; color: var(--gold-bright); letter-spacing: 0.1em; }
#chron-list { max-height: 62px; overflow-y: auto; scrollbar-width: thin; }
.entry { font-size: 11.5px; padding: 1.5px 0; color: rgba(240,226,188,0.75); animation: fadein 0.4s; }
.entry .when { color: rgba(201,150,46,0.7); font-size: 10px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.entry.crisis { color: #e8a58f; }
.entry.milestone { color: #ffe9b0; }
.entry.course { color: rgba(240,226,188,0.55); }
.entry.death { color: #e88a70; font-weight: 600; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }

/* ------------------------------------------------------------- cutaway */
#cutaway-wrap {
  position: fixed; inset: 0; z-index: 30; display: none;
  background: radial-gradient(ellipse at center, #3a2f1c, #1c1508);
  flex-direction: column;
}
#cutaway-wrap.show { display: flex; }
.cut-head { display: flex; justify-content: space-between; padding: 60px 20px 6px; }
.cut-title { font-family: 'Cormorant Garamond', serif; font-size: 20px; color: var(--gold-bright); letter-spacing: 0.06em; }
.cut-hint { font-size: 11px; color: rgba(240,226,188,0.5); align-self: end; }
#cutaway { flex: 1; width: 100%; }
#chamber-card { position: fixed; right: 16px; top: 120px; width: 260px; z-index: 31; }

/* ------------------------------------------------------------- modals */
#modal-root { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.modal-card, .setup-card {
  pointer-events: auto; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, 92vw); max-height: 86vh; overflow-y: auto;
  background: linear-gradient(180deg, #2c2416, #211a0e);
  border: 1px solid var(--gold); border-radius: 10px;
  padding: 22px 26px; box-shadow: 0 24px 80px rgba(0,0,0,0.7);
}
.modal-card.wide { width: min(680px, 94vw); }
.modal-card h2, .setup-card h1 {
  font-family: 'Cormorant Garamond', serif; margin: 4px 0 10px;
  color: #f4e3b0; font-size: 26px; font-weight: 600; letter-spacing: 0.03em;
}
.setup-card h1 { font-size: 30px; }
.setup-kicker { font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold); }
.ev-kind { font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold); }
.ev-kind.crisis { color: #e88a70; }
.ev-kind.milestone { color: #ffe9b0; }
.ev-body { font-size: 13.5px; line-height: 1.6; color: rgba(240,226,188,0.85); }
.ev-opts { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.ev-opt {
  font: inherit; text-align: left; cursor: pointer;
  background: rgba(240,226,188,0.06); color: var(--papyrus);
  border: 1px solid rgba(240,226,188,0.18); border-radius: 6px;
  padding: 9px 12px; transition: all 0.15s;
}
.ev-opt:hover { border-color: var(--gold); background: rgba(201,150,46,0.14); }
.ev-opt.current { border-color: var(--gold); background: rgba(201,150,46,0.2); }
.ev-opt b { display: block; font-size: 12.5px; }
.ev-opt span { font-size: 11px; color: rgba(240,226,188,0.6); }

/* setup wizard */
.setup { position: fixed; inset: 0; z-index: 50; background: radial-gradient(ellipse at 50% 30%, #3d3018 0%, #181206 75%); }
.setup-card { width: min(860px, 94vw); }
.setup-body .lede { font-size: 14px; line-height: 1.55; color: rgba(240,226,188,0.85); }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.choice {
  border: 1px solid rgba(240,226,188,0.16); border-radius: 8px;
  padding: 12px 14px; cursor: pointer; transition: all 0.15s;
  background: rgba(240,226,188,0.04);
}
.choice:hover { border-color: rgba(201,150,46,0.6); transform: translateY(-1px); }
.choice.sel { border-color: var(--gold); background: rgba(201,150,46,0.14); box-shadow: 0 0 0 1px var(--gold) inset; }
.choice h3 { margin: 0 0 4px; font-family: 'Cormorant Garamond', serif; font-size: 18px; color: #f4e3b0; }
.choice .sub { font-size: 11px; color: rgba(240,226,188,0.55); font-style: italic; }
.choice .era { font-size: 10.5px; color: var(--gold); margin: 2px 0 6px; }
.choice p { font-size: 12px; line-height: 1.5; color: rgba(240,226,188,0.75); margin: 6px 0 0; }
.choice ul { margin: 6px 0 0; padding-left: 16px; font-size: 11px; color: rgba(240,226,188,0.65); }
.choice .debate { font-size: 10.5px; color: #d8a86a; font-style: italic; margin-bottom: 4px; }
.choice .statline { font-size: 11px; color: var(--gold-bright); margin-top: 6px; }
.setup-nav { display: flex; justify-content: space-between; margin-top: 18px; gap: 10px; }
.setup-nav .primary { margin-left: auto; }

/* notes & help */
.notes .note { margin-bottom: 12px; font-size: 12.5px; }
.notes .note b { color: var(--gold-bright); }
.notes .note p { margin: 3px 0; line-height: 1.5; color: rgba(240,226,188,0.75); }
.help-body p { font-size: 13px; line-height: 1.6; color: rgba(240,226,188,0.8); }
.help-body b { color: #ffe9b0; }

/* ending */
.modal-card.ending { width: min(640px, 94vw); }
.modal-card.ending.complete { border-color: #ffe9b0; box-shadow: 0 0 60px rgba(232,185,74,0.35), 0 24px 80px rgba(0,0,0,0.7); }
.end-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.end-stats > div { background: rgba(240,226,188,0.06); border-radius: 6px; padding: 8px; text-align: center; }
.end-stats b { display: block; font-size: 20px; font-family: 'Cormorant Garamond', serif; color: var(--gold-bright); }
.end-stats span { font-size: 10px; color: rgba(240,226,188,0.55); }

#errlog {
  position: fixed; left: 0; bottom: 0; z-index: 99; max-width: 60vw; max-height: 30vh; overflow: auto;
  background: rgba(120,20,10,0.9); color: #ffd0c0; font: 10px monospace; padding: 6px;
}

/* ------------------------------------------------------------- mobile */
#mobile-tabs { display: none; }
@media (max-width: 860px) {
  #hud-top { flex-wrap: wrap; gap: 6px; padding: 6px 8px; }
  .cartouche { padding-right: 8px; }
  .cartouche .era { display: none; }
  .reign { font-size: 11px; gap: 6px; order: 3; width: 100%; }
  .chips { order: 4; justify-content: flex-start; }
  .controls { margin-left: auto; }

  .panel { top: auto; bottom: 52px; left: 0; right: 0; width: auto; max-height: 42vh; border-radius: 10px 10px 0 0; display: none; }
  body[data-mtab="left"] #panel-left, body[data-mtab="right"] #panel-right { display: block; }
  #hud-bottom { bottom: 44px; max-height: 96px; }
  body[data-mtab="chron"] #hud-bottom { max-height: 42vh; }
  body:not([data-mtab="chron"]) #chronicle { display: none; }
  body:not([data-mtab="chron"]) #hud-bottom { background: transparent; border-top: none; }
  #mobile-tabs {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
    background: rgba(20,15,8,0.95); border-top: 1px solid var(--hairline);
  }
  .mtab { flex: 1; font: inherit; font-size: 12px; padding: 12px; background: none; border: none; color: rgba(240,226,188,0.6); }
  .mtab.sel { color: var(--gold-bright); box-shadow: 0 -2px 0 var(--gold) inset; }
  #chamber-card { right: 8px; left: 8px; width: auto; top: auto; bottom: 120px; }
}

@media (max-width: 480px) {
  .chips .chip { font-size: 10px; padding: 2px 7px; }
  .controls .btn { padding: 3px 7px; }
}
