/* ═══════════════════════════════════════════════════
   DREADMARK ONLINE — MOBILE STYLES
   Breakpoint: ≤ 768px
   Layout: single-column + slide-up drawers + bottom nav
═══════════════════════════════════════════════════ */

/* ── TOUCH RESETS ── */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects that don't make sense on touch */
  .btn:hover { box-shadow: none; }
  .monster-card:hover { border-color: var(--border-dark); background: rgba(0,0,0,0.6); }
  .class-card:hover .class-card-img-wrap img { transform: none; filter: brightness(0.75) saturate(0.8); }
}

/* ─────────────────────────────────────────────────
   MOBILE LAYOUT ENGINE
───────────────────────────────────────────────── */
@media (max-width: 768px) {

  html, body { overflow: hidden; touch-action: manipulation; }

  /* ── Viewport meta-fix for iOS ── */
  #screen-game { height: 100dvh; }

  /* ── GAME LAYOUT: single column ── */
  #game-layout {
    display: grid;
    grid-template-rows: 44px 1fr auto 58px;
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main"
      "actionbar"
      "mobile-nav";
    height: 100dvh;
    overflow: hidden;
  }

  /* Hide desktop panels */
  #sidebar   { display: none !important; }
  #inv-panel { display: none !important; }
  #minimap   { display: none !important; }

  /* ── TOP BAR ── */
  #topbar {
    height: 44px;
    padding: 0 10px;
    gap: 8px;
  }

  #topbar-logo { font-size: 11px; letter-spacing: 2px; }
  #topbar-divider { display: none; }

  #player-info-bar {
    flex: 1;
    gap: 6px;
  }

  #player-name-bar { font-size: 11px; }
  #player-level-bar { font-size: 10px; white-space: nowrap; }

  .topbar-xp-wrap {
    flex: 1;
    max-width: 120px;
  }

  .topbar-xp-label { display: none; }

  #topbar-right { gap: 6px; }
  #topbar-right .btn { display: none; } /* hide desktop buttons */

  /* Gold stays visible */
  .gold-display { font-size: 11px; gap: 3px; }
  .gold-display .gold-icon { font-size: 12px; }

  /* Mobile settings icon in topbar */
  #mobile-topbar-menu {
    display: flex !important;
    background: none;
    border: 1px solid var(--border-dark);
    color: var(--text-dim);
    width: 32px; height: 32px;
    align-items: center; justify-content: center;
    font-size: 16px;
    cursor: pointer;
    border-radius: 3px;
    flex-shrink: 0;
  }

  /* ── MAIN AREA ── */
  #main-area {
    grid-area: main;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
  }

  #arena {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── COMBAT LOG (collapsible on mobile) ── */
  #combat-log-wrap {
    height: var(--log-height, 90px);
    transition: height 0.3s ease;
    flex-shrink: 0;
  }

  #combat-log-wrap.log-expanded { --log-height: 180px; }
  #combat-log-wrap.log-collapsed { --log-height: 32px; }

  #combat-log-wrap .panel-header {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  #combat-log { padding: 4px 8px; }
  .log-entry { font-size: 11px; padding: 2px 0; }

  /* ── ACTION BAR ── */
  #actionbar {
    grid-area: actionbar;
    height: auto;
    min-height: 72px;
    padding: 6px 10px;
    gap: 8px;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  /* Orbs: larger on mobile */
  .orb-container {
    width: 60px; height: 60px;
    flex-shrink: 0;
  }

  .orb-text { font-size: 8px; }

  /* Skill slots: scrollable horizontal row */
  #skill-slots {
    flex: 1;
    display: flex;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: center;
    padding: 0 2px;
  }

  #skill-slots::-webkit-scrollbar { display: none; }

  .skill-slot {
    width: 54px; height: 54px;
    min-width: 54px;
    flex-shrink: 0;
    touch-action: manipulation;
  }

  .skill-icon { font-size: 22px; }

  /* Potion slots */
  #potion-slots { gap: 5px; }

  .potion-slot {
    width: 38px; height: 54px;
    touch-action: manipulation;
  }

  /* Idle button */
  #idle-toggle {
    display: none; /* moved to mobile nav */
  }

  /* Combat actions: bigger touch targets */
  #combat-actions {
    gap: 5px;
    flex-shrink: 0;
  }

  #combat-actions .btn {
    padding: 8px 10px;
    font-size: 11px;
    letter-spacing: 0;
    min-width: 48px;
  }

  /* Area name: hide on mobile (shown in drawer header) */
  #area-name-display { display: none; }

  /* ── MOBILE NAV BAR ── */
  #mobile-nav {
    grid-area: mobile-nav;
    display: flex !important;
    height: 58px;
    background: linear-gradient(180deg, #0d0a10 0%, #080508 100%);
    border-top: 2px solid var(--border-gold);
    align-items: stretch;
  }

  .mob-nav-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border-dark);
    color: var(--text-dim);
    font-family: var(--font-ui);
    font-size: 8px;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    position: relative;
  }

  .mob-nav-btn:last-child { border-right: none; }

  .mob-nav-btn .mob-icon { width: 26px; height: 26px; object-fit: contain; image-rendering: pixelated; flex-shrink: 0; }

  .mob-nav-btn.active {
    color: var(--text-gold);
    background: rgba(100,70,20,0.25);
  }

  .mob-nav-btn.active::after {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 2px;
    background: var(--border-gold-bright);
    border-radius: 0 0 2px 2px;
  }

  .mob-nav-btn.highlight-red { color: #cc3322; }
  .mob-nav-btn.highlight-red.active { color: #ff4433; }

  /* Badge (stat points notif, etc.) */
  .mob-nav-badge {
    position: absolute;
    top: 4px; right: calc(50% - 18px);
    background: #cc2222;
    color: #fff;
    font-size: 8px;
    width: 14px; height: 14px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-ui);
    display: none;
  }

  .mob-nav-badge.visible { display: flex; }

  /* ── DRAWERS ── */
  .mob-drawer {
    position: fixed;
    bottom: 58px; /* above nav bar */
    left: 0; right: 0;
    z-index: 500;
    background: var(--bg-panel);
    border-top: 2px solid var(--border-gold);
    border-left: none; border-right: none;
    max-height: 70dvh;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.7);
  }

  .mob-drawer.open { transform: translateY(0); }

  .mob-drawer-handle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 8px;
    background: linear-gradient(180deg, #1a1218 0%, #130e12 100%);
    border-bottom: 1px solid var(--border-dark);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
  }

  .mob-drawer-title {
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--text-gold);
    letter-spacing: 2px;
    text-transform: uppercase;
  }

  .mob-drawer-close {
    font-size: 16px;
    color: var(--text-dim);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .mob-drawer-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Pull-bar at top of drawer */
  .mob-drawer::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: var(--border-dark);
    border-radius: 2px;
    margin: 8px auto 0;
    flex-shrink: 0;
  }

  /* Drawer backdrop */
  #mob-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 499;
    display: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  #mob-drawer-backdrop.visible { display: block; }

  /* ── CHARACTER DRAWER CONTENT ── */
  #mob-char-drawer .mob-drawer-body {
    padding: 12px 16px;
  }

  .mob-portrait-row {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 14px;
  }

  .mob-portrait-img {
    width: 64px; height: 64px;
    border: 2px solid var(--border-gold);
    border-radius: 3px;
    background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center;
    font-size: 30px;
    flex-shrink: 0;
    overflow: hidden;
  }

  .mob-portrait-img img {
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: top center;
  }

  .mob-char-info { flex: 1; }

  .mob-char-name {
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--text-gold);
  }

  .mob-char-class {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
  }

  /* Bars in drawer */
  .mob-bars { margin-bottom: 12px; }
  .mob-bar-row {
    display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  }
  .mob-bar-label {
    font-family: var(--font-ui);
    font-size: 10px;
    width: 20px;
    text-align: right;
    flex-shrink: 0;
  }
  .mob-bar-outer {
    flex: 1;
    height: 14px;
    background: rgba(0,0,0,0.7);
    border: 1px solid var(--border-dark);
    border-radius: 2px;
    overflow: hidden;
  }
  .mob-bar-val {
    font-family: var(--font-ui);
    font-size: 9px;
    color: var(--text-dim);
    width: 64px;
    text-align: right;
    flex-shrink: 0;
  }

  /* Stat points in drawer */
  .mob-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .mob-stat-row {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border-dark);
    border-radius: 3px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .mob-stat-name {
    font-family: var(--font-ui);
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 1px;
    width: 28px;
  }

  .mob-stat-val {
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--text-gold);
    flex: 1;
  }

  .mob-stat-plus {
    background: rgba(100,70,20,0.5);
    border: 1px solid var(--border-gold);
    color: var(--text-gold);
    width: 28px; height: 28px;
    font-size: 18px;
    border-radius: 2px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    line-height: 1;
  }

  .mob-stat-plus:active { background: rgba(150,100,30,0.7); }

  /* Full stats in drawer */
  .mob-full-stat-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid rgba(107,74,26,0.12);
    font-size: 12px;
  }

  .mob-full-stat-label { color: var(--text-dim); }
  .mob-full-stat-val { color: var(--text-light); font-family: var(--font-ui); }

  .mob-section-title {
    font-family: var(--font-ui);
    font-size: 9px;
    color: var(--text-gold);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 12px 0 6px;
  }

  /* ── MAP DRAWER ── */
  #mob-map-drawer .mob-drawer-body { padding: 6px 0; }

  .mob-area-btn {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(107,74,26,0.2);
    color: var(--text-dim);
    font-family: var(--font-body);
    font-size: 13px;
    padding: 12px 16px;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background 0.15s;
  }

  .mob-area-btn .area-btn-top { display: flex; align-items: center; gap: 8px; }
  .mob-area-btn:active { background: rgba(100,70,20,0.25); }
  .mob-area-btn.active { color: var(--text-gold); border-left: 3px solid var(--border-gold-bright); }
  .mob-area-btn .mob-area-level { font-size: 11px; color: var(--text-dim); margin-left: auto; }

  /* ── INVENTORY DRAWER ── */
  #mob-inv-drawer .mob-drawer-body { display: flex; flex-direction: column; }

  .mob-inv-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-gold);
    flex-shrink: 0;
  }

  .mob-inv-tab {
    flex: 1;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border-dark);
    color: var(--text-dim);
    font-family: var(--font-ui);
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 10px 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: all 0.15s;
  }

  .mob-inv-tab:last-child { border-right: none; }
  .mob-inv-tab.active { color: var(--text-gold); background: rgba(100,70,20,0.2); border-bottom: 2px solid var(--border-gold-bright); }

  .mob-inv-content { flex: 1; overflow-y: auto; padding: 8px; }

  /* Equipment grid in drawer */
  .mob-equip-wrap { padding: 4px; }

  .mob-equip-grid {
    display: grid;
    grid-template-areas:
      ".    head  ."
      "off  chest weapon"
      ".    hands ."
      ".    legs  ."
      ".    feet  .";
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    margin-bottom: 10px;
  }

  .mob-equip-slot {
    aspect-ratio: 1;
    background: rgba(0,0,0,0.6);
    border: 1px solid var(--border-dark);
    border-radius: 3px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: border-color 0.15s;
    min-width: 0;
  }

  .mob-equip-slot:active { background: rgba(100,70,20,0.3); }
  .mob-equip-slot.has-item { border-color: rgba(107,74,26,0.7); }

  .mob-equip-label {
    position: absolute;
    bottom: 2px;
    font-size: 7px;
    color: var(--text-dim);
    font-family: var(--font-ui);
  }

  .mob-equip-slot[data-slot="head"]   { grid-area: head; }
  .mob-equip-slot[data-slot="chest"]  { grid-area: chest; }
  .mob-equip-slot[data-slot="hands"]  { grid-area: hands; }
  .mob-equip-slot[data-slot="legs"]   { grid-area: legs; }
  .mob-equip-slot[data-slot="feet"]   { grid-area: feet; }
  .mob-equip-slot[data-slot="weapon"] { grid-area: weapon; }
  .mob-equip-slot[data-slot="offhand"]{ grid-area: off; }

  .mob-acc-row { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; }

  /* Bag grid in drawer */
  .mob-bag-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
  }

  .mob-inv-cell {
    aspect-ratio: 1;
    background: rgba(0,0,0,0.6);
    border: 1px solid var(--border-dark);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 52px;
  }

  .mob-inv-cell:active { background: rgba(100,70,20,0.3); border-color: var(--border-gold); }

  .mob-inv-count {
    position: absolute;
    bottom: 1px; right: 2px;
    font-family: var(--font-ui);
    font-size: 8px;
    color: var(--text-light);
  }

  .mob-inv-rarity {
    position: absolute;
    top: 1px; left: 1px;
    width: 5px; height: 5px;
    border-radius: 50%;
  }

  /* ── MONSTER CARDS on mobile ── */
  .monster-card {
    padding: 12px 14px;
    min-height: 64px;
  }

  .monster-icon { font-size: 30px; width: 38px; }
  .monster-name { font-size: 13px; }
  .monster-level { font-size: 11px; }

  /* ── COMBAT FLOAT on mobile ── */
  #combat-float {
    padding: 8px;
  }

  .cf-entity { padding: 8px 10px; }

  .cf-name { font-size: 12px; }

  .cf-vs { font-size: 16px; }

  /* ── TOOLTIP: disabled on touch, use bottom sheet instead ── */
  @media (hover: none) and (pointer: coarse) {
    #tooltip { display: none !important; }
  }

  /* ── CONTEXT MENU: bigger items on mobile ── */
  .ctx-item { padding: 13px 18px; font-size: 13px; }

  /* ── DEATH SCREEN on mobile ── */
  .death-text { font-size: 36px; }

  /* ── LEVEL UP on mobile ── */
  #levelup-effect { font-size: 24px; }

  /* ── SETTINGS MODAL on mobile ── */
  .modal { width: 90vw; padding: 20px; }
  .modal h3 { font-size: 16px; }
  .modal .btn { width: 100%; margin-bottom: 6px; }

} /* end @media 768px */

