/* ====================================================================== *
 * Idle Realms — responsive.css
 * ----------------------------------------------------------------------- *
 * Overall page layout + responsive behaviour.
 *
 *   DESKTOP  (>= 1201px) : 3-column grid
 *                            left skills  |  center game  |  right inventory
 *                          with a top bar above and an activity log below.
 *   TABLET  (769–1200px) : single center column; the two sidebars collapse
 *                          into slide-in drawers opened via top-bar toggles.
 *   MOBILE  (481–768px)  : single column + fixed bottom tab navigation
 *                          (Skills / Play / Bag). Only the active panel is
 *                          shown; non-essential chrome is hidden.
 *   SMALL   (<= 480px)   : even larger touch targets, denser grids, more
 *                          decoration hidden.
 *
 * BREAKPOINTS (documentary — media queries can't read custom props yet):
 *   --bp-desktop : 1200px     --bp-tablet : 768px     --bp-mobile : 480px
 *
 * TOKENS:
 * `css/components.css` owns the colour/radius/shadow palette. Layout-only
 * tokens (widths, heights, gaps) are declared in the `:root` block below.
 * Every dimension has a literal fallback via `var(--x, fallback)` so the
 * sheet is self-sufficient even before `css/style.css` (TASK-001) ships.
 *
 * MOBILE PANEL SWITCHING
 * The bottom tab bar is driven by `body[data-view="skills|play|bag"]`.
 * `js/core/game.js` (TASK-020) sets that attribute when a tab is tapped.
 * Without JS, the center "play" view is shown by default (see mobile MQ).
 * ====================================================================== */

/* ----------------------------------------------------------------------
   Layout tokens
   ---------------------------------------------------------------------- */
:root {
  /* Named breakpoints — informational only */
  --bp-desktop: 1200px;
  --bp-tablet:   768px;
  --bp-mobile:   480px;

  /* Sizing */
  --sidebar-w:         260px;   /* desktop sidebar column width */
  --sidebar-w-drawer:  300px;   /* tablet/mobile drawer width   */
  --topbar-h:          56px;
  --mobile-nav-h:      60px;
  --grid-gap:          12px;
  --radius-layout:     14px;

  /* Touch target floor (Apple/WCAG recommendation) */
  --touch-min: 44px;
}

/* ----------------------------------------------------------------------
   Base reset — only what layout needs (style.css may extend later)
   ---------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg-app, #0d1117);
  color: var(--text, #e8eaf0);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Idle games fill the viewport; panels scroll internally. */
  overflow: hidden;
  overscroll-behavior: none;
}


/* ====================================================================== *
 * BUTTONS — base (.btn) lives here; components.css styles richer controls.
 * ====================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius, 10px);
  background: var(--bg-elevated, #1f2733);
  color: var(--text, #e8eaf0);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast, 0.15s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)),
              border-color var(--dur-fast, 0.15s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)),
              transform var(--dur-fast, 0.15s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1));
}
.btn:hover  { background: var(--bg-surface, #161c26); border-color: var(--border-strong, rgba(255, 255, 255, 0.16)); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 2px solid var(--accent, #4aa3ff); outline-offset: 2px; }

.btn--ghost {
  min-height: 34px;
  padding: 0 10px;
  background: transparent;
  border-color: var(--border, rgba(255, 255, 255, 0.08));
  color: var(--text-muted, #9aa3b2);
}
.btn--ghost:hover { background: var(--bg-elevated, #1f2733); color: var(--text, #e8eaf0); }


/* ====================================================================== *
 * DESKTOP DEFAULT — 3-column grid
 *   ┌──────────────────────────────────────────────┐
 *   │                 top bar                       │
 *   ├──────────┬───────────────────────┬───────────┤
 *   │  skills  │      game view        │ inventory │
 *   ├──────────┴───────────────────────┴───────────┤
 *   │                activity log                   │
 *   └──────────────────────────────────────────────┘
 * ====================================================================== */
