/* =====================================================================
   KK BOARD VAULT — PORTAL SHELL STYLESHEET
   Tabletop Vault Dark / Warm Parchment Light Theme
   ===================================================================== */

:root {
  /* Common metrics */
  --sidebar-collapsed-w: 68px;
  --sidebar-expanded-w: 280px;
  --header-height: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);

  /* Fonts */
  --font-display: 'Cinzel', Georgia, serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ----------------- DARK THEME (Default) ----------------- */
[data-theme="dark"] {
  --bg-canvas: #0c0e14;
  --bg-surface: #141722;
  --bg-surface-elevated: #1b2030;
  --bg-surface-card: #161a27;
  --bg-surface-hover: #22283a;
  
  --border-subtle: #242a3e;
  --border-strong: #363e59;
  --border-focus: #e5a93c;

  --text-main: #f3f4f6;
  --text-muted: #9ba3b4;
  --text-subtle: #636c82;
  --text-gold: #fbbf24;

  --accent-gold: #e5a93c;
  --accent-gold-hover: #f59e0b;
  --accent-gold-glow: rgba(229, 169, 60, 0.18);
  --accent-blue: #38bdf8;

  --shadow-flyout: 10px 0 35px rgba(0, 0, 0, 0.55);
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-card-hover: 0 10px 30px rgba(0, 0, 0, 0.5);
  --frame-bg: #080a0f;
}

/* ----------------- LIGHT THEME (Warm Parchment) ----------------- */
[data-theme="light"] {
  --bg-canvas: #f5f2ea;
  --bg-surface: #fdfbf7;
  --bg-surface-elevated: #eae4d5;
  --bg-surface-card: #ffffff;
  --bg-surface-hover: #efe9dc;

  --border-subtle: #ded6c5;
  --border-strong: #c2b59d;
  --border-focus: #b47814;

  --text-main: #1e242b;
  --text-muted: #5f6874;
  --text-subtle: #8a94a2;
  --text-gold: #996206;

  --accent-gold: #b47814;
  --accent-gold-hover: #8f5d08;
  --accent-gold-glow: rgba(180, 120, 20, 0.12);
  --accent-blue: #0284c7;

  --shadow-flyout: 10px 0 30px rgba(70, 50, 20, 0.15);
  --shadow-card: 0 4px 16px rgba(80, 60, 30, 0.08);
  --shadow-card-hover: 0 10px 24px rgba(80, 60, 30, 0.14);
  --frame-bg: #f8f6f0;
}

/* ----------------- GLOBAL RESET & BASE ----------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-canvas);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ----------------- APP LAYOUT ----------------- */
.vault-app {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ----------------- GLOBAL SIDEBAR ----------------- */
.global-sidebar {
  position: relative;
  width: var(--sidebar-collapsed-w);
  height: 100%;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 100;
  transition: width var(--transition-normal);
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-expanded-w);
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Hover expansion when unpinned */
.global-sidebar:not(.pinned) {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-collapsed-w);
  overflow: hidden;
  transition: width var(--transition-normal), box-shadow var(--transition-normal);
}

.global-sidebar:not(.pinned):hover,
.global-sidebar.mobile-open {
  width: var(--sidebar-expanded-w);
  box-shadow: var(--shadow-flyout);
}

/* When pinned */
.global-sidebar.pinned {
  position: relative;
  width: var(--sidebar-expanded-w);
  box-shadow: none;
}

/* Sidebar Header / Brand */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 14px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 10px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  font-size: 26px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--accent-gold-glow);
  border: 1px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.global-sidebar.pinned .brand-text,
.global-sidebar:hover .brand-text,
.global-sidebar.mobile-open .brand-text {
  opacity: 1;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-gold);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-pin-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
  opacity: 0;
}

.global-sidebar.pinned .sidebar-pin-btn,
.global-sidebar:hover .sidebar-pin-btn {
  opacity: 1;
}