/* ─────────────────────────────────────────────────
   CHAR CREATE — MOBILE (≤ 680px)
───────────────────────────────────────────────── */
@media (max-width: 680px) {
  #screen-charCreate {
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Compact portrait strip at top */
  #cc-portrait-side {
    flex: 0 0 220px;
    min-height: 220px;
    flex-direction: row;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0;
  }

  #cc-portrait-img {
    width: 140px;
    max-width: 140px;
    animation: none;
    position: relative;
    z-index: 2;
    align-self: flex-end;
    filter: drop-shadow(0 0 20px var(--cc-glow-sharp, rgba(200,100,30,0.7)));
  }

  #cc-class-info {
    display: none; /* shown inline in form side */
  }

  /* Show class name in form instead */
  #cc-mobile-class-name {
    display: block !important;
    font-family: var(--font-title);
    font-size: 20px;
    color: var(--cc-text-color, var(--text-gold));
    letter-spacing: 3px;
    text-shadow: 0 0 12px var(--cc-glow-sharp, rgba(200,150,42,0.5));
    text-align: center;
    margin-bottom: 6px;
    transition: color 0.4s, text-shadow 0.4s;
  }

  #cc-mobile-class-lore {
    display: block !important;
    font-size: 11px;
    color: var(--text-dim);
    font-style: italic;
    text-align: center;
    margin-bottom: 14px;
    line-height: 1.6;
    padding: 0 4px;
    transition: opacity 0.3s;
  }

  #cc-form-side {
    flex: 1;
    padding: 16px 18px 24px;
    overflow-y: auto;
  }

  #cc-form-side h2 { font-size: 15px; letter-spacing: 3px; margin-bottom: 4px; }
  #cc-form-subtitle { display: none; }
  .cc-divider { margin-bottom: 14px; }

  .class-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .class-card-img-wrap { aspect-ratio: 2/3; }

  .class-card-footer { padding: 5px 2px 7px; }
  .class-card .class-name { font-size: 8px; letter-spacing: 0.5px; }

  #cc-skill-preview { margin-top: 14px; padding: 10px; }
  #cc-skill-preview-title { font-size: 8px; margin-bottom: 8px; }

  .cc-skill-icon { width: 36px; height: 36px; font-size: 18px; }
  .cc-skill-name { font-size: 7px; }

  .cc-actions { margin-top: 16px; }
  .cc-actions .btn { flex: 1; padding: 12px 8px; font-size: 11px; }
}

