/* ══════════════════════════════════════════════════════════════════════
   guide.css  —  Guide Chrome
   Covers layout used in both viewer and editor modes.
   Editor-only / viewer-only rules at the bottom.
   ══════════════════════════════════════════════════════════════════════ */

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

/* ── CSS VARIABLE DEFAULTS ─────────────────────────────────────────────
   Fallbacks only — real guides load themes.json + palettes.json.
   ─────────────────────────────────────────────────────────────────── */
:root {
  /* Theme */
  --font-body:    Georgia, serif;
  --font-display: Georgia, serif;
  --font-mono:    'Courier New', monospace;
  --radius-card:  8px;
  --radius-btn:   6px;
  --radius-input: 5px;
  --shadow-card:  0 2px 8px rgba(0,0,0,0.08);
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.06);

  /* Layout */
  --header-h: 72px;
  --tabbar-h: 44px;
}

/* ── EDITOR HEADER HARDCODED COLORS ─────────────────────────────────────────
   Only the editor header bar should have hardcoded colors.
   Everything else uses the applied theme.
   ─────────────────────────────────────────────────────────────────── */
body.mode-editor #editor-header {
  --bg:          #0d1117;
  --surface:     #161b22;
  --border:      #30363d;
  --text:        #e6edf3;
  --textMid:     #8b949e;
}

/* ── BACKGROUND IMAGE (optional, set from _00.json bgImage field) ── */
body.has-bg-image {
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
body.has-bg-image #tab-content {
  background: transparent;
}
@media (max-width: 600px) {
  body.has-bg-image {
    background-image: none !important;
  }
  body.has-bg-image #tab-content {
    background: var(--bg);
  }
}

/* ── BODY ── */
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 60px;
}

/* ── GUIDE HEADER ── */
#guide-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--neutralMid);
  border-bottom: 2px solid var(--emphasis);
  padding: 0 16px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.back-link {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--textMuted);
  text-decoration: none;
  white-space: nowrap;
  padding: 5px 9px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-btn);
  transition: color .15s, border-color .15s;
  flex-shrink: 0;
}
.back-link:hover { color: var(--emphasis); border-color: rgba(255,255,255,0.3); }
#guide-icon { font-size: 26px; line-height: 1; flex-shrink: 0; }
.header-text { min-width: 0; flex: 1; }
#guide-title {
  font-family: var(--font-display);
  font-size: clamp(13px, 2.5vw, 19px);
  font-weight: 900;
  color: var(--emphasis);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
#guide-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--textMuted);
  letter-spacing: .4px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.storage-badge {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--positive);
  opacity: .7;
  letter-spacing: .5px;
  white-space: nowrap;
}
.display-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 9px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-btn);
  background: transparent;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.display-btn:hover { color: rgba(255,255,255,0.8); border-color: rgba(255,255,255,0.35); }
.display-btn.overriding { color: var(--emphasis); border-color: var(--emphasis); opacity: 0.9; }
.display-btn.filter-active { color: var(--emphasis); border-color: var(--emphasis); opacity: 0.9; }
.btn-icon { flex-shrink: 0; }
.btn-label { flex-shrink: 0; }

/* ── TAB BAR ── */
#tab-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  background: var(--surface2);
  border-bottom: 2px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-height: var(--tabbar-h);
  overflow-x: auto;
  scrollbar-width: none;
}
#tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  font-family: var(--font-body);
  font-size: 12.5px;
  color: var(--textMuted);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 8px 15px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
  flex-shrink: 0;
  min-height: var(--tabbar-h);
  display: flex;
  align-items: center;
}
.tab-btn:hover { color: var(--textMid); }
.tab-btn.active {
  color: var(--neutral);
  font-weight: 600;
  border-bottom-color: var(--emphasis);
  background: var(--bg);
}

/* ── CONTENT ── */
#tab-content {
  max-width: 70vw;
  margin: 0 auto;
  padding: 20px 16px 0;
  background: var(--bg);
  color: var(--text);
}
#guide-subtitle {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--textMuted);
  padding: 8px 0 14px;
  border-bottom: 1px solid var(--borderL);
  margin-bottom: 16px;
  letter-spacing: .3px;
}

