/* ===========================================================
   Drift — RPG Prototype
   Global / layout styles
   =========================================================== */

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

html, body {
  width: 100%;
  height: 100%;
  background: #0b0d12;
  color: #e6e9ef;
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The game viewport. Camera math is done in JS; the canvas
   itself is a fixed-size window into the world. */
#game {
  display: block;
  background: #11151d;
  image-rendering: pixelated;        /* crisp placeholder squares */
  box-shadow: 0 0 0 2px #1d2330, 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* ===========================================================
   HUD overlay
   =========================================================== */

#hud {
  position: absolute;
  top: 0;
  left: 0;
  padding: 12px 16px;
  pointer-events: none;             /* never block the canvas */
  font-variant-numeric: tabular-nums;
}

#coords {
  font-size: 16px;
  font-weight: 600;
  color: #9ad0ff;
  background: rgba(11, 13, 18, 0.6);
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-block;
}

#hint {
  margin-top: 8px;
  font-size: 12px;
  color: #6b7384;
}

#action-hint {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #ffe9a8;
  min-height: 16px;             /* avoid layout shift when empty */
}

/* Player health bar (top of the inventory panel, right side). Fill width =
   health fraction; it recolors green -> yellow (75-50%) -> red (<50%)
   as it empties (see .low / .critical in ui.js). */
#health {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #1d2330;
}
#health .health-label {
  font-size: 12px;
  font-weight: 600;
  color: #ff8f8f;
  white-space: nowrap;
}
#health .health-bar {
  flex: 1;
  height: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
#health .health-fill {
  height: 100%;
  width: 100%;
  border-radius: 6px;
  background: #5fae4a;                    /* healthy green (>75%) */
  transition: width 120ms linear, background-color 200ms ease;
}
#health .health-fill.low      { background: #e7c94a; }   /* yellow (75-50%) */
#health .health-fill.critical { background: #d8564a; }   /* red (<50%) */
#health .health-num {
  font-size: 12px;
  font-weight: 600;
  color: #cfd6e4;
  min-width: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ===========================================================
   Inventory / homestead panel
   =========================================================== */

#inventory {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 190px;
  padding: 12px 14px;
  background: rgba(11, 13, 18, 0.78);
  border: 1px solid #1d2330;
  border-radius: 8px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

#inventory h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b94a6;
  margin-bottom: 6px;
}

#inventory h2:not(:first-child) {
  margin-top: 14px;
}

/* Capacity badge (inventory / chest column headers) */
.cap {
  float: right;
  font-size: 11px;
  font-weight: 700;
  color: #9ad0ff;
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}
.cap.full { color: #ff7a7a; }

#inventory .lvl {
  color: #ffcc4d;
  letter-spacing: 0;
}

.res-list {
  list-style: none;
}

.res-list li {
  display: flex;
  align-items: center;
  font-size: 14px;
  padding: 3px 0;
  color: #e6e9ef;
}

.res-val {
  margin-left: auto;
  font-weight: 700;
  color: #9ad0ff;
}

.res-icon {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.res-icon.wood  { background: #8a5a36; }
.res-icon.money { background: #e7c450; }
.res-icon.wool  { background: #ece7da; }
.res-icon.stone { background: #7c828c; }

/* Extra inventory items, merged into the same list */
.res-icon.good { background: #6b7384; }

.goods .good-name {
  text-transform: capitalize;
}

.goods li .res-val {
  color: #9fe07f;
}

.tools-line {
  margin-top: 8px;
  font-size: 13px;
  color: #8b94a6;
}
.tools-line #tools {
  color: #e7c450;
  font-weight: 600;
}

.money-line {
  display: flex;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
  color: #c7cdd9;
  margin-bottom: 10px;
}
.money-line #inv-money {
  margin-left: 6px;
  color: #e7c450;
  font-weight: 700;
}

/* ===========================================================
   Game time / monthly cycle
   =========================================================== */

#timebar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: rgba(11, 13, 18, 0.82);
  border: 1px solid #1d2330;
  border-radius: 8px;
  z-index: 50;
  pointer-events: auto;            /* sit above the canvas for clicks */
}

#timebar .date {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

#date-main {
  font-size: 15px;
  font-weight: 700;
  color: #9ad0ff;
  white-space: nowrap;
}

#turn-count {
  font-size: 11px;
  color: #6b7384;
  font-variant-numeric: tabular-nums;
}

/* Week countdown — auto-advances when it hits zero (see js/game.js). */
#timebar .week-clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  padding: 0 4px;
  border-left: 1px solid #1d2330;
  border-right: 1px solid #1d2330;
}

.week-clock-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7384;
  white-space: nowrap;
}

#week-timer {
  font-size: 18px;
  font-weight: 700;
  color: #9ad0ff;
  font-variant-numeric: tabular-nums;
}

/* Last 10 seconds: flag the urgency. */
#week-timer.low { color: #ff7676; }

#advance-btn {
  pointer-events: auto;            /* clickable above the HUD layer */
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #0b0d12;
  background: #79d05a;
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}

#advance-btn:hover { background: #8fe06f; }
#advance-btn:disabled {
  background: #2a3140;
  color: #6b7384;
  cursor: default;
}

/* ===========================================================
   Skill progression
   =========================================================== */

