/* ============================================================
   layout.css — Page structure: sidebar, main column, page title
   Edit here for structural/spacing changes.
   ============================================================ */

/* ── PAGE SHELL ── */
body {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 230px;
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  overflow-y: auto;
  z-index: 100;
  padding: 0 0 2rem 0;
  border-right: 3px solid var(--gold);
  box-shadow: 4px 0 18px rgba(0, 0, 0, 0.6);
}

#sidebar-header {
  background: var(--page-bg);
  padding: 1.4rem 1rem 1rem;
  border-bottom: 2px solid var(--gold);
  text-align: center;
}

.sidebar-home {
  display: block;
  font-size: 0.7rem;
  color: #7a5a30;
  text-decoration: none;
  letter-spacing: 0.05em;
  margin-bottom: 0.6rem;
  transition: color 0.15s;
}

.sidebar-home:hover { color: var(--gold-light); }

#sidebar-header .title {
  font-size: 1.05rem;
  font-weight: bold;
  color: var(--gold-light);
  letter-spacing: 0.04em;
  line-height: 1.3;
}

#sidebar-header .subtitle {
  font-size: 0.72rem;
  color: #b89060;
  margin-top: 0.3rem;
  font-style: italic;
}

#sidebar nav {
  padding: 0.8rem 0;
}

#sidebar nav a {
  display: block;
  padding: 0.45rem 1.2rem;
  color: #d4b88a;
  text-decoration: none;
  font-size: 0.82rem;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1.35;
}

#sidebar nav a:hover,
#sidebar nav a.active {
  background: rgba(200, 160, 80, 0.15);
  border-left-color: var(--gold-light);
  color: var(--gold-light);
}

#sidebar nav .section-label {
  display: block;
  padding: 0.9rem 1.2rem 0.3rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #7a5a30;
  font-family: 'Georgia', serif;
}

#sidebar nav a.sub {
  padding-left: 1.9rem;
}

/* ── MAIN CONTENT COLUMN ── */
#main {
  margin-left: 230px;
  margin-right: 280px;
  flex: 1;
  max-width: 960px;
  padding: 2.5rem 2.5rem 4rem;
}

/* ── NOTES PANEL ── */
#notes-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 280px;
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-left: 3px solid var(--gold);
  box-shadow: -4px 0 18px rgba(0,0,0,0.6);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.notes-header {
  background: var(--page-bg);
  padding: 1.2rem 1rem 0.8rem;
  border-bottom: 2px solid var(--gold);
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-light);
  text-align: center;
  position: relative;
}

#notes-export-btn {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid rgba(160, 120, 48, 0.4);
  border-radius: 3px;
  color: rgba(255,255,255,0.45);
  font-size: 0.65rem;
  font-weight: normal;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.4rem;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}

#notes-export-btn:hover {
  color: var(--gold-light);
  border-color: var(--gold);
}

#notes-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
  transition: background 0.15s;
}

#notes-resize-handle:hover { background: rgba(160, 120, 48, 0.35); }

.notes-section {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid rgba(160, 120, 48, 0.25);
}

.notes-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #7a5a30;
  margin-bottom: 0.5rem;
}

/* ── NOTE TABS ── */
#notes-tabs-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0.5rem 0.75rem 0;
  flex-wrap: wrap;
}

.notes-tab-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0.2rem 0.5rem;
  border-radius: 3px 3px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  cursor: pointer;
  background: transparent;
  transition: background 0.12s;
}

.notes-tab-pill:hover { background: rgba(255,255,255,0.05); }

.notes-tab-pill.active {
  background: rgba(0,0,0,0.25);
  border-color: rgba(160,120,48,0.3);
}

.notes-tab-pill-name {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.72);
  white-space: nowrap;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.notes-tab-pill.active .notes-tab-pill-name { color: var(--gold-light); }

.notes-tab-pill-del {
  background: transparent;
  border: none;
  color: transparent;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.1s;
}

.notes-tab-pill:hover .notes-tab-pill-del { color: rgba(255,255,255,0.25); }
.notes-tab-pill-del:hover { color: #dd8a8a !important; }

.notes-tab-add {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.25);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.3rem;
  transition: color 0.12s;
}

.notes-tab-add:hover { color: var(--gold-light); }