/* ── LOADING / ERROR / EMPTY ── */
.loading-state {
  text-align: center; padding: 60px 20px;
  font-family: var(--font-mono); font-size: 13px; color: var(--textMuted);
}
.loading-dot { display: inline-block; animation: blink 1.2s step-start infinite; }
.loading-dot:nth-child(2) { animation-delay: .4s; }
.loading-dot:nth-child(3) { animation-delay: .8s; }
@keyframes blink { 50% { opacity: 0; } }
.error-state {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid #c04040; border-radius: var(--radius-card);
  padding: 16px 18px; font-family: var(--font-mono); font-size: 12px;
  color: #c04040; margin: 20px 0;
}
.empty-tab {
  text-align: center; padding: 40px 20px;
  font-family: var(--font-mono); font-size: 12px; color: var(--textMuted);
}

/* ── SHOW-REMAINING FILTER ── */
body.show-remaining .gr-check-row.gr-checked { display: none; }

/* ── DISPLAY OVERRIDE SHEET (viewer-only) ── */
#do-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 80; opacity: 0; pointer-events: none; transition: opacity .22s;
}
#do-backdrop.open { opacity: 1; pointer-events: all; }
#do-sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
  background: #161b22; border: 1px solid #30363d;
  border-radius: 18px 18px 0 0;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(0.32,0.72,0,1);
  max-height: 82vh; display: flex; flex-direction: column;
  box-shadow: 0 -6px 36px rgba(0,0,0,0.45);
}
#do-sheet.open { transform: translateY(0); }
#do-sheet-handle { width: 36px; height: 4px; background: #2d3748; border-radius: 2px; margin: 11px auto 0; flex-shrink: 0; }
#do-sheet-header {
  display: flex; align-items: center; padding: 10px 18px;
  border-bottom: 1px solid #30363d; flex-shrink: 0; gap: 10px;
}
#do-sheet-title { font-family: 'Outfit', sans-serif; font-size: 14px; font-weight: 700; color: #e6edf3; flex: 1; }
#do-current { font-family: monospace; font-size: 10px; color: #8b949e; flex-shrink: 0; }
#do-sheet-close {
  width: 26px; height: 26px; border-radius: 50%; background: #1e2530;
  border: none; color: #8b949e; cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
