/* Recovered base styles extracted from index.html. */
body {
      font-family: "Trebuchet MS", sans-serif;
      background: #111;
      color: #eee;
      margin: 0;
      padding: 0;
font-size: 1rem;   /* base size ~16px */
  line-height: 1.4;
    }
    /* Popup */
    #popup {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.8);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 1000;
    }
    #popup-content {
      background: #222;
      border: 2px solid #888;
      padding: 20px;
      width: min(90vw, 400px);
      min-height: 170px;
      box-sizing: border-box;
      text-align: center;
      position: relative;
      overflow: hidden;
    }
    #popup-content::after {
      content: '';
      position: absolute;
      inset: 0;
      pointer-events: none;
      opacity: 0;
      z-index: 2;
      background:
        repeating-linear-gradient(
          0deg,
          rgba(255,255,255,0.42) 0 2px,
          rgba(0,0,0,0.42) 2px 4px
        ),
        repeating-linear-gradient(
          90deg,
          rgba(255,0,0,0.08) 0 2px,
          rgba(0,180,255,0.08) 2px 4px
        );
      mix-blend-mode: screen;
    }
    #popup-content.error-overlay-active::after {
      opacity: 0.8;
      animation: dialogErrorStatic 0.08s steps(6, end) infinite;
    }
    @keyframes dialogErrorStatic {
      0% {
        transform: translateX(0);
        background-position: 0 0, 0 0;
      }
      30% {
        transform: translateX(-1px);
        background-position: -3px 2px, 2px -1px;
      }
      60% {
        transform: translateX(1px);
        background-position: 2px -2px, -3px 2px;
      }
      100% {
        transform: translateX(0);
        background-position: 0 0, 0 0;
      }
    }
    #popup-message {
      min-height: 3.2em;
    }
    #popup button {
      margin-top: 15px;
      padding: 5px 15px;
      background: #444;
      color: #eee;
      border: 1px solid #888;
      cursor: pointer;
    }
    /* Tabs */
    .tabs {
      display: flex;
      background: #222;

  overflow-x: auto;
      border-bottom: 2px solid #555;
    }
    .tab {
flex: 0 0 auto; 
      padding: 10px 20px;
      cursor: pointer;
      border-right: 1px solid #555;
    }
    .tab.active {
      background: #444;
      font-weight: bold;
    }
    #story-tab {
      background: linear-gradient(180deg, #6f5529 0%, #4d3817 100%);
      color: #f4e6c8;
      font-weight: 700;
      letter-spacing: 0.03em;
      box-shadow: inset 0 -2px 0 rgba(255, 214, 138, 0.2);
    }
    #story-tab.active {
      background: linear-gradient(180deg, #a37a39 0%, #6f5529 100%);
      color: #fff4db;
      box-shadow: inset 0 -2px 0 rgba(255, 230, 180, 0.55), 0 0 14px rgba(163, 122, 57, 0.25);
    }
    .tab-content {
      display: none;
      padding: 20px;
    }
    .tab-content.active {
      display: block;
    }
    .hidden-initial {
      display: none;
    }
    .story-tab-wrap {
      margin-left: auto;
      display: flex;
      align-items: center;
      gap: 8px;
      padding-right: 10px;
      color: #bdbdbd;
      font-size: 0.9rem;
    }
    .story-shell {
      max-width: 860px;
      margin: 0 auto;
      background: linear-gradient(180deg, #f4ecd8 0%, #e8dcc2 100%);
      color: #2f2417;
      border: 1px solid #a79068;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.35);
      border-radius: 6px;
      overflow: hidden;
    }
    .story-header {
      padding: 14px 18px;
      border-bottom: 1px solid #b69d72;
      background: linear-gradient(90deg, #e9dbc0 0%, #e3d2b1 100%);
      font-family: Georgia, "Times New Roman", serif;
      font-size: 1.1rem;
      letter-spacing: 0.04em;
      text-transform: uppercase;
    }
    #story-segment {
      padding: 20px;
      font-family: Georgia, "Times New Roman", serif;
      line-height: 1.7;
      font-size: 1.08rem;
      transform-origin: left center;
      backface-visibility: hidden;
    }
    #story-segment.page-turn-out {
      animation: pageTurnOut 240ms ease-in forwards;
    }
    #story-segment.page-turn-in {
      animation: pageTurnIn 280ms ease-out forwards;
    }
    @keyframes pageTurnOut {
      0% {
        opacity: 1;
        transform: perspective(1200px) rotateY(0deg) translateX(0);
      }
      100% {
        opacity: 0;
        transform: perspective(1200px) rotateY(-16deg) translateX(-8px);
      }
    }
    @keyframes pageTurnIn {
      0% {
        opacity: 0;
        transform: perspective(1200px) rotateY(14deg) translateX(8px);
      }
      100% {
        opacity: 1;
        transform: perspective(1200px) rotateY(0deg) translateX(0);
      }
    }
    .story-kicker {
      margin: 0 0 14px;
      color: #7a6037;
      font-size: 0.92rem;
      letter-spacing: 0.08em;
      text-transform: uppercase;
    }
    .story-text {
      margin: 0 0 16px;
    }
    .story-image-placeholder {
      margin: 16px 0;
      padding: 8px;
      border: 1px solid #8d7752;
      border-radius: 4px;
      background: rgba(120, 97, 62, 0.08);
    }
    .story-image-placeholder img {
      display: block;
      width: 100%;
      height: auto;
      max-height: 520px;
      object-fit: contain;
      border-radius: 2px;
      background: #15120d;
    }
    .story-popup {
      margin: 16px 0;
      padding: 14px 16px;
      border-left: 5px solid #8f743f;
      background: #efe4cd;
      color: #3a2c16;
      font-family: "Trebuchet MS", sans-serif;
      box-shadow: inset 0 0 0 1px rgba(143, 116, 63, 0.25);
      white-space: pre-line;
    }
    .story-actions {
      margin-top: 22px;
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
    }
    .story-action {
      border: 1px solid #6f5529;
      background: #dbc49b;
      color: #2d2010;
      padding: 10px 14px;
      font-size: 0.95rem;
      cursor: pointer;
      transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
    }
    .story-action:hover {
      transform: translateY(-1px);
      box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
      background: #e4cea7;
    }
    .inventory-list {
      display: grid;
      gap: 14px;
    }
    .inventory-item {
      border: 1px solid #5b5b5b;
      background: #1a1a1a;
      padding: 12px;
      box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    }
    .inventory-item-text {
      margin-bottom: 10px;
      line-height: 1.5;
    }
    .inventory-item-text i {
      color: #b9d9ff;
    }
    .inventory-item-header {
      font-weight: 700;
      margin-bottom: 8px;
      color: #f3f3f3;
    }
    .inventory-item-help {
      font-style: italic;
      color: #b9d9ff;
      margin-bottom: 10px;
      line-height: 1.45;
    }
    .inventory-item-body {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .inventory-body-text {
      white-space: pre-line;
      line-height: 1.45;
    }
    .inventory-images {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
    }
    .inventory-image-wrap {
      border: 1px solid #444;
      background: #111;
      padding: 8px;
      min-width: 160px;
      width: fit-content;
    }
    .inventory-image {
      width: 100%;
      max-width: 260px;
      height: auto;
      display: block;
      background: #0d0d0d;
    }
    .inventory-image-name {
      margin-top: 6px;
      font-size: 0.85rem;
      color: #bbb;
      word-break: break-word;
    }
    .inventory-item-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 10px;
    }
    .inventory-item-status {
      margin-top: 8px;
      font-size: 0.8rem;
      color: #b9d9ff;
    }
    a.glossary-link {
      color: #6cf;
      text-decoration: underline;
      cursor: pointer;
    }
    h2 {
      margin-top: 0;
    }
    /* Quest subtabs */
    .subtabs {
      display: flex;
      margin-bottom: 10px;
      border-bottom: 1px solid #555;
    }
    .subtab {
      padding: 5px 15px;
      cursor: pointer;
      border-right: 1px solid #555;
    }
    .subtab.active {
      background: #333;
      font-weight: bold;
    }
    .subtab-content {
      display: none;
    }
    .subtab-content.active {
      display: block;
    }
    /* Map */
    .map-box {
      font-family: monospace;
      background: #222;
      padding: 10px;
      display: inline-block;
      border: 1px solid #555;
    }
    /* Glossary layout only applies inside its tab */