.game-grid {
  display: grid;
  grid-template-columns: var(--sidebar-w, 260px) minmax(0, 1fr) var(--sidebar-w, 260px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "topbar   topbar   topbar"
    "leftbar  gameview rightbar"
    "activity activity activity";
  gap: var(--grid-gap, 12px);
  height: 100vh;
  height: 100dvh;          /* dynamic viewport — handles mobile URL bar */
  padding: var(--grid-gap, 12px);
}

/* Place each region into its named area. */
#top-bar      { grid-area: topbar; }
#sidebar-left { grid-area: leftbar; }
#game-view    { grid-area: gameview; }
#sidebar-right{ grid-area: rightbar; }
#activity-log { grid-area: activity; }

/* Children must be allowed to shrink so internal scroll works. */
.game-grid > * { min-width: 0; min-height: 0; }


/* --- Top bar --------------------------------------------------------- */
.top-bar {
  display: flex;
  align-items: center;
  gap: var(--grid-gap, 12px);
  padding: 8px 14px;
  min-height: var(--topbar-h, 56px);
  background: linear-gradient(180deg, var(--bg-elevated, #1f2733), var(--bg-surface, #161c26));
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-layout, 14px);
  box-shadow: var(--shadow-sm, 0 2px 6px rgba(0, 0, 0, 0.30));
}
.top-bar__section { display: flex; align-items: center; gap: 10px; }
.top-bar__character { flex: 1 1 auto; min-width: 0; }
.top-bar__currencies { flex: 0 0 auto; }
.top-bar__actions { flex: 0 0 auto; gap: 6px; }

.top-bar__avatar { font-size: 22px; line-height: 1; }
.top-bar__char-info { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.top-bar__name { font-weight: 700; font-size: 14px; }
.top-bar__level { font-size: 11.5px; color: var(--text-muted, #9aa3b2); }
.top-bar__stats { display: flex; gap: 12px; margin-left: 6px; }

.stat { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; }
.stat__icon { font-size: 14px; }
.stat__value { font-variant-numeric: tabular-nums; font-weight: 600; }

.currency { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  background: var(--bg-sunken, #0b0f15); border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-pill, 999px); }
.currency__icon { font-size: 14px; }
.currency__value { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold, #ffc83d); }
.currency__label { font-size: 11px; color: var(--text-muted, #9aa3b2); }


/* --- Sidebars (shared) ---------------------------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-surface, #161c26);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-layout, 14px);
  overflow: hidden;
}
.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  background: var(--bg-sunken, #0b0f15);
}
.sidebar__title { margin: 0; font-size: 13px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted, #9aa3b2); }
.sidebar__counter { font-size: 11.5px; color: var(--text-dim, #6b7280); font-variant-numeric: tabular-nums; }

/* Left: scrollable skill list */
#sidebar-left .skill-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
}

/* Right: inventory grid + bank button */
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  align-content: start;
}
.sidebar__bank-btn { margin: 10px; flex: 0 0 auto; }


/* --- Center game view ----------------------------------------------- */
.game-view {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-surface, #161c26);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-layout, 14px);
  overflow: hidden;
}
.game-view__content {
  flex: 1 1 auto;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.game-view__title { margin: 0 0 6px; font-size: 20px; }
.game-view__hint { margin: 0; color: var(--text-muted, #9aa3b2); }


/* --- Activity log (bottom) ------------------------------------------ */
.activity-log {
  display: flex;
  flex-direction: column;
  max-height: 150px;
  min-height: 0;
  background: var(--bg-sunken, #0b0f15);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-layout, 14px);
  overflow: hidden;
}
.activity-log__title { margin: 0; padding: 8px 12px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted, #9aa3b2);
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08)); }
.activity-log__list { list-style: none; margin: 0; padding: 6px 12px;
  overflow-y: auto; overscroll-behavior: contain; font-size: 12.5px; color: var(--text-muted, #9aa3b2); }


/* ====================================================================== *
 * TOUCH-FRIENDLY TARGETS — coarse pointers (phones + most tablets)
 * Lift every interactive control to at least the 44px touch floor without
 * disturbing desktop layouts (mouse pointers stay compact).
 * ====================================================================== */
@media (pointer: coarse) {
  .btn,
  .btn--ghost,
  .tab,
  .modal__close,
  .toast__close,
  .dropdown__item,
  .context-menu__item,
  .mobile-nav__btn,
  .sidebar-toggle {
    min-height: var(--touch-min, 44px);
  }
  .btn--ghost,            /* square icon buttons get square targets */
  .modal__close,
  .toast__close {
    min-width: var(--touch-min, 44px);
  }
}


/* ====================================================================== *
 * TABLET — max-width 1200px
 * Sidebars leave the grid and become slide-in drawers. The center column
 * fills the width; toggles in the top bar open each drawer.
 * ====================================================================== */
@media (max-width: 1200px) {
  .game-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "gameview"
      "activity";
  }

  /* Reveal the drawer toggles (hidden on desktop). */
  .sidebar-toggle { display: inline-flex; }

  /* Sidebars become fixed overlay drawers. */
  .sidebar {
    position: fixed;
    top: calc(var(--topbar-h, 56px) + var(--grid-gap, 12px) * 2);
    bottom: var(--grid-gap, 12px);
    width: min(var(--sidebar-w-drawer, 300px), 86vw);
    z-index: var(--z-sticky, 850);
    box-shadow: var(--shadow-lg, 0 16px 48px rgba(0, 0, 0, 0.55));
    transition: transform var(--dur, 0.25s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)),
                visibility 0s linear var(--dur, 0.25s);
    visibility: hidden;
  }
  #sidebar-left  { left: var(--grid-gap, 12px);  transform: translateX(calc(-100% - 12px)); }
  #sidebar-right { right: var(--grid-gap, 12px); transform: translateX(calc(100% + 12px));  }

  /* body class toggled by game.js when a toggle is pressed */
  body.drawer-left-open  #sidebar-left,
  body.drawer-right-open #sidebar-right {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--dur, 0.25s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1));
  }

  /* Dim + click-to-close backdrop. */
  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-sticky, 850) - 1);
    background: var(--bg-overlay, rgba(8, 11, 16, 0.72));
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--dur, 0.25s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)),
                visibility 0s linear var(--dur, 0.25s);
  }
  body.drawer-left-open .drawer-backdrop,
  body.drawer-right-open .drawer-backdrop {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--dur, 0.25s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1));
  }

  /* Slightly shorter log on tablet so the game view breathes. */
  .activity-log { max-height: 120px; }
}

/* Toggles are hidden by default (desktop); tablet/mobile reveal them. */
.sidebar-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}


/* ====================================================================== *
 * MOBILE — max-width 768px
 * Single column + fixed bottom tab bar. Only one panel is visible at a
 * time, selected via `body[data-view="skills|play|bag"]`.
 * ====================================================================== */
@media (max-width: 768px) {
  :root {
    --topbar-h: 52px;
  }

  .game-grid {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "gameview";
    gap: 0;
    padding: 0;
    /* leave room for the fixed bottom nav */
    height: calc(100dvh - var(--mobile-nav-h, 60px));
  }

  /* --- Activity log hidden on mobile (toasts still cover feedback) --- */
  #activity-log { display: none; }

  /* --- Compact top bar --- */
  .top-bar {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    padding: 6px 10px;
    min-height: var(--topbar-h, 52px);
  }
  .top-bar__avatar { font-size: 20px; }
  .top-bar__name { font-size: 13px; }
  .top-bar__level { font-size: 11px; }
  .top-bar__stats { gap: 8px; }
  .stat { font-size: 12px; }

  /* Hide the tablet drawer toggles — bottom nav takes over. */
  .sidebar-toggle { display: none; }

  /* --- Panels: show only the active one --- */
  #sidebar-left,
  #game-view,
  #sidebar-right { display: none; }

  /* Without JS (no data-view yet), default to the play view. */
  body:not([data-view]) #game-view,
  body[data-view=""] #game-view { display: flex; }

  body[data-view="skills"] #sidebar-left,
  body[data-view="play"]   #game-view,
  body[data-view="bag"]    #sidebar-right { display: flex; }

  /* When a sidebar is the active mobile panel it should read as a normal
     scrolling column, not a floating drawer. */
  #sidebar-left,
  #sidebar-right {
    position: static;
    width: auto;
    transform: none;
    visibility: visible;
    box-shadow: none;
    border-radius: 0;
    border: 0;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  }
  body[data-view="skills"] #sidebar-left,
  body[data-view="bag"]    #sidebar-right {
    grid-area: gameview;   /* occupy the single content row */
  }

  /* Hide backdrop logic isn't needed in single-column mode. */
  .drawer-backdrop { display: none; }

  /* Game view loses its rounded frame on mobile (edge-to-edge). */
  .game-view { border-radius: 0; border: 0; }
  .game-view__content { padding: 12px; }

  /* Skill rows + inventory slots get taller for thumbs. */
  #sidebar-left .skill-list { padding: 10px; gap: 8px; }
  .inventory-grid {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
    padding: 12px;
  }

  /* Show the bottom tab bar. */
  .mobile-nav { display: flex; }
}