#do-sheet-close:hover { color: #e6edf3; }
#do-sheet-body { flex: 1; overflow-y: auto; padding: 14px 18px 20px; }
.do-section-label {
  font-family: monospace; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; color: #8b949e; margin: 0 0 8px;
}
.do-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.do-card {
  padding: 12px 14px; background: #1e2530; border: 2px solid #30363d;
  border-radius: 8px; cursor: pointer; transition: all .15s;
}
.do-card:hover { border-color: #58a6ff; }
.do-card.active { border-color: #3fb950; background: rgba(63,185,80,0.08); }
.do-card-dots { display: flex; gap: 4px; margin-bottom: 6px; }
.do-dot { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; }
.do-card-name { font-size: 11.5px; font-weight: 600; color: #e6edf3; }
.do-card-desc { font-size: 10px; color: #8b949e; margin-top: 2px; line-height: 1.3; }
#do-reset-row {
  margin-top: 16px; padding-top: 14px; border-top: 1px solid #30363d;
  display: flex; align-items: center; justify-content: space-between;
}
#do-guide-default { font-size: 11px; color: #8b949e; }
#do-guide-default strong { color: #e6edf3; }
#do-reset-btn {
  font-family: monospace; font-size: 11px; padding: 6px 14px;
  border-radius: 5px; border: 1px solid #30363d; background: transparent;
  color: #8b949e; cursor: pointer; transition: all .15s;
}
#do-reset-btn:hover { color: #e6edf3; border-color: #8b949e; }

/* ── PALETTE FILTER CHIPS ── */
.do-filter-row {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px;
}
.do-chip {
  font-family: monospace; font-size: 10px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
  border: 1px solid #30363d; background: #1e2530;
  color: #8b949e; cursor: pointer; transition: all .15s;
  text-transform: uppercase; letter-spacing: 0.5px; line-height: 1.6;
}
.do-chip:hover { border-color: #58a6ff; color: #e6edf3; }
.do-chip.active { background: rgba(88,166,255,0.15); border-color: #58a6ff; color: #58a6ff; }
.do-chip-sep {
  font-family: monospace; font-size: 12px; color: #30363d;
  display: flex; align-items: center; padding: 0 2px;
}

/* ── DYSLEXIA / A11Y TOGGLE ROW ── */
.do-a11y-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0 12px; border-bottom: 1px solid #30363d; margin-bottom: 14px;
}
.do-a11y-label { font-size: 12px; color: #e6edf3; }
.do-toggle {
  font-family: monospace; font-size: 10px; font-weight: 700;
  padding: 4px 14px; border-radius: 20px;
  border: 1px solid #30363d; background: #1e2530;
  color: #8b949e; cursor: pointer; transition: all .15s;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.do-toggle[aria-checked="true"] {
  background: rgba(63,185,80,0.15); border-color: #3fb950; color: #3fb950;
}

/* ── DYSLEXIA FONT OVERRIDE (global a11y preference) ── */
body.a11y-dyslexia,
body.a11y-dyslexia * {
  font-family: 'Lexend', Arial, sans-serif !important;
  letter-spacing: 0.04em;
  line-height: 1.75;
  word-spacing: 0.1em;
}

/* ── CLEAR PROGRESS MODAL (viewer-only) ── */
#clear-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s;
  display: flex; align-items: center; justify-content: center;
}
#clear-backdrop.open { opacity: 1; pointer-events: all; }
#clear-modal {
  background: #1e2530; border: 1px solid #30363d; border-radius: 12px;
  padding: 24px 28px; max-width: 360px; width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#clear-modal-title {
  font-family: monospace; font-size: 14px; font-weight: 700;
  color: #e6edf3; margin-bottom: 10px;
}
#clear-modal-body {
  font-family: monospace; font-size: 12px; color: #8b949e;
  line-height: 1.6; margin-bottom: 20px;
}
#clear-modal-btns { display: flex; gap: 10px; justify-content: flex-end; }
#clear-cancel {
  font-family: monospace; font-size: 12px; padding: 7px 16px;
  border-radius: 6px; border: 1px solid #30363d; background: transparent;
  color: #8b949e; cursor: pointer; transition: all .15s;
}
#clear-cancel:hover { color: #e6edf3; border-color: #8b949e; }
#clear-confirm {
  font-family: monospace; font-size: 12px; padding: 7px 16px;
  border-radius: 6px; border: 1px solid rgba(248,81,73,0.4); background: rgba(248,81,73,0.1);
  color: #f85149; cursor: pointer; transition: all .15s;
}
#clear-confirm:hover { background: rgba(248,81,73,0.2); border-color: #f85149; }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  #guide-header { padding: 0 10px; gap: 8px; }
  #tab-content { padding: 14px 10px 0; }
  .tab-btn { padding: 6px 11px; font-size: 12px; }
  .storage-badge { display: none; }
  .display-btn .btn-label { display: none; }
}

/* ══════════════════════════════════════════════════════════════════════
   MODE VISIBILITY
   body.mode-editor is set by builder.js on init.
   ══════════════════════════════════════════════════════════════════════ */

/* Editor-only elements hidden by default */
.editor-only { display: none; }

/* Viewer-only elements hidden in editor mode */
body.mode-editor .viewer-only { display: none !important; }

/* Reveal editor-only elements in editor mode */
body.mode-editor #editor-header { display: flex; }
body.mode-editor #editor-empty  { display: flex; }
body.mode-editor #edit-meta-btn { display: block; }
/* Don't force display block on backdrop - let it use its fixed positioning and opacity */
body.mode-editor #b-sheet       { display: flex; }

/* Editor mode: keep sticky positioning for navigation */
body.mode-editor #guide-header,
body.mode-editor #tab-bar {
  position: sticky;
  top: 0;
  z-index: 50;
}

body.mode-editor #tab-bar {
  top: var(--header-h);
  z-index: 40;
}

/* Editor mode: content area has no top padding gap (editor header provides spacing) */
body.mode-editor #tab-content { padding-top: 20px; }