#skills {
  /* Hidden for now — the skills overlay is suppressed visually while the
     markup and its updater code (buildSkillRows/updateSkillUI, skills.js)
     stay intact. Delete this `display: none` to bring the panel back. */
  display: none;

  position: absolute;
  bottom: 12px;
  left: 16px;
  width: 200px;
  padding: 10px 14px;
  background: rgba(11, 13, 18, 0.78);
  border: 1px solid #1d2330;
  border-radius: 8px;
  pointer-events: none;
}

#skills h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b94a6;
  margin-bottom: 8px;
}

#skill-list {
  list-style: none;
}

.skill {
  margin-bottom: 8px;
}

.skill-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 3px;
}

.skill-name { color: #e6e9ef; }
.skill-lvl  { color: #8b94a6; }
.skill-lvl b { color: #ffcc4d; }

.bar {
  height: 6px;
  background: #1d2330;
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4a8f3c, #79d05a);
  transition: width 0.15s ease-out;
}

.bar-fill.maxed {
  background: linear-gradient(90deg, #c79a2e, #ffcc4d);
}

/* ===========================================================
   Activity feed (tail of event_log)
   =========================================================== */

#activity {
  /* Hidden for now — the event_log still populates #event-log in the DOM (see
     eventlog.js / render); remove this line to bring the feed back. */
  display: none;
  position: absolute;
  bottom: 12px;
  right: 16px;
  width: 250px;
  padding: 10px 14px;
  background: rgba(11, 13, 18, 0.78);
  border: 1px solid #1d2330;
  border-radius: 8px;
  pointer-events: none;
}

#activity h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b94a6;
  margin-bottom: 6px;
}

#event-log {
  list-style: none;
}

#event-log li {
  font-size: 12px;
  color: #c7cdd9;
  padding: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#event-log .t {
  color: #5f6b80;
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
}

/* ===========================================================
   Business directory
   =========================================================== */

.hidden { display: none !important; }

/* ===========================================================
   On-screen touch controls (mobile only)

   Hidden by default; revealed at mobile widths OR on coarse-pointer
   (primary-touch) devices via the media query at the bottom of this block.
   The joystick reads movement, the button fires the interact action —
   both wired in js/managers/touch.js.
   =========================================================== */

#touch-controls {
  display: none;                     /* shown by the media query below */
  position: absolute;
  inset: 0;
  pointer-events: none;             /* only the controls themselves are live */
  z-index: 60;                      /* above HUD panels, below modals */
}

.touch-stick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(11, 13, 18, 0.35);
  border: 2px solid rgba(154, 208, 255, 0.35);
  pointer-events: auto;
  touch-action: none;               /* we handle the gesture ourselves */
  -webkit-user-select: none;
  user-select: none;
}

.touch-stick.active {
  background: rgba(11, 13, 18, 0.5);
  border-color: rgba(154, 208, 255, 0.6);
}

.touch-nub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(154, 208, 255, 0.55);
  border: 2px solid rgba(230, 238, 255, 0.7);
  transform: translate(-50%, -50%);
  pointer-events: none;             /* the base handles all touches */
}

.touch-action {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(34px, env(safe-area-inset-bottom));
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: rgba(121, 208, 90, 0.9);
  color: #0b0d12;
  border: 2px solid rgba(230, 255, 220, 0.7);
  font: inherit;
  font-size: 28px;
  font-weight: 700;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

.touch-action:active { background: rgba(143, 224, 111, 1); }

/* Reveal the controls on mobile-sized screens or primary-touch devices. */
@media (max-width: 820px), (pointer: coarse) {
  #touch-controls { display: block; }
}

#directory {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 11, 0.72);
  pointer-events: auto;
}

.directory-card {
  width: min(880px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: #11151d;
  border: 1px solid #2a3140;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.directory-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #1d2330;
}

.directory-card h1 {
  font-size: 18px;
  color: #e6e9ef;
}

#directory-close {
  font-size: 22px;
  line-height: 1;
  color: #8b94a6;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 6px;
}

#directory-close:hover { color: #fff; }

#directory-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.cat-group { margin-bottom: 18px; }

.cat-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8b94a6;
  margin-bottom: 8px;
  border-bottom: 1px dashed #2a3140;
  padding-bottom: 4px;
}

.cat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.biz {
  background: #161b25;
  border: 1px solid #232b3a;
  border-left-width: 4px;
  border-radius: 8px;
  padding: 12px 14px;
}

.biz.mission      { border-left-color: #79d05a; }
.biz.conventional { border-left-color: #c79a2e; }

.biz-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.biz-name {
  font-size: 15px;
  font-weight: 700;
  color: #e6e9ef;
}

.biz-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.biz.mission .biz-type      { background: rgba(121, 208, 90, 0.18); color: #9fe07f; }
.biz.conventional .biz-type { background: rgba(199, 154, 46, 0.18); color: #e7c450; }

.biz-cat {
  font-size: 11px;
  color: #6b7384;
  margin-top: 2px;
}

.biz-mission {
  font-size: 13px;
  color: #c7cdd9;
  line-height: 1.4;
  margin: 8px 0 10px;
}

.biz-prices {
  list-style: none;
  border-top: 1px solid #1d2330;
  padding-top: 8px;
}

.biz-prices li {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 2px 0;
  color: #aeb6c4;
}

.biz-prices b {
  color: #9ad0ff;
  font-variant-numeric: tabular-nums;
}

/* ===========================================================
   Purchase dialog (single business)
   =========================================================== */

#shop {
  position: absolute;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 11, 0.72);
  pointer-events: auto;
}

.shop-card {
  width: min(420px, 92vw);
  background: #11151d;
  border: 1px solid #2a3140;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

#shop-body {
  padding: 16px 18px 8px;
}

.shop-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b94a6;
  margin-top: 14px;
  margin-bottom: 2px;
}

.shop-item-name em {
  color: #6b7384;
  font-style: normal;
  font-size: 12px;
}

.shop-items {
  list-style: none;
  margin-top: 6px;
  border-top: 1px solid #1d2330;
}

.shop-items li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #161b25;
}