/* ====================================================================== *
 * SMALL MOBILE — max-width 480px
 * Maximise touch targets, drop decorative labels, tighten grids.
 * ====================================================================== */
@media (max-width: 480px) {
  /* Currency: keep icon + amount, drop the word "Gold". */
  .currency__label { display: none; }

  /* Hint text + verbose log titles are non-essential here. */
  .game-view__hint { display: none; }

  /* Slightly larger icons in the top bar for glanceability. */
  .top-bar__avatar { font-size: 22px; }

  /* Inventory: 4 comfortable columns on narrow phones. */
  .inventory-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Modal dialogs almost full-bleed on tiny screens. */
  .modal { padding: 0; }
  .modal__dialog {
    max-width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    min-height: 100dvh;
  }

  /* Toasts use more of the narrow viewport. */
  .toast-stack { max-width: calc(100vw - 16px); }
  .toast-stack--br, .toast-stack--tr,
  .toast-stack--bl, .toast-stack--tl { right: 8px; left: 8px; }

  /* Bottom nav labels: icon-led, compact. */
  .mobile-nav__label { font-size: 10px; }
}


/* ====================================================================== *
 * BOTTOM TAB NAVIGATION  (.mobile-nav)
 * Hidden on desktop/tablet; revealed by the 768px breakpoint above.
 * ====================================================================== */