.sidebar-pin-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.global-sidebar.pinned .sidebar-pin-btn {
  color: var(--accent-gold);
  background: var(--accent-gold-glow);
}

.icon-pin {
  width: 16px;
  height: 16px;
}

/* Sidebar Search */
.sidebar-search {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  height: 38px;
  padding: 0 10px;
  gap: 8px;
}

.search-icon {
  width: 16px;
  height: 16px;
  color: var(--text-subtle);
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 13px;
}

.search-input::placeholder {
  color: var(--text-subtle);
}

.search-clear-btn {
  font-size: 16px;
  color: var(--text-muted);
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  padding: 14px 8px;
  overflow-y: auto;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  padding: 4px 12px 8px;
  white-space: nowrap;
}

.game-nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.game-nav-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.game-nav-item a:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.game-nav-item.active a {
  background: var(--accent-gold-glow);
  color: var(--accent-gold);
  font-weight: 600;
  border: 1px solid rgba(229, 169, 60, 0.3);
}

.nav-game-icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.nav-game-title {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.nav-game-pill {
  font-size: 10px;
  padding: 2px 6px;
  background: var(--bg-surface-elevated);
  border-radius: 12px;
  color: var(--text-subtle);
}

/* Sidebar Footer Utilities */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  border-top: 1px solid var(--border-subtle);
  gap: 4px;
}

.util-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.util-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.util-icon {
  font-size: 18px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

/* ----------------- MAIN STAGE ----------------- */
.main-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  margin-left: 0;
  transition: margin-left var(--transition-normal);
}

/* Adjust stage when unpinned sidebar takes space */
.global-sidebar:not(.pinned) ~ .main-stage {
  margin-left: var(--sidebar-collapsed-w);
}

/* ----------------- PER-GAME HEADER ----------------- */
.per-game-header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 50;
}

.header-game-info {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.mobile-menu-btn {
  display: none;
  font-size: 20px;
  color: var(--text-main);
  padding: 6px;
}

.game-meta-cluster {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.game-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-header-icon {
  font-size: 22px;
}

.game-header-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-header-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  background: var(--accent-gold-glow);
  color: var(--accent-gold);
  border: 1px solid rgba(229, 169, 60, 0.3);
  border-radius: 12px;
  white-space: nowrap;
}

.game-subtitle-row {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header Center Tools (Theme Variants) */
.header-center-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface-elevated);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.variant-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.variant-select {
  background: transparent;
  color: var(--text-main);
  border: none;
  outline: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.variant-select option {
  background-color: var(--bg-surface);
  color: var(--text-main);
}

/* Header Nav Tabs */
.header-nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.tab-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--accent-gold);
  border-color: var(--accent-gold);
  box-shadow: 0 0 12px var(--accent-gold-glow);
}

.tab-icon {
  font-size: 15px;
}

/* ----------------- MAIN VIEWPORT ----------------- */
.main-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-canvas);
}

/* ----------------- VIEW 1: SHELF (HOME) ----------------- */
.shelf-view {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 36px 40px 60px;
}

.shelf-hero {
  max-width: 800px;
  margin-bottom: 32px;
}

.hero-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--accent-gold-glow);
  color: var(--accent-gold);
  border: 1px solid var(--accent-gold);
  margin-bottom: 12px;
}

.hero-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-main);
  margin-bottom: 8px;
}

.hero-description {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
}

.shelf-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  gap: 12px;
}

.shelf-stats {
  font-size: 13px;
  color: var(--text-muted);
}

.shelf-filters {
  display: flex;
  gap: 8px;
}

.filter-pill {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.filter-pill:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.filter-pill.active {
  background: var(--accent-gold-glow);
  color: var(--accent-gold);
  border-color: var(--accent-gold);
}

/* Game Cards Grid */
.game-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 24px;
}

.game-card {
  background: var(--bg-surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 22px;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-card);
}