.shop-item-name {
  flex: 1;
  font-size: 14px;
  color: #e6e9ef;
  text-transform: capitalize;
}

.shop-item-price {
  font-size: 14px;
  font-weight: 700;
  color: #9ad0ff;
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: right;
}

.buy-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #0b0d12;
  background: #79d05a;
  border: none;
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
}

.buy-btn:hover { background: #8fe06f; }
.buy-btn:disabled {
  background: #2a3140;
  color: #6b7384;
  cursor: default;
}

.shop-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid #1d2330;
  background: #0e121a;
}

.shop-wallet { font-size: 13px; color: #aeb6c4; }
.shop-wallet b { color: #e7c450; }

#shop-leave {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #c7cdd9;
  background: #2a3140;
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
}

#shop-leave:hover { background: #353d4e; }

/* ===========================================================
   NPC dialog box
   =========================================================== */

#dialog {
  position: absolute;
  inset: 0;
  z-index: 115;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(5, 7, 11, 0.35);
  pointer-events: auto;
}

.dialog-card {
  width: min(620px, 94vw);
  margin-bottom: 48px;
  background: #11151d;
  border: 1px solid #3a4150;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: 16px 20px 14px;
}

/* Text on the left, speaker portrait on the right. */
.dialog-main {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.dialog-body { flex: 1 1 auto; min-width: 0; }

.dialog-name {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #ffb3b3;
  background: rgba(216, 58, 58, 0.16);
  border: 1px solid rgba(216, 58, 58, 0.5);
  border-radius: 6px;
  padding: 3px 10px;
  margin-bottom: 10px;
}

.dialog-text {
  font-size: 15px;
  line-height: 1.5;
  color: #e6e9ef;
  margin: 0;
  min-height: 3em;
}

/* Profile-pic frame. When the <img> is absent/broken it is hidden and the
   frame shows the speaker's initial (via data-initial) as a placeholder. */
.dialog-portrait {
  position: relative;
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  border-radius: 10px;
  border: 1px solid #3a4150;
  background: #1a1f2a;
  overflow: hidden;
}
.dialog-portrait::after {
  content: attr(data-initial);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 700;
  color: #5b6674;
}
/* The full profile sheet, positioned so one 84x84 tile shows through the
   frame's overflow:hidden clip. Size + top/left offset are set in ui.js. */
.dialog-portrait img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  z-index: 1;
  display: block;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

/* Choice buttons shown before the buy/sell screen (Chat more / Buy·Sell). */
.dialog-choices {
  display: flex;
  gap: 10px;
}
.dialog-choices button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #e6e9ef;
  background: #232a36;
  border: 1px solid #3a4150;
  border-radius: 6px;
  padding: 7px 16px;
  cursor: pointer;
}
.dialog-choices button:hover { background: #2c3444; }
.dialog-choices button.primary {
  color: #0b0d12;
  background: #e7c450;
  border-color: #e7c450;
}
.dialog-choices button.primary:hover { background: #f4d97a; }

#dialog-next {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #0b0d12;
  background: #e7c450;
  border: none;
  border-radius: 6px;
  padding: 7px 18px;
  cursor: pointer;
}

#dialog-next:hover { background: #f4d97a; }

/* ===========================================================
   Warning toast
   =========================================================== */

#toast {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 150;
  max-width: 80vw;
  padding: 10px 16px;
  background: #5a1f1f;
  border: 1px solid #ff7a7a;
  border-radius: 8px;
  color: #ffd9d9;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===========================================================
   Congratulatory popup (key homestead milestones)
   =========================================================== */

#celebration {
  position: absolute;
  inset: 0;
  z-index: 200;              /* above the chest/shop modals an upgrade fires from */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;      /* let the card own clicks; no backdrop to block the modal beneath */
}

#celebration.hidden { display: none; }

#celebration .celebration-card {
  pointer-events: auto;
  max-width: 84vw;
  width: 340px;
  padding: 24px 26px 22px;
  text-align: center;
  background: linear-gradient(180deg, #2c3a1f 0%, #223018 100%);
  border: 1px solid #f4d97a;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(244, 217, 122, 0.12);
  color: #f3ecd6;
  transform: scale(0.9);
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

#celebration.show .celebration-card {
  transform: scale(1);
  opacity: 1;
}

#celebration .celebration-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 10px;
}

#celebration .celebration-title {
  font-size: 20px;
  font-weight: 700;
  color: #f4d97a;
  margin-bottom: 8px;
}

#celebration .celebration-body {
  font-size: 14px;
  line-height: 1.45;
  color: #d9d2bd;
  margin-bottom: 18px;
}

#celebration .celebration-dismiss {
  padding: 9px 22px;
  font-size: 14px;
  font-weight: 600;
  color: #223018;
  background: #f4d97a;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

#celebration .celebration-dismiss:hover { background: #ffe8a0; }

/* ===========================================================
   Death popup — full-screen, blocking (unlike the celebration toast).
   =========================================================== */