.notes-tab-rename {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--gold);
  border-radius: 2px;
  color: #e8dfc8;
  font-size: 0.82rem;
  padding: 0.1rem 0.3rem;
  width: 70px;
  outline: none;
}

#notes-tabs-content {
  border-top: 1px solid rgba(160,120,48,0.3);
}

#notes-tab-textarea {
  width: 100%;
  min-height: 140px;
  background: rgba(0,0,0,0.25);
  border: none;
  color: var(--sidebar-text);
  font-family: 'Georgia', serif;
  font-size: 0.92rem;
  line-height: 1.5;
  padding: 0.5rem;
  resize: vertical;
}

#notes-tab-textarea:focus { outline: none; }
#notes-tab-textarea::placeholder { color: #4a3a20; }

.notes-npc-row {
  margin-bottom: 0.8rem;
}

.notes-npc-name {
  font-size: 0.78rem;
  color: #d4b88a;
  margin-bottom: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notes-npc-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.notes-pill {
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  border: 1px solid #444;
  background: transparent;
  color: #666;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: all 0.15s;
}

.notes-pill--alive.active   { background: #1a4a2a; border-color: #2a7a42; color: #7dda8a; }
.notes-pill--dead.active    { background: #4a1a1a; border-color: #8b2a2a; color: #dd8a8a; }
.notes-pill--allied.active  { background: #1a3a5c; border-color: #2a5a9c; color: #8ab4dd; }
.notes-pill--hostile.active { background: #4a2a1a; border-color: #8b4a2a; color: #ddaa8a; }

.npc-status--dead    { opacity: 0.55; filter: grayscale(0.6); }
.npc-status--allied  { box-shadow: 0 0 0 2px #2a5a9c; }
.npc-status--hostile { box-shadow: 0 0 0 2px #8b2a2a; }

/* ── NOTES TABS ── */
.notes-tabs {
  display: flex;
  border-bottom: 2px solid var(--gold);
}

.notes-tab {
  flex: 1;
  padding: 0.5rem 0;
  background: transparent;
  border: none;
  color: #7a5a30;
  font-size: 0.72rem;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.notes-tab.active {
  color: var(--gold-light);
  background: rgba(160,120,48,0.1);
}

.notes-tab-content { display: none; }
.notes-tab-content.active { display: block; }

/* ── COMBAT TRACKER ── */

/* Roster rows */
.combat-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem;
  border-radius: 3px;
}

.combat-row:hover { background: rgba(255,255,255,0.04); }

/* In-combat rows: 5-column grid */
.combat-row.in-combat {
  display: grid;
  grid-template-columns: 26px 1fr 58px 26px 16px;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.4rem;
  border-radius: 3px;
}

/* Column header row */
.combat-table-header {
  display: grid;
  grid-template-columns: 26px 1fr 58px 26px 16px;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.4rem 0.4rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 0.15rem;
}

.combat-table-header span {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.85);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.combat-table-header span:nth-child(2) {
  text-align: left;
  justify-content: flex-start;
}

/* Two overlapping dice for initiative column */
.combat-hdr-init {
  display: flex;
  align-items: center;
  justify-content: center;
}
.combat-hdr-init .d1,
.combat-hdr-init .d2 {
  font-size: 0.82rem;
  line-height: 1;
}
.combat-hdr-init .d2 { margin-left: -0.18em; opacity: 0.7; }

/* Heart should match shield visually */
.combat-table-header span:nth-child(3) { font-size: 1.25rem; }

/* Shared roster name */
.combat-name {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Name column (in-combat) */
.combat-name-col {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  overflow: hidden;
  min-width: 0;
}

.combat-name-text {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.88);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.combat-name-text:hover { color: #fff; }

/* Remove/delete buttons — invisible until row hover */
.combat-remove-btn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.55);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 16px;
  text-align: center;
  transition: color 0.1s;
}

.combat-remove-btn:hover { color: #dd8a8a; }

/* HP column */
.combat-hp-col {
  display: flex;
  align-items: baseline;
  gap: 0;
  justify-content: flex-end;
}

/* Current HP — transparent input, looks like plain text */
.combat-cur-hp-input {
  width: 28px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.88);
  font-size: 0.92rem;
  text-align: right;
  padding: 0;
  font-family: inherit;
}

.combat-cur-hp-input:focus {
  outline: none;
  background: rgba(255,255,255,0.07);
  border-radius: 2px;
}

/* Hide number spinners */
.combat-cur-hp-input::-webkit-outer-spin-button,
.combat-cur-hp-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.combat-cur-hp-input[type=number] { -moz-appearance: textfield; }

.combat-cur-hp-display {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.88);
  font-family: inherit;
  cursor: pointer;
  min-width: 20px;
  text-align: right;
}

.combat-cur-hp-display:hover { color: #fff; }
.combat-cur-hp-display.hp-dead { color: #dd8a8a; }
.combat-cur-hp-display.hp-low  { color: #ddaa66; }
.combat-cur-hp-input.hp-dead { color: #dd8a8a; }
.combat-cur-hp-input.hp-low  { color: #ddaa66; }

.combat-hp-sep { color: rgba(255,255,255,0.45); font-size: 0.88rem; margin: 0 1px; }

.combat-max-hp {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.58);
  cursor: pointer;
  min-width: 16px;
  text-align: left;
}

.combat-max-hp:hover { color: rgba(255,255,255,0.6); }

/* AC column */
.combat-ac-cell {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.88);
  text-align: center;
  cursor: pointer;
  display: block;
}

.combat-ac-cell:hover { color: #fff; }

/* Initiative input — transparent, looks like a bold number */
.combat-init-input {
  width: 100%;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 1rem;
  font-weight: bold;
  text-align: center;
  padding: 0;
  font-family: inherit;
}

.combat-init-input:focus {
  outline: none;
  background: rgba(255,255,255,0.07);
  border-radius: 2px;
}

.combat-init-input::-webkit-outer-spin-button,
.combat-init-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.combat-init-input[type=number] { -moz-appearance: textfield; }

/* Roster + button */
.combat-hp-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 3px;
  color: rgba(255,255,255,0.55);
  font-size: 0.8rem;
  width: 18px;
  height: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: border-color 0.1s, color 0.1s;
}

.combat-hp-btn:hover { border-color: rgba(255,255,255,0.4); color: rgba(255,255,255,0.7); }

#combat-btn-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.1rem;
}

#combat-reset-all,
#combat-roll-all {
  flex: 1;
  border-radius: 3px;
  padding: 0.3rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#combat-reset-all {
  background: rgba(120,40,40,0.15);
  border: 1px dashed #8b3a3a;
  color: #c07070;
}
#combat-reset-all:hover { background: rgba(140,40,40,0.3); color: #e09090; }

#combat-roll-all {
  background: rgba(48,100,48,0.15);
  border: 1px dashed #4a8a4a;
  color: #7db87d;
}
#combat-roll-all:hover { background: rgba(48,100,48,0.3); color: #9dd09d; }

.combat-add-player-btn {
  background: transparent;
  border: 1px dashed #a07830;
  color: #a07830;
  border-radius: 3px;
  padding: 0.1rem 0.45rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.combat-add-player-btn:hover { background: rgba(160,120,48,0.2); color: var(--gold-light); }

.combat-name-input {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--gold);
  border-radius: 3px;
  color: #e8dfc8;
  font-size: 0.9rem;
  padding: 0.15rem 0.4rem;
  width: 100%;
  font-family: 'Georgia', serif;
}

.combat-name-input:focus { outline: none; }
.combat-row.is-player { border-left-color: #8ab4dd; }

/* ── STATBLOCK HOVER POPUP ── */
#sb-popup {
  position: fixed;
  right: 284px;
  top: 60px;
  width: 340px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--parchment);
  border: 2px solid var(--gold);
  border-radius: 4px;
  box-shadow: -4px 4px 20px rgba(0,0,0,0.6);
  z-index: 300;
  padding: 1rem;
  display: none;
}

/* ── PAGE TITLE BLOCK ── */
.page-title {
  text-align: center;
  padding: 2.5rem 2rem 2rem;
  background: var(--parchment-dark);
  border: 3px solid var(--gold);
  border-radius: 4px;
  margin-bottom: 2.5rem;
  box-shadow: 0 4px 20px var(--shadow);
  position: relative;
}

.page-title::before,
.page-title::after {
  content: '⬥';
  position: absolute;
  color: var(--gold);
  font-size: 1.2rem;
  top: 50%;
  transform: translateY(-50%);
}

.page-title::before { left: 1.2rem; }
.page-title::after  { right: 1.2rem; }

.page-title h1 {
  font-size: 2.6rem;
  color: var(--red);
  letter-spacing: 0.05em;
  text-shadow: 1px 1px 0 var(--parchment-dark), 2px 2px 3px rgba(0, 0, 0, 0.2);
  line-height: 1.15;
}

.page-title .tagline {
  font-size: 1rem;
  color: var(--gold);
  font-style: italic;
  margin-top: 0.6rem;
}

.page-title .meta {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.page-title .meta span {
  background: var(--parchment);
  border: 1px solid var(--gold);
  padding: 0.25rem 0.8rem;
  border-radius: 3px;
  font-size: 0.8rem;
  color: var(--ink-light);
}

/* ── SCROLL TO TOP ── */
#top-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--red);
  color: var(--parchment);
  border: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0.85;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

#top-btn:hover { opacity: 1; }

/* ── HOMEPAGE (no sidebar) ── */
body.homepage {
  display: block;
}

body.homepage #main {
  margin-left: auto;
  margin-right: auto;
  max-width: 1100px;
  padding: 3rem 2rem 5rem;
}

.adventure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 2rem;
  margin-top: 1.5rem;
}

.adventure-card {
  background: var(--parchment);
  border: 1px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 2px 12px var(--shadow);
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.adventure-card:hover {
  box-shadow: 0 4px 22px var(--shadow);
  border-color: var(--gold-light);
}

.adventure-card-banner {
  height: 180px;
  background: var(--parchment-dark);
  border-bottom: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
}

.adventure-card-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.adventure-card-body {
  padding: 1.1rem 1.3rem 1.4rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.adventure-card-title {
  font-size: 1.2rem;
  color: var(--red);
  font-weight: bold;
  letter-spacing: 0.02em;
  margin-bottom: 0.3rem;
}

.adventure-card-type {
  font-size: 0.75rem;
  color: var(--gold);
  font-style: italic;
  margin-bottom: 0.7rem;
}

.adventure-card-desc {
  font-size: 0.88rem;
  color: var(--ink-light);
  line-height: 1.5;
  flex: 1;
}

.adventure-card-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.adventure-card-meta .stat-pill {
  font-size: 0.72rem;
}

.adventure-card--placeholder {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
  border-style: dashed;
}

.adventure-card--placeholder .adventure-card-banner {
  background: var(--page-bg);
  filter: grayscale(1);
}

/* ── MOBILE TOGGLE BUTTONS ── */
#sidebar-toggle,
#notes-toggle {
  display: none;
}

/* Prevent any overflowing content from causing the browser to zoom out */
@media (max-width: 767px) {
  html { overflow-x: hidden; }
}

/* ── RESPONSIVE ── */
@media (max-width: 767px) {
  /* Toggle buttons */
  #sidebar-toggle,
  #notes-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0.6rem;
    z-index: 200;
    width: 2.4rem;
    height: 2.4rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--gold);
    border-radius: 4px;
    color: var(--gold-light);
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  }

  #sidebar-toggle { left: 0.6rem; }
  #notes-toggle   { right: 0.6rem; }

  /* Backdrop */
  #mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 99;
  }

  #mobile-backdrop.active { display: block; }

  /* Sidebar: slide off left, overlay on open */
  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 150;
  }

  #sidebar.mobile-open { transform: translateX(0); }

  /* Notes panel: slide off right, overlay on open */
  #notes-panel {
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 150;
    width: min(320px, 90vw) !important;
  }

  #notes-panel.mobile-open { transform: translateX(0); }

  /* Main: fill screen, top padding for toggle buttons */
  #main {
    margin-left: 0;
    margin-right: 0;
    padding: 3.5rem 1.25rem 4rem;
  }

  /* Hide resize handle — no drag-to-resize on touch */
  #notes-resize-handle { display: none; }

  /* Statblock popup: centre instead of fixed left-of-panel */
  #sb-popup {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    width: 90vw;
    max-width: 360px;
  }

  /* Adventure grid: single column */
  .adventure-grid {
    grid-template-columns: 1fr;
  }

  /* NPC grid: single column */
  .npc-grid {
    grid-template-columns: 1fr;
  }

  /* Page title: smaller h1 so it doesn't wrap badly */
  .page-title h1 { font-size: 1.8rem; }
}
