/* ═══════════════════════════════════════════════════════════════
   THE SAVAGE LANDS — Mobile "Arcane Compendium" App Mode
   ───────────────────────────────────────────────────────────────
   Design direction: An enchanted grimoire held in your hands.
   Obsidian depth. Amber-gold rune-glyph navigation. Candlelit
   text. Silky page-turn transitions. Everything feels intentional,
   weighted, and alive.

   Loaded after style.css — overrides at < 900px only.
   Desktop layout is completely untouched.
═══════════════════════════════════════════════════════════════ */

/* ── New design tokens for mobile ───────────────────────────── */
:root {
  --bottom-nav-h:   64px;
  --nav-active-glow: rgba(201, 168, 76, 0.40);
  --screen-ease:    cubic-bezier(0.22, 1, 0.36, 1);
  --screen-dur:     0.22s;
  --section-bar-h:  34px;
}

/* ── Utility: always hidden until inside the media query ─────── */
.mobile-only { display: none; }


/* ═══════════════════════════════════════════════════════════════
   MOBILE APP MODE  ·  < 900px
═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {

  /* ─── Reveal mobile-only elements ─── */
  .mobile-only { display: block; }


  /* ─────────────────────────────────────────────────────────────
     LAYOUT — column stack, height accounts for bottom nav
  ───────────────────────────────────────────────────────────── */
  #layout {
    flex-direction: column;
    height: calc(100vh  - var(--bottom-nav-h)); /* fallback */
    height: calc(100dvh - var(--bottom-nav-h)); /* dynamic vh: excludes browser chrome on mobile */
  }

  /* Ensure flex children shrink properly — prevents overflow in some browsers */
  #chat-section,
  body.screen-character #sidebar,
  body.screen-inventory #sidebar,
  body.screen-spells    #sidebar,
  body.screen-quests    #sidebar,
  body.screen-area      #sidebar,
  body.screen-party     #sidebar,
  body.screen-map       #sidebar {
    min-height: 0;
  }


  /* ─────────────────────────────────────────────────────────────
     HEADER — compact, essential info only
  ───────────────────────────────────────────────────────────── */
  #site-header {
    padding: 0 14px;
  }

  #realm-sub       { display: none; }
  #header-username { display: none; }

  #realm-title {
    font-size: 13px;
    letter-spacing: 0.12em;
  }

  #header-status { gap: 7px; }

  #header-game-time {
    font-size: 10px;
    margin-right: 0;
  }

  .badge {
    font-size: 11px;
    padding: 2px 8px 2px 6px;
    gap: 4px;
  }

  /* Compact logout */
  #site-header button[onclick="handleLogout()"] {
    font-size: 10px;
    padding: 2px 7px;
  }


  /* ─────────────────────────────────────────────────────────────
     BOTTOM NAVIGATION BAR — Arcane Rune Strip
  ───────────────────────────────────────────────────────────── */
  #mobile-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: var(--bottom-nav-h);
    display: flex;
    align-items: stretch;
    /* Layered background: deep obsidian with barely-visible scanlines */
    background:
      repeating-linear-gradient(
        0deg,
        rgba(255,255,255,0.012) 0px,
        rgba(255,255,255,0.012) 1px,
        transparent 1px,
        transparent 4px
      ),
      linear-gradient(180deg, #0d0d1a 0%, #09090f 100%);
    z-index: 9999;
    padding: 0;
  }

  /* Top edge: glowing gold gradient line */
  #mobile-nav::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent        0%,
      var(--gold-border) 15%,
      rgba(201,168,76,0.7) 50%,
      var(--gold-border) 85%,
      transparent       100%
    );
  }

  /* Faint vertical dividers between 8 buttons (12.5% intervals) */
  #mobile-nav::after {
    content: '';
    position: absolute;
    inset: 8px 0 8px 0;
    background: repeating-linear-gradient(
      90deg,
      transparent                 0,
      transparent                 calc(12.5% - 0.5px),
      rgba(201,168,76,0.07)       calc(12.5% - 0.5px),
      rgba(201,168,76,0.07)       12.5%
    );
    pointer-events: none;
  }

  /* ── Nav button base ── */
  #mobile-nav .mnav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 8px 2px 6px;
    position: relative;
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 7.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    min-height: unset; /* override global tap-target rule for this element */
    transition: color 0.18s;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile-nav .mnav-btn:hover { color: rgba(160,160,192,0.9); }

  /* ── Glyph icons drawn with ::before ── */
  #mobile-nav .mnav-btn::before {
    font-family: var(--font-display), 'Apple Symbols', 'Segoe UI Symbol', serif;
    font-size: 16px;
    line-height: 1;
    display: block;
    transition: all 0.25s var(--screen-ease);
    color: inherit;
  }

  #mobile-nav .mnav-btn[data-screen="chat"]::before      { content: "◈"; }
  #mobile-nav .mnav-btn[data-screen="character"]::before { content: "✦"; }
  #mobile-nav .mnav-btn[data-screen="inventory"]::before { content: "◆"; }
  #mobile-nav .mnav-btn[data-screen="spells"]::before    { content: "✧"; }
  #mobile-nav .mnav-btn[data-screen="quests"]::before    { content: "❖"; }
  #mobile-nav .mnav-btn[data-screen="area"]::before      { content: "◉"; }
  #mobile-nav .mnav-btn[data-screen="party"]::before     { content: "❋"; }
  #mobile-nav .mnav-btn[data-screen="map"]::before       { content: "⊕"; }

  /* ── Active state: glow + lift + indicator line ── */
  #mobile-nav .mnav-btn.active {
    color: var(--gold);
  }

  #mobile-nav .mnav-btn.active::before {
    color: var(--gold);
    transform: scale(1.22) translateY(-2px);
    filter: drop-shadow(0 0 7px var(--nav-active-glow));
  }

  /* Gold indicator bar at very top of active button */
  #mobile-nav .mnav-btn.active::after {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 32px; height: 2px;
    background: var(--gold);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 0 10px var(--gold), 0 2px 16px var(--nav-active-glow);
  }


  /* ─────────────────────────────────────────────────────────────
     HIDE DESKTOP SIDEBAR TAB STRIP
  ───────────────────────────────────────────────────────────── */
  #sidebar-tabs { display: none !important; }


  /* ─────────────────────────────────────────────────────────────
     SCREEN SWITCHING — body.screen-* toggles chat vs sidebar
  ───────────────────────────────────────────────────────────── */

  /* Default: chat visible, sidebar off */
  #sidebar      { display: none; }
  #chat-section { display: flex; }

  /* Sidebar screens */
  body.screen-character #sidebar,
  body.screen-inventory #sidebar,
  body.screen-spells    #sidebar,
  body.screen-quests    #sidebar,
  body.screen-area      #sidebar,
  body.screen-party     #sidebar,
  body.screen-map       #sidebar {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: unset;
    border-right: none;
    height: 100%;
    /* Scrolling happens on the tab-content child, not the sidebar itself,
       but allow sidebar-level scroll as fallback */
    overflow-y: auto;
    animation: mobilePageIn var(--screen-dur) var(--screen-ease) both;
  }

  body.screen-character #chat-section,
  body.screen-inventory #chat-section,
  body.screen-spells    #chat-section,
  body.screen-quests    #chat-section,
  body.screen-area      #chat-section,
  body.screen-party     #chat-section,
  body.screen-map       #chat-section { display: none; }

  /* Chat re-entry animation */
  body.screen-chat #chat-section {
    animation: mobilePageIn var(--screen-dur) var(--screen-ease) both;
  }

  @keyframes mobilePageIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
  }


  /* ─────────────────────────────────────────────────────────────
     SECTION TITLE BAR — sticky label at top of each sidebar screen
  ───────────────────────────────────────────────────────────── */
  body.screen-character #sidebar::before,
  body.screen-inventory #sidebar::before,
  body.screen-spells    #sidebar::before,
  body.screen-quests    #sidebar::before,
  body.screen-area      #sidebar::before,
  body.screen-party     #sidebar::before,
  body.screen-map       #sidebar::before {
    /* Flex item inside sidebar; sticky within the scroll container */
    content: '';  /* overridden per-screen below */
    display: block;
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--section-bar-h);
    flex-shrink: 0;
    /* Ornate header: deep bg with bottom border-glow */
    background: linear-gradient(180deg, #0d0d1a 0%, var(--bg-panel) 100%);
    border-bottom: 1px solid var(--gold-border);
    /* Text */
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--gold);
    line-height: var(--section-bar-h);
    padding: 0 14px;
    /* Decorative left ornament */
    box-shadow: 0 1px 12px rgba(0,0,0,0.5);
  }

  body.screen-character #sidebar::before { content: '✦  Character'; }
  body.screen-inventory #sidebar::before { content: '◆  Inventory'; }
  body.screen-spells    #sidebar::before { content: '✧  Spells'; }
  body.screen-quests    #sidebar::before { content: '❖  Quests'; }
  body.screen-area      #sidebar::before { content: '◉  Area'; }
  body.screen-party     #sidebar::before { content: '❋  Party'; }
  body.screen-map       #sidebar::before { content: '⊕  World Map'; }


  /* ─────────────────────────────────────────────────────────────
     CHAT SECTION — immersive, scroll-locked
  ───────────────────────────────────────────────────────────── */
  #chat-section {
    height: 100%;
    overflow: hidden;
    position: relative;
  }

  /* Gradient vignette at top of message stream */
  #chat-section::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 48px;
    background: linear-gradient(to bottom, var(--bg-deep) 0%, transparent 100%);
    z-index: 5;
    pointer-events: none;
  }

  #messages {
    padding: 10px 12px 6px;
  }

  /* Tighten message bubbles on mobile */
  .msg-wrap { gap: 3px; }

  .msg-dm   { padding: 10px 12px; font-size: 15px; }
  .msg-player { padding: 8px 12px; }

  /* ─────────────────────────────────────────────────────────────
     INPUT BAR — pill textarea + circular send button
  ───────────────────────────────────────────────────────────── */
  #input-bar {
    padding: 8px 10px 10px;
    gap: 7px;
    /* Gradient fade from transparent so messages feel they flow into the bar */
    background: linear-gradient(
      to bottom,
      rgba(8,8,15,0) 0%,
      rgba(8,8,15,0.6) 16px,
      var(--bg-panel) 36px
    );
    border-top: 1px solid rgba(201,168,76,0.12);
  }

  #action-input {
    font-size: 15px;
    padding: 9px 14px;
    border-radius: 22px;
    border-color: rgba(201,168,76,0.2);
    background: rgba(6, 6, 12, 0.85);
    /* Prevent zoom on focus in iOS */
    font-size: 16px;
  }

  #action-input:focus {
    border-color: rgba(201,168,76,0.5);
    box-shadow: 0 0 0 1px rgba(201,168,76,0.15),
                inset 0 0 16px rgba(201,168,76,0.03);
  }

  /* Circular send button — solid gold, arcane glow */
  #send-btn {
    width: 46px;
    height: 46px;
    min-height: unset;
    border-radius: 50%;
    background: linear-gradient(135deg, #8a6820 0%, #c9a84c 55%, #e0c060 100%);
    border: none;
    color: #0a0a0f;
    box-shadow:
      0 0 14px rgba(201, 168, 76, 0.45),
      0 3px 10px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.18s, transform 0.12s;
  }

  #send-btn:hover,
  #send-btn:active {
    background: linear-gradient(135deg, #a07830 0%, #e0c060 55%, #f0d880 100%);
    box-shadow:
      0 0 22px rgba(201, 168, 76, 0.7),
      0 3px 12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
  }

  /* TTS buttons: smaller, circular */
  #tts-toggle-btn,
  #tts-settings-btn {
    width: 38px;
    height: 38px;
    min-height: unset;
    border-radius: 50%;
    flex-shrink: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }


  /* ─────────────────────────────────────────────────────────────
     PANELS — edge-to-edge, styled for mobile density
  ───────────────────────────────────────────────────────────── */
  .panel {
    padding: 10px 14px;
    /* Subtle left-edge gold accent */
    border-left: 2px solid rgba(201,168,76,0.15);
    border-bottom: 1px solid rgba(255,255,255,0.04);
  }

  .panel-header {
    font-size: 9px;
    letter-spacing: 0.18em;
    margin-bottom: 8px;
  }


  /* ─────────────────────────────────────────────────────────────
     ROLL CARD — compact floating card above input
  ───────────────────────────────────────────────────────────── */
  .roll-card {
    margin: 0 10px 8px;
    border-radius: 12px;
    padding: 10px 14px;
    gap: 8px;
  }

  #roll-header { font-size: 11px; }
  #roll-type-label { font-size: 15px; }

  #roll-btn {
    align-self: flex-start;
    padding: 7px 18px;
    font-size: 13px;
  }


  /* ─────────────────────────────────────────────────────────────
     COMBAT PANEL — compact on mobile, scrollable initiative strip
  ───────────────────────────────────────────────────────────── */
  #combat-panel {
    margin: 0 8px 6px;
    font-size: 12px;
  }

  #combat-header {
    padding: 5px 9px;
    font-size: 11px;
  }

  /* Initiative: horizontal scroll strip */
  #initiative-order {
    padding: 5px 8px;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 5px;
    scrollbar-width: none;
  }
  #initiative-order::-webkit-scrollbar { display: none; }

  .combatant-row {
    flex-shrink: 0;
    min-width: 90px;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 5px 8px;
  }

  #action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 6px 8px;
  }

  .combat-action-btn {
    font-size: 11px;
    padding: 5px 11px;
    min-height: 34px;
  }


  /* ─────────────────────────────────────────────────────────────
     MAP CANVAS — full-width, aspect-ratio preserved
  ───────────────────────────────────────────────────────────── */
  #tab-map {
    padding: 8px;
  }

  #map-canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 62vh;
    border-radius: 8px;
    box-shadow: 0 0 0 1px var(--gold-border),
                0 4px 24px rgba(0,0,0,0.6);
  }


  /* ─────────────────────────────────────────────────────────────
     TABLES — horizontal scroll wrapper (skills only)
  ───────────────────────────────────────────────────────────── */
  .skills-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .skills-table::-webkit-scrollbar { display: none; }

  /* Ability table: normal table layout — 3 columns fit without scroll */
  .ability-table {
    display: table;
    width: 100%;
    table-layout: auto;
  }

  .ability-name {
    font-size: 13px;
    padding: 9px 14px 9px 4px;
    white-space: nowrap;
  }

  .ability-score,
  .ability-mod {
    font-size: 14px;
    padding: 9px 12px;
    white-space: nowrap;
    text-align: center;
  }

  .ability-table thead th {
    font-size: 11px;
    padding: 6px 12px 9px;
    white-space: nowrap;
  }


  /* ─────────────────────────────────────────────────────────────
     STAT BADGES — slightly more compact
  ───────────────────────────────────────────────────────────── */
  .stat-badge {
    min-width: 50px;
    padding: 5px 8px;
  }

  .badge-val { font-size: 18px; }
  .badge-label { font-size: 8px; }


  /* ─────────────────────────────────────────────────────────────
     CHARACTER PANEL — better density on small screens
  ───────────────────────────────────────────────────────────── */
  #char-name { font-size: 18px; }
  #char-meta { font-size: 11px; }

  .bar-track { height: 5px; }

  .currency-row {
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }

  .coin {
    padding: 5px 3px;
  }

  .coin-val { font-size: 14px; }


  /* ─────────────────────────────────────────────────────────────
     DISCOVERY NOTIFICATION — positioned above bottom nav
  ───────────────────────────────────────────────────────────── */
  #discovery-notification {
    bottom: calc(var(--bottom-nav-h) + 10px);
    right: 10px;
    left: 10px;
    top: auto;
    max-width: none;
    border-radius: 14px;
  }


  /* ─────────────────────────────────────────────────────────────
     MODALS — bottom sheet style (slides up from bottom)
  ───────────────────────────────────────────────────────────── */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
    z-index: 10000;
  }

  .modal-box {
    border-radius: 22px 22px 0 0;
    padding: 24px 20px 28px;
    max-width: 100%;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    animation: sheetUp var(--screen-dur) var(--screen-ease) both;
  }

  @keyframes sheetUp {
    from { transform: translateY(100%); opacity: 0.8; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  /* Drag indicator pill on top of sheets */
  .modal-box::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(201,168,76,0.25);
    border-radius: 2px;
    margin: 0 auto 20px;
  }

  .battle-summary-box {
    border-radius: 22px 22px 0 0;
    max-height: 92vh;
  }

  .battle-summary-box::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(201,168,76,0.25);
    border-radius: 2px;
    margin: 0 auto 16px;
  }

  /* Level up modal: ensure buttons are tappable */
  .levelup-hp-choices {
    flex-direction: column;
    gap: 10px;
  }

  .levelup-hp-btn {
    min-height: 46px;
    font-size: 13px;
  }


  /* ─────────────────────────────────────────────────────────────
     PARTY MEMBER MODAL — full screen on mobile
  ───────────────────────────────────────────────────────────── */
  .pm-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .pm-box {
    border-radius: 22px 22px 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    animation: sheetUp var(--screen-dur) var(--screen-ease) both;
  }

  .pm-box::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: rgba(201,168,76,0.25);
    border-radius: 2px;
    margin: 0 auto 14px;
  }

  .pm-tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }
  .pm-tabs::-webkit-scrollbar { display: none; }


  /* ─────────────────────────────────────────────────────────────
     LEVEL-UP BANNER — always visible above bottom nav
  ───────────────────────────────────────────────────────────── */
  #levelup-banner {
    bottom: calc(var(--bottom-nav-h) + 8px);
    left: 10px;
    right: 10px;
    /* Desktop uses left:50% + translateX(-50%). Reset both for mobile. */
    transform: none;
    border-radius: 12px;
  }


  /* ─────────────────────────────────────────────────────────────
     QUEST INTRO MODAL — full screen, scroll within
  ───────────────────────────────────────────────────────────── */
  #quest-intro-modal {
    padding-bottom: var(--bottom-nav-h);
  }

  #quest-intro-actions {
    padding: 0 14px 16px;
    gap: 10px;
    display: flex;
    flex-direction: column;
  }

  .qi-action-btn {
    font-size: 14px;
    padding: 12px 16px;
    min-height: 48px;
    text-align: left;
    line-height: 1.4;
    border-radius: 10px;
  }


  /* ─────────────────────────────────────────────────────────────
     TTS SETTINGS MODAL — bottom sheet
  ───────────────────────────────────────────────────────────── */
  .tts-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .tts-grimoire {
    border-radius: 22px 22px 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    animation: sheetUp var(--screen-dur) var(--screen-ease) both;
  }

  /* Drag-pill (overrides the @600px rule but same visual) */
  .tts-grimoire::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(201,168,76,0.25);
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
  }

  /* Single-column voice grid on all mobile widths */
  .tts-voice-grid { grid-template-columns: 1fr; }

  /* Full-width footer buttons */
  .tts-grim-footer  { flex-direction: column; gap: 8px; padding: 10px 16px 18px; }
  .tts-cancel-btn, .tts-save-btn { width: 100%; text-align: center; padding: 11px 16px; }

  /* Bigger tap targets */
  .tts-fx-expand-btn, .tts-npc-fx-btn { min-height: 32px; }
  .tts-npc-row { min-height: 44px; }


  /* ─────────────────────────────────────────────────────────────
     GLOBAL TAP TARGET FLOOR
     Only on elements that need it — NOT on the nav (handled above)
  ───────────────────────────────────────────────────────────── */
  .tab-btn,
  .combat-action-btn,
  .levelup-hp-btn,
  .battle-summary-close-x,
  .battle-summary-continue-btn,
  .revival-btn,
  .qc-btn,
  .pm-tab-btn,
  .pm-remove-party-btn,
  .pm-remove-confirm-btn,
  .pm-remove-cancel-btn,
  #roll-btn {
    min-height: 44px;
  }

}
/* ── End of mobile app mode ─────────────────────────────────── */