.glossary-layout {
  display: flex;
}
.glossary-sidebar {
  width: 220px;
  border-right: 1px solid #555;
  padding-right: 10px;
}
#glossary-search,
#crystals-search {
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 8px;
  border: 1px solid #555;
  background: #161616;
  color: #eee;
}
#glossary-list {
  max-height: 68vh;
  overflow: auto;
}
#glossary-list .glossary-item {
  padding: 5px;
  cursor: pointer;
}
#glossary-list .glossary-item-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
#glossary-list .glossary-item-main {
  flex: 1;
  min-width: 0;
}
#glossary-list .glossary-section {
  margin: 10px 0 4px;
  padding-top: 6px;
  border-top: 1px solid #555;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #b7d4ea;
}
#glossary-list .glossary-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
#glossary-list .glossary-empty {
  color: #aaa;
  cursor: default;
  padding: 5px;
}
#glossary-list .glossary-item:hover {
  background: #333;
}
#glossary-list .glossary-item.active {
  background: #2d4057;
  font-weight: 700;
}
#glossary-list .glossary-item-meta {
  margin-top: 2px;
  font-size: 0.75rem;
  color: #a8bac8;
  font-weight: 400;
}
#glossary-detail {
  flex: 1;
  padding-left: 20px;
}
#glossary-detail .glossary-note {
  color: #aaa;
  font-size: 0.9rem;
}
#glossary-detail .glossary-card-preview {
  width: 100%;
  max-width: 320px;
  height: 460px;
  border: 1px solid #555;
  background: #111;
}
.glossary-item-action,
.glossary-detail-action {
  border: 1px solid #4f6c83;
  background: #263747;
  color: #dbe9f3;
  padding: 3px 7px;
  cursor: pointer;
  font-size: 0.75rem;
}
.glossary-item-action:hover,
.glossary-detail-action:hover {
  background: #30485d;
}
.glossary-item-action:disabled,
.glossary-detail-action:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  background: #1b2631;
}
.glossary-detail-actions,
.crystals-detail-actions {
  margin: 8px 0 10px;
}
#crystals-content {
  max-height: 72vh;
  overflow: auto;
}
.crystals-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.crystal-card-shell {
  border: 1px solid #4a4a4a;
  background: #181818;
  padding: 10px;
  width: min(100%, 360px);
}
.crystal-card-shell.power-used {
  opacity: 0.55;
}
.crystal-card-shell.power-used .glossary-card-preview {
  filter: grayscale(1);
}
.crystal-card-shell .glossary-card-preview {
  width: 100%;
  max-width: 320px;
  height: 460px;
  border: 1px solid #555;
  background: #111;
}
.map-room {
  position: relative;
  width: 50px;   /* scaled down representation of 50x50 ft */
  height: 50px;
  background: #2a2a2a;
  border: 4px solid #666;
  margin: 20px 0;
  box-shadow: inset 0 0 10px #000;
}