/* ─────────────────────────────────────────────────
   TITLE SCREEN — MOBILE
───────────────────────────────────────────────── */
@media (max-width: 480px) {
  .title-logo h1 { font-size: 28px; letter-spacing: 4px; }
  .title-logo .subtitle { font-size: 11px; }
  .title-divider { width: 80vw; }
  .title-buttons .btn { min-width: 200px !important; padding: 14px 20px; font-size: 13px; }
}

/* ─────────────────────────────────────────────────
   LANDSCAPE MOBILE
───────────────────────────────────────────────── */
@media (max-width: 768px) and (orientation: landscape) {
  #game-layout {
    grid-template-rows: 40px 1fr 64px 48px;
  }

  #combat-log-wrap { --log-height: 70px; }

  .orb-container { width: 52px; height: 52px; }
  .skill-slot { width: 48px; height: 48px; min-width: 48px; }
  #actionbar { min-height: 64px; padding: 4px 8px; }

  .mob-drawer { max-height: 85dvh; bottom: 48px; }
}

/* ─────────────────────────────────────────────────
   ALWAYS-ON: hide mobile-only elements on desktop
───────────────────────────────────────────────── */
#mobile-nav            { display: none; }
#mob-drawer-backdrop   { display: none; }
#mob-char-drawer       { display: none; }
#mob-map-drawer        { display: none; }
#mob-inv-drawer        { display: none; }
#mobile-topbar-menu    { display: none; }
#cc-mobile-class-name  { display: none; }
#cc-mobile-class-lore  { display: none; }