.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sticky, 850);
  display: none;                       /* shown via mobile MQ */
  height: var(--mobile-nav-h, 60px);
  padding-bottom: env(safe-area-inset-bottom, 0);   /* iPhone home bar */
  background: linear-gradient(180deg, var(--bg-elevated, #1f2733), var(--bg-surface, #161c26));
  border-top: 1px solid var(--border-strong, rgba(255, 255, 255, 0.16));
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.35);
}
.mobile-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 100%;
  display: flex;
}
.mobile-nav__btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--touch-min, 44px);
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--text-muted, #9aa3b2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--dur-fast, 0.15s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)),
              background var(--dur-fast, 0.15s) var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1));
}
.mobile-nav__btn:hover,
.mobile-nav__btn:focus-visible { color: var(--text, #e8eaf0); background: var(--bg-elevated, #1f2733); outline: none; }
.mobile-nav__icon { font-size: 20px; line-height: 1; }
.mobile-nav__label { font-size: 11px; letter-spacing: 0.02em; }

/* Active tab mirrors the `body[data-view]` state set by game.js. */
body[data-view="skills"] .mobile-nav__btn[data-view="skills"],
body[data-view="play"]   .mobile-nav__btn[data-view="play"],
body[data-view="bag"]    .mobile-nav__btn[data-view="bag"] {
  color: var(--accent-strong, #6db5ff);
}
body[data-view="skills"] .mobile-nav__btn[data-view="skills"]::after,
body[data-view="play"]   .mobile-nav__btn[data-view="play"]::after,
body[data-view="bag"]    .mobile-nav__btn[data-view="bag"]::after {
  content: "";
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 2px;
  border-radius: 0 0 var(--radius-pill, 999px) var(--radius-pill, 999px);
  background: var(--accent, #4aa3ff);
}
.mobile-nav__btn { position: relative; }


/* ====================================================================== *
 * LANDSCAPE PHONES — give the content row a bit more vertical room
 * ====================================================================== */
@media (max-width: 920px) and (orientation: landscape) and (max-height: 500px) {
  :root { --topbar-h: 44px; --mobile-nav-h: 50px; }
  .top-bar { min-height: var(--topbar-h, 44px); }
  .game-view__content { padding: 8px 12px; }
}


/* ====================================================================== *
 * REDUCED MOTION — kill drawer / nav sliding for users who prefer stillness
 * (component-level motion is already handled in components.css)
 * ====================================================================== */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .drawer-backdrop,
  .mobile-nav__btn,
  .btn,
  .btn--ghost {
    transition: none !important;
  }
}