/* Player token */
.player-token {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 5px;
  height: 5px;
  background-color: #3f3;
  border: 2px solid #0a0;
  border-radius: 50%;
}

/* Door styling */
.door {
  position: absolute;
  width: 5px;
  height: 12px;
  background: #8b5;
  border: 2px solid #333;
}
.door.south {
  bottom: -6px;   /* slightly outside the wall */
  left: 50%;
  transform: translateX(-50%);
}
#clear-button {
  margin-left: auto;
  margin-right: 10px;
  padding: 5px 10px;
  background: #600;
  color: #fff;
  border: 1px solid #933;
  cursor: pointer;
  font-weight: bold;
}
h2 {
  font-size: 1.3rem;
}
.tab, .subtab {
  font-size: 0.95rem;
}
@media (max-width: 600px) {
  body {
    font-size: 1.1rem;   /* bump text size */
  }
  #clear-button {
    padding: 8px 14px;
    font-size: 1rem;
  }
  .map-room {
    width: 180px;
    height: 180px;
  }
  #story-segment {
    padding: 16px;
    font-size: 1rem;
  }
  .story-actions {
    flex-direction: column;
  }
}
button, .tab, .subtab {
  min-height: 44px;   /* Apple/Google recommend ~44px touch targets */
}

#system-word-wrap {
    position: relative;
    display: inline-block;
  min-width: 7ch;
  }
  #system-word-link {
    color: #6cf;
    text-decoration: underline;
    cursor: pointer;
  }
  #system-word-static {
    position: absolute;
    inset: -1px;
    pointer-events: none;
    display: none;
  }

  /* Debug terminal popup */
  #debug-popup {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1200;
  }
  #debug-popup-content {
    width: min(760px, 94vw);
    border: 1px solid #2c2c2c;
    background: #0b0d0b;
    box-shadow: 0 0 0 2px #111, 0 0 30px rgba(0,0,0,0.8);
    color: #a6f3a6;
    font-family: Consolas, "Courier New", monospace;
  }
  .debug-titlebar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid #263026;
    background: #111;
    color: #8ce98c;
    font-size: 0.9rem;
  }
  .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
  .dot.red { background: #ff5f56; }
  .dot.yellow { background: #ffbd2e; }
  .dot.green { background: #27c93f; }

  #debug-console {
    min-height: 220px;
    max-height: 45vh;
    overflow-y: auto;
    padding: 12px;
    background: #050805;
    border-bottom: 1px solid #263026;
    white-space: pre-wrap;
    line-height: 1.35;
  }
  #debug-console-output .line { margin: 0 0 3px; }
  .cursor {
    display: inline-block;
    margin-left: 2px;
    animation: blink 1s step-end infinite;
  }
  @keyframes blink {
    50% { opacity: 0; }
  }
  .debug-actions {
    padding: 10px;
    text-align: right;
  }
  #system-word-link {
  color: inherit;
  text-decoration: none;
  font: inherit;
  cursor: pointer; /* keeps it clickable, but plain-text look */
}
  /* Entry screen */
  #entry-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1100;
  }
  #entry-screen-content {
    background: #222;
    border: 2px solid #888;
    padding: 30px 28px 24px;
    width: min(90vw, 440px);
    box-sizing: border-box;
    text-align: center;
  }
  #entry-screen-content h2 {
    margin: 0 0 6px;
    font-size: 1.4rem;
    color: #f0f0f0;
  }
  #entry-screen-content > p {
    margin: 0 0 22px;
    color: #aaa;
    font-size: 0.9rem;
  }
  .entry-choices {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
  }
  .entry-choice-btn {
    padding: 12px 18px;
    background: #333;
    color: #eee;
    border: 1px solid #666;
    cursor: pointer;
    font-size: 1rem;
    min-width: 160px;
    transition: background 120ms;
  }
  .entry-choice-btn:hover {
    background: #444;
  }
  .entry-choice-btn.primary {
    border-color: #a37a39;
    background: linear-gradient(180deg, #6f5529 0%, #4d3817 100%);
    color: #f4e6c8;
  }
  .entry-choice-btn.primary:hover {
    background: linear-gradient(180deg, #8a6a32 0%, #5e4420 100%);
  }
  #entry-name-step {
    display: none;
    margin-top: 18px;
  }
  #entry-name-step label {
    display: block;
    margin-bottom: 8px;
    color: #ccc;
    font-size: 0.95rem;
  }
  #entry-name-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    background: #1a1a1a;
    border: 1px solid #666;
    color: #eee;
    font-size: 1rem;
    margin-bottom: 12px;
  }
  #system-word-link.hyperlink-flash {
    color: #7bcfff;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-shadow: 0 0 6px rgba(123, 207, 255, 0.5);
  }
  #popup button.temp-disabled {
    opacity: 0.6;
    filter: grayscale(0.5);
    cursor: not-allowed;
  }
  /* ── Character edit mode ──────────────────────────── */
  .char-header-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
  }
  .char-header-row h2 { margin: 0; }
  #char-edit-btn {
    padding: 4px 12px;
    background: #333;
    border: 1px solid #666;
    color: #ccc;
    cursor: pointer;
    font-size: 0.85rem;
    min-height: 0;
  }
  #char-edit-btn:hover { background: #444; }
  .char-edit-input,
  .char-edit-select {
    background: #1a1a1a;
    border: 1px solid #666;
    color: #eee;
    font-size: 1rem;
    padding: 4px 8px;
    font-family: "Trebuchet MS", sans-serif;
    min-width: 160px;
  }
  .char-edit-input {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
  }