#death {
  position: absolute;
  inset: 0;
  z-index: 260;                     /* above every in-game overlay */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 6, 0.72);  /* darkening backdrop */
  pointer-events: auto;             /* backdrop captures clicks — a hard stop */
}

#death.hidden { display: none; }

#death .death-card {
  max-width: 84vw;
  width: 360px;
  padding: 28px 28px 24px;
  text-align: center;
  background: linear-gradient(180deg, #3a1f1f 0%, #2a1616 100%);
  border: 1px solid #d8564a;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 3px rgba(216, 86, 74, 0.15);
  color: #f3e6e6;
}

#death .death-icon {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 10px;
}

#death .death-title {
  font-size: 22px;
  font-weight: 700;
  color: #ff8f8f;
  margin-bottom: 8px;
}

#death .death-body {
  font-size: 14px;
  line-height: 1.45;
  color: #e0cccc;
  margin-bottom: 20px;
}

#death .death-restart {
  padding: 10px 26px;
  font-size: 14px;
  font-weight: 600;
  color: #2a1616;
  background: #ff8f8f;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

#death .death-restart:hover { background: #ffb0b0; }

/* Number inputs in dialogs (buy/sell amount, chest transfer amount) */
.amt {
  width: 48px;
  font: inherit;
  font-size: 13px;
  text-align: center;
  color: #e6e9ef;
  background: #0e121a;
  border: 1px solid #2a3140;
  border-radius: 5px;
  padding: 3px 4px;
  font-variant-numeric: tabular-nums;
}
.amt:disabled { opacity: 0.4; }

/* ===========================================================
   Cabin storage chest dialog
   =========================================================== */

#chest {
  position: absolute;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 11, 0.72);
  pointer-events: auto;
}

.chest-card {
  width: min(640px, 94vw);
  background: #11151d;
  border: 1px solid #2a3140;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.chest-card header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #1d2330;
}

.chest-card header h1 {
  font-size: 16px;
  color: #e6e9ef;
}

.chest-cap-wrap {
  margin-left: auto;
  font-size: 13px;
  color: #8b94a6;
}

.chest-cap-wrap b {
  color: #9ad0ff;
  font-variant-numeric: tabular-nums;
}

#chest-close {
  font-size: 22px;
  line-height: 1;
  color: #8b94a6;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 4px;
}
#chest-close:hover { color: #fff; }

.chest-upgrade,
.chest-house,
.chest-bake {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #1d2330;
  font-size: 13px;
  color: #aeb6c4;
}
.chest-upgrade b,
.chest-house b,
.chest-bake b { color: #9ad0ff; }

.chest-upgrade { background: rgba(199, 154, 46, 0.07); }

.chest-bake .amt { width: 56px; }

#homestead-upgrade,
#stove-build,
#bake-bread {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #0b0d12;
  background: #c79a2e;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
#homestead-upgrade:hover,
#stove-build:hover,
#bake-bread:hover { background: #e0b13e; }
#homestead-upgrade:disabled,
#stove-build:disabled,
#bake-bread:disabled {
  background: #2a3140;
  color: #6b7384;
  cursor: default;
}

.chest-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.chest-cols section {
  padding: 12px 16px;
}
.chest-cols section:first-child {
  border-right: 1px solid #1d2330;
}

.chest-cols h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b94a6;
  margin-bottom: 8px;
}

.store-list {
  list-style: none;
}

.store-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 14px;
  color: #e6e9ef;
}

.store-name {
  flex: 1;
  text-transform: capitalize;
}

.store-qty {
  font-weight: 700;
  color: #9fe07f;
  font-variant-numeric: tabular-nums;
  min-width: 20px;
  text-align: right;
}

.store-move {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #0b0d12;
  background: #79d05a;
  border: none;
  border-radius: 5px;
  padding: 2px 9px;
  cursor: pointer;
}
.store-move:hover { background: #8fe06f; }
.store-move:disabled {
  background: #2a3140;
  color: #6b7384;
  cursor: default;
}

/* ===========================================================
   Experimental vignette flow
   Textual pages overlay the static vignette-background.png.
   =========================================================== */

#vignette {
  position: absolute;
  inset: 0;
  z-index: 200;                    /* above all in-game UI */
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b0d12;             /* dark fill behind the .vignette-bg layer */
  overflow: hidden;                /* clip the Ken Burns scale + panning media */
  pointer-events: auto;

  /* ---- Animation framework knobs (see js/managers/vignette-anim.js) -------
     Tunable defaults for every reusable animation below. Later prompts set
     specific values (per element via inline style, or per page via a more
     specific rule) — nothing here assigns concrete images or timings. */
  --vg-anim-duration: 900ms;                                  /* fade / stagger item */
  --vg-anim-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --vg-stagger-step: 90ms;                                    /* gap between staggered items */
  --vg-pan-distance: 6%;                                      /* travel for directional pans */
  --vg-pan-duration: 12s;                                     /* slow, Ken-Burns-like drift */
  --vg-kenburns-scale: 1.06;                                  /* background push target */
  --vg-kenburns-duration: 60s;                                /* spans the vignette sequence */
  --vg-scene-fade: 600ms;                                     /* one half of the black cross-fade */

  /* Typography: engraved serif for titles, humanist sans for body. Serif /
     system fallbacks keep it readable if the web fonts don't load offline. */
  --vg-font-title: "Cinzel", "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --vg-font-body: "Inter", "Segoe UI", system-ui, sans-serif;
}

#vignette.hidden { display: none; }