.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-gold);
  box-shadow: var(--shadow-card-hover);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-icon {
  font-size: 32px;
  width: 52px;
  height: 52px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  background: var(--bg-surface-elevated);
  border-radius: 12px;
  color: var(--text-gold);
  border: 1px solid var(--border-subtle);
}

.card-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.card-tagline {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
  flex: 1;
}

.card-specs {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  padding: 8px 12px;
  background: var(--bg-canvas);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-muted);
}

.spec-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.btn-card-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-gold);
  color: #000000;
  font-weight: 600;
  font-size: 13px;
  transition: background var(--transition-fast);
}

.btn-card-primary:hover {
  background: var(--accent-gold-hover);
}

.btn-card-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 13px;
  transition: all var(--transition-fast);
}

.btn-card-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

/* ----------------- VIEWPORT FRAMES (Prototype & PDF) ----------------- */
.viewport-frame-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--frame-bg);
}

.frame-toolbar {
  height: 36px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.toolbar-status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.tool-btn {
  font-size: 11px;
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
}

.tool-btn:hover {
  color: var(--text-main);
  border-color: var(--border-strong);
}

.game-iframe, .pdf-iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
}

/* ----------------- VIEW 4: REFERENCE & FAQ ----------------- */
.reference-view {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 40px 20px 80px;
}

.reference-container {
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg-surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 40px;
  box-shadow: var(--shadow-card);
}

/* Prose Typography for Markdown Reference */
.prose h1 {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--text-main);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 12px;
}

.prose h2 {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--text-gold);
  margin-top: 28px;
  margin-bottom: 12px;
}

.prose h3 {
  font-size: 16px;
  color: var(--text-main);
  margin-top: 18px;
  margin-bottom: 8px;
}

.prose p {
  color: var(--text-main);
  margin-bottom: 14px;
  line-height: 1.7;
}

.prose ul, .prose ol {
  margin-left: 24px;
  margin-bottom: 16px;
  color: var(--text-main);
}

.prose li {
  margin-bottom: 6px;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 24px 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
}

.prose th, .prose td {
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.prose th {
  background: var(--bg-surface-elevated);
  font-weight: 600;
  color: var(--text-gold);
}

.prose tr:nth-child(even) td {
  background: var(--bg-canvas);
}

/* ----------------- VIEW 5: COMPONENTS GALLERY ----------------- */
.components-view {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 36px 40px 60px;
}

.components-container {
  max-width: 1000px;
  margin: 0 auto;
}

.components-header {
  margin-bottom: 24px;
}

.components-header h2 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--text-main);
  margin-bottom: 6px;
}

.components-header p {
  color: var(--text-muted);
  font-size: 14px;
}

.components-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.component-card {
  background: var(--bg-surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.comp-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin-bottom: 8px;
}

.comp-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.comp-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
  flex: 1;
}

.comp-actions {
  display: flex;
  gap: 8px;
}

/* ----------------- ERROR VIEW ----------------- */
.error-view {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 40px;
}

.error-card {
  text-align: center;
  max-width: 440px;
  padding: 40px;
  background: var(--bg-surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.error-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

.error-card h2 {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--text-main);
  margin-bottom: 8px;
}

.error-card p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.btn-primary {
  display: inline-block;
  padding: 10px 20px;
  background: var(--accent-gold);
  color: #000;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.btn-primary:hover {
  background: var(--accent-gold-hover);
}

/* ----------------- RESPONSIVE BREAKPOINTS ----------------- */
@media (max-width: 900px) {
  .header-game-subtitle,
  .tab-text {
    display: none;
  }
  .shelf-view {
    padding: 24px 20px;
  }
}

@media (max-width: 640px) {
  .mobile-menu-btn {
    display: block;
  }
  .global-sidebar:not(.pinned) ~ .main-stage {
    margin-left: 0;
  }
  .global-sidebar {
    display: none;
  }
  .global-sidebar.mobile-open {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
  }
}