/* Fixed full-screen background image. Sits behind the card and persists for
   the whole sequence; the Ken Burns push is a slow scale so the frame stays
   full-bleed (overflow on #vignette clips the growth). */
.vignette-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #0b0d12 url("../assets/vignette-background.png") center / cover no-repeat;
  transform: scale(1);
  transform-origin: center;
  will-change: transform;
}

/* Ken Burns — modifier class so JS can (re)start it; also present in the
   markup so it runs even without the animator. 1.00 -> ~1.06 over the run. */
.vignette-bg.vg-kenburns {
  animation: vg-kenburns var(--vg-kenburns-duration) ease-out both;
}

@keyframes vg-kenburns {
  from { transform: scale(1); }
  to   { transform: scale(var(--vg-kenburns-scale)); }
}

.vignette-card {
  position: relative;
  z-index: 10;                     /* above .vignette-bg, below the fade curtain */
  width: min(620px, 92vw);         /* resizes responsively; stays centered/stationary */
  max-height: 88vh;
  overflow-y: auto;
  padding: 36px 40px;
  /* Slightly translucent so the background image reads behind the text. */
  background: rgba(17, 21, 29, 0.92);
  border: 1px solid #2a3140;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
  font-family: var(--vg-font-body);
}

/* Treatment badge — shows the assigned mission-drift condition on the
   drift page (proactive/reactive · opportunity/survival · profit/loss). */
.vignette-treatment {
  display: inline-block;
  margin-bottom: 18px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #ffd98a;
  background: rgba(120, 85, 20, 0.35);
  border: 1px solid #6a5320;
  border-radius: 999px;
}

.vignette-card h1 {
  font-size: 24px;
  color: #e6e9ef;
  margin-bottom: 14px;
}

.vignette-headline {
  font-size: 16px;
  font-weight: 700;
  color: #9fd6ff;
  margin-bottom: 16px;
}

#vignette-body p {
  font-size: 15px;
  line-height: 1.6;
  color: #c7cdd9;
  margin-bottom: 14px;
}

/* ============================================================
   Company introduction screen (kind: "company")
   ------------------------------------------------------------
   Documentary / case-study feel: an engraved serif title beside the
   company logo, a lead mission line, then the company description as
   quiet, well-spaced body copy. Rendered into #vignette-body by
   renderCompany(); entrance animations are triggered by the animator.
   ============================================================ */
.vc {
  text-align: center;
}

/* Logo + name lockup. Logo sits above the name on a centered stack; the
   name is the engraved serif title. */
.vc-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}

.vc-logo {
  display: block;
  width: auto;
  height: 72px;                    /* scales the artwork; hidden if it fails to load */
  max-width: 60%;
  object-fit: contain;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.45));
}

.vc-name {
  font-family: var(--vg-font-title);
  font-weight: 600;
  font-size: clamp(26px, 4.6vw, 40px);
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: #f2ede3;                  /* warm off-white — reads over the backdrop */
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
  margin: 0;
}

/* Mission description — the lead line. Larger, lighter serif italic to set
   it apart from the body copy without shouting. */
.vc-mission {
  font-family: "Cormorant Garamond", var(--vg-font-title);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(17px, 2.4vw, 22px);
  line-height: 1.5;
  color: #d9c9a3;                  /* muted gold */
  max-width: 34em;
  margin: 4px auto 26px;
}

/* A hairline divider between the mission lead and the description. */
.vc-mission::after {
  content: "";
  display: block;
  width: 56px;
  height: 2px;
  margin: 20px auto 0;
  background: linear-gradient(90deg, transparent, rgba(217, 201, 163, 0.7), transparent);
}

/* Company description — quiet, readable body copy, left-aligned for long-form
   reading with generous spacing (the "case study" body). */
.vc-desc {
  text-align: left;
  max-width: 40em;
  margin: 0 auto;
}

.vc-desc p {
  font-family: var(--vg-font-body);
  font-size: 15.5px;
  line-height: 1.72;
  color: #cfd5df;
  margin: 0 0 15px;
}

.vc-desc p:last-child { margin-bottom: 0; }

/* Slider question block */
.vignette-questions { text-align: left; }

.vignette-questions .vq-instructions {
  font-size: 14px;
  font-style: italic;
  color: #9aa3b2;
  margin-bottom: 22px;
  text-align: center;
}

.vq {
  margin-bottom: 26px;
}

.vq-text {
  font-size: 15px;
  color: #e6e9ef;
  margin-bottom: 12px;
}

.vq-slider {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 14px;
}

.vq-slider input[type="range"] {
  grid-column: 1 / 2;
  width: 100%;
  accent-color: #79d05a;
  cursor: pointer;
}

.vq-value {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
  min-width: 2.4em;
  font-weight: 700;
  font-size: 16px;
  color: #79d05a;
  text-align: center;
}

.vq-ends {
  grid-column: 1 / 2;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #8a93a4;
}

/* Demographic questions on the welcome page — sits beneath the prose,
   separated by a rule. Each item is a label above a dropdown / number field. */
.vd-section {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid #2a3140;
  text-align: left;
}

.vd {
  margin-bottom: 18px;
}

.vd-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #e6e9ef;
  margin-bottom: 6px;
}

.vd-control select,
.vd-control input[type="number"] {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: #e6e9ef;
  background: rgba(11, 13, 18, 0.6);
  border: 1px solid #2a3140;
  border-radius: 6px;
  padding: 9px 10px;
  cursor: pointer;
}

.vd-control input[type="number"] { cursor: text; }

.vd-control select:focus,
.vd-control input[type="number"]:focus {
  outline: none;
  border-color: #79d05a;
}

/* Reaction scales — Qualtrics-style matrix tables. Each scale prints its
   shared 1..5 agreement anchors once in the header row; every statement
   below is just text + a slider + a live value readout. */
.vq-scale {
  margin-bottom: 30px;
}

.vq-scale-title {
  font-size: 15px;
  font-weight: 700;
  color: #9fd6ff;
  margin-bottom: 10px;
}

.vq-matrix {
  width: 100%;
  border-collapse: collapse;
}

.vq-matrix th,
.vq-matrix td {
  padding: 9px 10px;
  vertical-align: middle;
}

/* Header row: only the scale column carries content (the anchor labels). */
.vq-matrix thead th {
  border-bottom: 1px solid #2a3140;
  padding-bottom: 8px;
}

.vq-matrix .vq-matrix-scale .vq-ends {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #8a93a4;
}

.vq-matrix .vq-matrix-stmt { width: 50%; }
.vq-matrix .vq-matrix-val  { width: 2.6em; }

.vq-matrix tbody tr + tr td {
  border-top: 1px solid rgba(42, 49, 64, 0.6);
}

.vq-matrix .vq-stmt {
  font-size: 14px;
  color: #e6e9ef;
  line-height: 1.45;
}

.vq-matrix .vq-control input[type="range"] {
  width: 100%;
  accent-color: #79d05a;
  cursor: pointer;
}

.vq-matrix .vq-value {
  min-width: 2.4em;
  font-weight: 700;
  font-size: 16px;
  color: #79d05a;
  text-align: center;
}

.vignette-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 24px;
}

.vignette-progress {
  font-size: 12px;
  color: #5f6b80;
}

#vignette-next {
  margin-left: auto;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #0b0d12;
  background: #79d05a;
  border: none;
  border-radius: 8px;
  padding: 11px 28px;
  cursor: pointer;
}

#vignette-next:hover { background: #8fe06f; }

/* Scroll affordance — floats at the bottom-center of the vignette overlay
   when the card has content below the fold (so the footer button isn't
   stranded off-screen on short viewports). Bounces to draw the eye and
   hides once the bottom is reached. */
#vignette-scroll-hint {
  position: absolute;
  left: 50%;
  bottom: 4vh;
  z-index: 15;                     /* above the card, below the fade curtain */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 16px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #0b0d12;
  background: #79d05a;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  animation: scroll-hint-bounce 1.4s ease-in-out infinite;
}

#vignette-scroll-hint.hidden { display: none; }
#vignette-scroll-hint:hover { background: #8fe06f; }

.scroll-hint-arrow {
  font-size: 13px;
  line-height: 1;
}

/* Keep the X-centering (translateX(-50%)) through the vertical bounce. */
@keyframes scroll-hint-bounce {
  0%, 100% { transform: translate(-50%, 0); }
  50%      { transform: translate(-50%, 6px); }
}

@media (prefers-reduced-motion: reduce) {
  #vignette-scroll-hint { animation: none; transform: translateX(-50%); }
}

/* ============================================================
   Vignette animation framework
   ------------------------------------------------------------
   Reusable, content-agnostic building blocks. The animator
   (js/managers/vignette-anim.js) triggers these by toggling the
   classes below; later prompts only assign images/timings and
   call the triggers. Nothing here binds specific content.

   Layers inside #vignette (low -> high z):
     .vignette-bg (0) · .vignette-card (10) · #vignette-scroll-hint (15)
     · .vignette-fade (20)
   ============================================================ */

/* Between-scene curtain: fades the whole overlay to black so the caller can
   swap page content unseen (~1s of black), then fades back in. */
.vignette-fade {
  position: absolute;
  inset: 0;
  z-index: 20;                     /* above the card + scroll hint */
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--vg-scene-fade) ease;
}
.vignette-fade.black  { opacity: 1; }
.vignette-fade.hidden { display: none; }

/* ---- Reusable content animations --------------------------------------
   Applied to any element inside the card (which is itself stationary).
   Each is a one-shot; the animator restarts it by removing + re-adding the
   class (forcing a reflow) so it can replay on every scene. */

.anim-fade-in  { animation: vg-fade-in  var(--vg-anim-duration) var(--vg-anim-ease) var(--vg-anim-delay, 0ms) both; }
.anim-fade-out { animation: vg-fade-out var(--vg-anim-duration) var(--vg-anim-ease) var(--vg-anim-delay, 0ms) both; }

@keyframes vg-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes vg-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* Staggered fade-in: apply to a CONTAINER; the animator stamps each child
   with --anim-index so they rise + fade in sequence. --vg-stagger-base shifts
   the whole run (e.g. to begin after the title has faded in). */
.anim-stagger-in > * {
  opacity: 0;
  animation: vg-stagger-in var(--vg-anim-duration) var(--vg-anim-ease) both;
  animation-delay: calc(var(--vg-stagger-base, 0ms) + var(--anim-index, 0) * var(--vg-stagger-step));
}

@keyframes vg-stagger-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Directional pans — slow drift across the four axes. Chiefly for images in
   an overflow-hidden frame (below), but usable on any element. Distance +
   duration are tunable via --vg-pan-distance / --vg-pan-duration. */
.anim-pan-lr { animation: vg-pan-lr var(--vg-pan-duration) var(--vg-anim-ease) var(--vg-anim-delay, 0ms) both; }
.anim-pan-rl { animation: vg-pan-rl var(--vg-pan-duration) var(--vg-anim-ease) var(--vg-anim-delay, 0ms) both; }
.anim-pan-bt { animation: vg-pan-bt var(--vg-pan-duration) var(--vg-anim-ease) var(--vg-anim-delay, 0ms) both; }
.anim-pan-tb { animation: vg-pan-tb var(--vg-pan-duration) var(--vg-anim-ease) var(--vg-anim-delay, 0ms) both; }

@keyframes vg-pan-lr {  /* left -> right */
  from { transform: translate3d(calc(-1 * var(--vg-pan-distance)), 0, 0); }
  to   { transform: translate3d(var(--vg-pan-distance), 0, 0); }
}
@keyframes vg-pan-rl {  /* right -> left */
  from { transform: translate3d(var(--vg-pan-distance), 0, 0); }
  to   { transform: translate3d(calc(-1 * var(--vg-pan-distance)), 0, 0); }
}
@keyframes vg-pan-bt {  /* bottom -> top */
  from { transform: translate3d(0, var(--vg-pan-distance), 0); }
  to   { transform: translate3d(0, calc(-1 * var(--vg-pan-distance)), 0); }
}
@keyframes vg-pan-tb {  /* top -> bottom */
  from { transform: translate3d(0, calc(-1 * var(--vg-pan-distance)), 0); }
  to   { transform: translate3d(0, var(--vg-pan-distance), 0); }
}

/* ---- Media frame -------------------------------------------------------
   Clips an image that may be LARGER than the overlay so it can pan/scale
   within its bounds without spilling. Drop an <img class="vignette-media">
   inside a .vignette-frame and trigger a pan on the image; no image wired. */
.vignette-frame {
  position: relative;
  overflow: hidden;                /* image can exceed these bounds while moving */
  border-radius: 8px;
}

.vignette-media {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  will-change: transform, opacity;
}

/* Respect reduced-motion: drop the movement, keep content visible. */
@media (prefers-reduced-motion: reduce) {
  .vignette-bg.vg-kenburns { animation: none; transform: none; }
  .anim-pan-lr, .anim-pan-rl, .anim-pan-bt, .anim-pan-tb {
    animation: none; transform: none;
  }
  .anim-stagger-in > * { animation: none; opacity: 1; transform: none; }
  .anim-fade-in  { animation-duration: 1ms; }
  .anim-fade-out { animation: none; opacity: 0; }
}

/* ============================================================
   Cinematic treatment sequence
   ------------------------------------------------------------
   Three full-bleed-ish scenes over the (unchanged) fixed background:
   a bounded frame clips an oversized image that pans at constant speed;
   a caption fades in over it. The company mission background stays put
   behind the frame, so the drift feels like footage on a set.
   Orchestrated by playTreatmentSequence() in js/systems/research.js.
   ============================================================ */
.vignette-scene {
  position: absolute;
  inset: 0;
  z-index: 16;                     /* above the card, below the fade curtain (20) */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;            /* the sequence auto-plays; nothing to click */
}
.vignette-scene.hidden { display: none; }

/* The overlay: a bounded, letterboxed panel that CLIPS the oversized image.
   The mission background remains visible around it. */
.scene-frame {
  position: relative;
  width: min(900px, 92vw);
  height: min(560px, 70vh);
  overflow: hidden;                /* image is larger than this and is clipped */
  border-radius: 10px;
  background: #05070b;             /* shows if the image is missing/loading */
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(0, 0, 0, 0.5);
}

/* The image — intentionally LARGER than the frame so it can pan without
   exposing an edge. Orientation classes size the overflow on the pan axis.
   Opacity is a transition (independent of the transform-based pan animation),
   so an image can fade in AND move at the same time. */
.scene-media {
  position: absolute;
  object-fit: cover;
  opacity: 0;
  transition: opacity 800ms ease;
  will-change: transform, opacity;
}
.scene-media.is-shown { opacity: 1; }

/* Horizontal pans (scenes 1 & 2): extra width, centered, generous headroom. */
.scene-media.pan-x {
  top: 0;
  left: -30%;
  width: 160%;
  height: 100%;
}
/* Vertical pans (scene 3): extra height, centered. */
.scene-media.pan-y {
  left: 0;
  top: -30%;
  width: 100%;
  height: 160%;
}

/* Caption — a documentary lower-third: text over a dark gradient scrim,
   fading in independently of the image. */
.scene-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 64px 40px 30px;
  background: linear-gradient(to top,
              rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.62) 55%, rgba(0, 0, 0, 0) 100%);
  opacity: 0;
  transition: opacity 900ms ease;
}
.scene-caption.is-shown { opacity: 1; }

/* Keeps the caption text and its Continue button in one centered column, so
   the button lands at the lower-right corner of the text block. */
.scene-caption-inner {
  max-width: 46em;
  margin: 0 auto;
}

.scene-caption p {
  margin: 0;
  font-family: var(--vg-font-body);
  font-size: clamp(15px, 1.9vw, 18px);
  line-height: 1.62;
  color: #f2f4f8;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.6);
}

/* Green Continue button, lower-right of the caption text. Mirrors #vignette-next.
   The scene overlay is pointer-events:none, so re-enable clicks on the button.
   Hidden (and un-clickable) until the scene has settled, then fades in. */
.scene-continue {
  display: block;
  margin: 16px 0 0 auto;             /* below the text, pushed to the right edge */
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #0b0d12;
  background: #79d05a;
  border: none;
  border-radius: 8px;
  padding: 11px 28px;
  cursor: pointer;
  pointer-events: none;
  opacity: 0;
  transition: opacity 500ms ease;
}
.scene-continue:hover { background: #8fe06f; }
.scene-continue.is-shown { opacity: 1; pointer-events: auto; }

/* Reduced motion: keep the scenes (images + captions still fade), drop the
   pan so nothing slides. The oversized image simply shows its center. */
@media (prefers-reduced-motion: reduce) {
  .scene-media.pan-x { left: -30%; }
  .scene-media.pan-y { top: -30%; }
}

/* ============================================================
   Transition — glowing Homestead Act letter -> portal -> game
   ============================================================ */

/* Scene backdrop: a dark, faintly warm void so the glowing letter pops. */
#transition {
  position: absolute;
  inset: 0;
  z-index: 210;                 /* above the vignette flow (200) */
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 45%,
              rgba(28, 22, 10, 0.72), rgba(0, 0, 0, 0.94));
  perspective: 1200px;          /* gives the fly-in a touch of depth */
  pointer-events: auto;
}

#transition.hidden { display: none; }

/* The letter — aged parchment that rests at a slight angle, as if dropped
   on a table. A perpetual golden glow marks it as something uncanny. */
.letter {
  position: relative;
  width: min(560px, 88vw);
  max-height: 86vh;
  overflow-y: auto;
  padding: 40px 44px 34px;
  text-align: center;
  color: #3a2c18;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 250, 235, 0.9), rgba(0,0,0,0) 60%),
    linear-gradient(160deg, #f0e6cd 0%, #e6d8b6 55%, #dccaa1 100%);
  border: 1px solid #b9a572;
  border-radius: 4px;
  transform: rotate(-4deg);     /* resting angle if animation is disabled */
  box-shadow:
    0 0 42px 10px rgba(255, 214, 120, 0.6),
    0 0 90px 24px rgba(255, 196, 86, 0.28),
    0 22px 48px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
}

/* Fly in from off-screen, overshoot, and settle at -4deg; then begin to
   pulse. The two animations touch different properties (transform vs.
   box-shadow), so they coexist. */
.letter.fly {
  animation:
    letter-fly 1150ms cubic-bezier(0.16, 0.84, 0.3, 1.25) both,
    letter-glow 2.8s ease-in-out 1150ms infinite;
}

@keyframes letter-fly {
  0%   { transform: translate(-58vw, -82vh) rotate(-46deg) scale(0.55); opacity: 0; }
  55%  { opacity: 1; }
  68%  { transform: translate(0, 0) rotate(7deg) scale(1.05); }
  84%  { transform: translate(0, 0) rotate(-6deg) scale(0.99); }
  100% { transform: translate(0, 0) rotate(-4deg) scale(1); }
}

@keyframes letter-glow {
  0%, 100% {
    box-shadow:
      0 0 42px 10px rgba(255, 214, 120, 0.6),
      0 0 90px 24px rgba(255, 196, 86, 0.28),
      0 22px 48px rgba(0, 0, 0, 0.6);
  }
  50% {
    box-shadow:
      0 0 70px 18px rgba(255, 232, 160, 0.9),
      0 0 130px 40px rgba(255, 206, 110, 0.45),
      0 22px 48px rgba(0, 0, 0, 0.6);
  }
}

/* Touched — the letter spins down into the portal and vanishes. */
.letter.sucked {
  animation: letter-suck 950ms ease-in forwards;
  pointer-events: none;
}

@keyframes letter-suck {
  0%   { transform: rotate(-4deg) scale(1);    opacity: 1; }
  100% { transform: rotate(560deg) scale(0.04); opacity: 0; }
}

.letter-seal {
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #f6e6c0;
  background: radial-gradient(circle at 35% 30%, #b8403a, #7d211d);
  border-radius: 50%;
  box-shadow: inset 0 0 6px rgba(0,0,0,0.5), 0 2px 5px rgba(0,0,0,0.4);
}

.letter-head {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #2e2210;
  margin-bottom: 8px;
}

.letter-meta {
  font-size: 12px;
  font-style: italic;
  color: #6b5731;
  margin-bottom: 20px;
}

.letter-body p {
  font-size: 15px;
  line-height: 1.62;
  text-align: left;
  margin-bottom: 14px;
}

.letter-body b { color: #5a3a12; }

.letter-sign {
  margin-top: 18px;
  font-size: 13px;
  font-style: italic;
  color: #5a4824;
  line-height: 1.5;
}

.letter-hint {
  margin-top: 22px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #8a5a18;
  animation: hint-pulse 1.8s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* Portal curtain — fades to black over the letter, holds, then fades out
   to reveal the game world behind it. */
#portal-fade {
  position: absolute;
  inset: 0;
  z-index: 230;                 /* above the transition scene */
  background: #000;
  opacity: 0;
  transition: opacity 1200ms ease;
  pointer-events: none;
}

#portal-fade.black  { opacity: 1; }
#portal-fade.hidden { display: none; }

/* Respect reduced-motion: skip the flight/spin, keep the angle + fades. */
@media (prefers-reduced-motion: reduce) {
  .letter.fly    { animation: letter-glow 2.8s ease-in-out infinite; }
  .letter.sucked { animation: none; opacity: 0; transition: opacity 300ms ease; }
}
