/* ================================================================
   Apostle — Global Design System  (teal + orange)
   Fonts: Cinzel (display), Inter (UI) via Google Fonts
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Inter:wght@400;500;600&display=swap');

/* ── Design tokens ──────────────────────────────────────────────── */
:root {
  /* Brand palette */
  --orange:      #E2693C;
  --orange-dim:  rgba(226, 105, 60, 0.55);
  --orange-glow: rgba(226, 105, 60, 0.15);

  /* Kept aliases so old code still compiles */
  --gold:        #E2693C;
  --gold-dim:    rgba(226, 105, 60, 0.55);
  --gold-glow:   rgba(226, 105, 60, 0.15);

  --cream:       #F2EBDC;
  --cream-muted: rgba(242, 235, 220, 0.62);
  --cream-dim:   rgba(242, 235, 220, 0.32);

  /* Teal surface stack (darkest page → lighter cards) */
  --bg:          #0F3D3A;   /* page bg */
  --surface:     #16524D;   /* card bg */
  --surface-2:   #1C615B;   /* nested card / input bg */
  --surface-3:   #0C3330;   /* deep nested */

  --panel-bg:    #0C3330;   /* footer bar backing */
  --border:      rgba(255, 255, 255, 0.12);
  --border-soft: rgba(255, 255, 255, 0.07);

  --success:     #5cbe6c;
  --success-bg:  rgba(92, 190, 108, 0.12);
  --error:       #cf4545;
  --error-bg:    rgba(207, 69, 69, 0.12);
  --warn:        #d4881a;
  --warn-bg:     rgba(212, 136, 26, 0.12);

  /* Layout */
  --footer-h:    86px;
  --panel-w:     98px;      /* main section icon width */
  --max-w:       720px;     /* max content / nav width    */
  --radius:      6px;
  --radius-lg:   10px;
  --transition:  180ms ease;

  --font-display: 'Cinzel', Georgia, serif;
  --font-ui:      'Inter', system-ui, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family:      var(--font-ui);
  font-size:        15px;
  line-height:      1.55;
  color:            var(--cream);
  background-color: var(--bg);
  min-height:    100dvh;
  overflow-x:    hidden;
  /* Pad bottom so footer + section panel never hide content */
  padding-bottom: calc(var(--footer-h) + 16px);
}

img, svg { display: block; }
a { color: var(--orange); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: var(--font-ui); }

/* ── Typography ─────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family:    var(--font-display);
  font-weight:    600;
  line-height:    1.2;
  color:          var(--cream);
  letter-spacing: 0.03em;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

.page-title {
  font-family:    var(--font-display);
  font-size:      1.5rem;
  font-weight:    700;
  color:          var(--orange);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom:  20px;
}

.page-head {
  display:         flex;
  align-items:     baseline;
  justify-content: space-between;
  margin-bottom:   14px;
}
.page-head-brand {
  font-family:    var(--font-display);
  font-size:      1.1rem;
  font-weight:    600;
  color:          var(--cream);
  letter-spacing: 0.04em;
}
.page-head-sub { font-size: 0.8rem; color: var(--cream-muted); }

.section-title {
  font-family:    var(--font-display);
  font-size:      0.8rem;
  font-weight:    600;
  color:          var(--orange);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom:  12px;
}

/* ── Layout ─────────────────────────────────────────────────────── */
.wrap {
  max-width: var(--max-w);
  margin:    0 auto;
  padding:   24px 16px calc(var(--footer-h) + 100px);
}

/* ── Section switcher popup ──────────────────────────────────────── */
/*
  Hover the main icon → 3 other section buttons animate up above it.
  flex-direction:column-reverse so DOM child 1 = bottom of stack.
*/
.section-popup {
  position:       fixed;
  z-index:        410;
  display:        flex;
  flex-direction: column-reverse;
  gap:            8px;
  padding:        8px;
  border-radius:  14px 14px 0 0;
  pointer-events: none;
}
.section-popup.is-open {
  background: var(--panel-bg);
}
/* Animation only — sizing/colour overrides live in .footer-btn.section-popup-btn below */
.section-popup-btn {
  opacity:        0;
  transform:      translateY(12px);
  pointer-events: none;
  transition:     opacity 180ms ease,
                  transform 240ms cubic-bezier(0.34, 1.3, 0.64, 1);
}
.section-popup.is-open                          { pointer-events: auto; }
.section-popup.is-open .section-popup-btn       { opacity: 1; transform: translateY(0); pointer-events: auto; }
.section-popup.is-open .section-popup-btn:nth-child(1) { transition-delay:   0ms; }
.section-popup.is-open .section-popup-btn:nth-child(2) { transition-delay:  50ms; }
.section-popup.is-open .section-popup-btn:nth-child(3) { transition-delay: 100ms; }

/* ── Footer bar ─────────────────────────────────────────────────── */
.footer-nav {
  position:        fixed;
  bottom:          0; left: 0; right: 0;
  height:          var(--footer-h);
  background:      var(--panel-bg);
  border-top:      none;
  z-index:         400;
  display:         flex;
  justify-content: center;
  align-items:     stretch;
  padding-bottom:  env(safe-area-inset-bottom, 0px);
}
.footer-nav-inner {
  display:     flex;
  align-items: stretch;
  width:       100%;
  max-width:   var(--max-w);
  gap:         10px;
  padding:     8px 10px;
}

/* ── Button base ─────────────────────────────────────────────────── */
.footer-btn {
  display:                     flex;
  flex-direction:              column;
  align-items:                 center;
  justify-content:             center;
  gap:                         4px;
  flex:                        1;           /* equal width by default  */
  background:                  transparent;
  border-radius:               10px;
  border:                      none;
  cursor:                      pointer;
  text-decoration:             none;
  -webkit-tap-highlight-color: transparent;
  transition:                  background 150ms ease;
}
.footer-btn-label {
  font-size:      0.66rem;
  font-weight:    500;
  letter-spacing: 0.02em;
  color:          var(--cream-muted);
  user-select:    none;
  pointer-events: none;
  transition:     color 150ms ease;
}
.footer-btn:hover .footer-btn-label { color: var(--cream); }
.footer-btn.is-active .footer-btn-label,
.footer-btn-main.is-home .footer-btn-label { color: var(--orange); font-weight: 600; }
.footer-btn:hover { background: rgba(255, 255, 255, 0.05); }

/* Main (category) button — double width to match popup above it */
.footer-btn-main {
  flex: 2;
}

/* Popup section-switcher buttons — double-class beats .footer-btn specificity */
.footer-btn.section-popup-btn {
  flex:       none;
  width:      100%;
  height:     calc(var(--footer-h) - 16px);  /* match footer button height (footer padding = 8px top + 8px bottom) */
  background: var(--surface);
  box-shadow: none;
}
.footer-btn.section-popup-btn:hover {
  background: var(--surface-2);
  box-shadow: none;
}

/* Icon images — SVGs scale cleanly */
.footer-btn img {
  width:         22px;
  height:        22px;
  display:       block;
  user-select:   none;
  pointer-events:none;
  object-fit:    contain;
  opacity:       0.72;
  transition:    opacity 150ms ease;
}
.footer-btn:hover img,
.footer-btn.is-active img,
.footer-btn-main.is-home img { opacity: 1; }
.footer-btn-main img {
  width:  24px;
  height: 24px;
}

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow:      hidden;
}
.card + .card { margin-top: 14px; }

.card-head {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         14px 18px;
  border-bottom:   1px solid var(--border);
  gap:             10px;
}
.card-head h2 {
  font-family:    var(--font-display);
  font-size:      0.88rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color:          var(--cream);
}
.card-body { padding: 18px; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display:         inline-flex;
  align-items:     center;
  justify-content: center;
  gap:             7px;
  padding:         10px 20px;
  border-radius:   var(--radius);
  font-family:     var(--font-display);
  font-size:       0.78rem;
  font-weight:     600;
  letter-spacing:  0.1em;
  text-transform:  uppercase;
  border:          none;
  cursor:          pointer;
  transition:      opacity var(--transition), background var(--transition), transform 80ms;
  white-space:     nowrap;
}
.btn:active   { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; pointer-events: none; }

.btn-primary { background: var(--orange); color: #002222; }
.btn-primary:hover { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  color:      var(--cream-muted);
  border:     1px solid var(--border-soft);
}
.btn-ghost:hover { color: var(--cream); border-color: var(--orange-dim); }

.btn-danger {
  background: var(--error-bg);
  color:      var(--error);
  border:     1px solid rgba(207, 69, 69, 0.25);
}
.btn-danger:hover { background: rgba(207, 69, 69, 0.22); }

.btn-sm   { padding: 6px 12px; font-size: 0.7rem; }
.btn-full { width: 100%; }

/* Legacy auth CTA */
.cta {
  display:        block;
  width:          100%;
  padding:        12px 20px;
  margin-top:     24px;
  background:     var(--orange);
  color:          #002222;
  font-family:    var(--font-display);
  font-size:      0.82rem;
  font-weight:    700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border:         none;
  border-radius:  var(--radius);
  cursor:         pointer;
  transition:     opacity var(--transition);
}
.cta:disabled         { opacity: 0.35; pointer-events: none; }
.cta.is-enabled:hover { opacity: 0.88; }

/* ── Inputs ─────────────────────────────────────────────────────── */
.input {
  display:       block;
  width:         100%;
  padding:       10px 14px;
  background:    var(--surface-2);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  color:         var(--cream);
  font-family:   var(--font-ui);
  font-size:     0.95rem;
  outline:       none;
  transition:    border-color var(--transition);
  appearance:    none;
}
.input::placeholder { color: var(--cream-dim); }
.input:focus         { border-color: var(--orange-dim); }
.input:disabled      { opacity: 0.5; }
select.input         { cursor: pointer; }

label {
  display:        block;
  font-size:      0.75rem;
  font-weight:    600;
  letter-spacing: 0.06em;
  color:          var(--cream-muted);
  text-transform: uppercase;
  margin-bottom:  6px;
  margin-top:     18px;
}
label:first-child { margin-top: 0; }
.field            { margin-bottom: 16px; }
.field label      { margin-top: 0; margin-bottom: 6px; }

/* ── Notice / flash messages ────────────────────────────────────── */
.notice {
  display:       none;
  padding:       10px 14px;
  border-radius: var(--radius);
  font-size:     0.85rem;
  line-height:   1.4;
  border:        1px solid transparent;
  margin-bottom: 16px;
}
.notice.error   { display: block; background: var(--error-bg);   color: var(--error);   border-color: rgba(207,69,69,0.25); }
.notice.success { display: block; background: var(--success-bg); color: var(--success); border-color: rgba(92,190,108,0.25); }
.notice.info    { display: block; background: var(--orange-glow);color: var(--orange);  border-color: var(--border); }

/* ── Badges / status pills ──────────────────────────────────────── */
.badge {
  display:        inline-block;
  padding:        2px 9px;
  border-radius:  99px;
  font-size:      0.7rem;
  font-weight:    600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.badge-active   { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--surface-3);  color: var(--cream-dim); }
.badge-pending  { background: var(--warn-bg);    color: var(--warn); }
.badge-creator  { background: var(--orange-glow);color: var(--orange); }

/* ── Auth forms ─────────────────────────────────────────────────── */
.auth-card {
  max-width:     420px;
  margin:        80px auto 0;   /* top margin so logo shows above */
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow:      hidden;
}
.topbar {
  width: 100%;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.brand {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: min(72vw, 350px);
  max-width: 350px;
  height: auto;
  margin-top: 20px;
}

@media (max-width: 480px) {

  .brand-logo {
    width: min(78vw, 280px);
    max-width: 280px;
  }

}

.auth-head {
  padding:      28px 24px 20px;
  text-align:   center;
  border-bottom: 1px solid var(--border);
}
.auth-head h2 {
  font-family:    var(--font-display);
  font-size:      1.1rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color:          var(--orange);
}

.auth-body { padding: 24px; }

.auth-links {
  margin-top:  20px;
  text-align:  center;
  font-size:   0.83rem;
  color:       var(--cream-muted);
}
.auth-links a { color: var(--orange); }

.password-hint {
  margin-top:  6px;
  font-size:   0.75rem;
  color:       var(--cream-dim);
  line-height: 1.4;
}

/* ── Empty state ────────────────────────────────────────────────── */
.empty-state {
  text-align:  center;
  padding:     40px 20px;
  color:       var(--cream-dim);
  font-size:   0.9rem;
}
.empty-state p + p { margin-top: 6px; }

/* ── Game cards ─────────────────────────────────────────────────── */
.game-card {
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       16px 18px;
  cursor:        pointer;
  transition:    border-color var(--transition), background var(--transition);
  text-decoration: none;
  display:       block;
}
.game-card:hover { border-color: var(--orange-dim); background: var(--surface-2); text-decoration: none; }
.game-card + .game-card { margin-top: 10px; }

.game-card-name {
  font-family:   var(--font-display);
  font-size:     1rem;
  font-weight:   600;
  color:         var(--cream);
  margin-bottom: 6px;
}
.game-card-meta {
  display:    flex;
  align-items: center;
  gap:        10px;
  flex-wrap:  wrap;
  font-size:  0.78rem;
  color:      var(--cream-muted);
}

/* ── Character cards ────────────────────────────────────────────── */
.char-card {
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       16px 18px;
}
.char-card + .char-card { margin-top: 10px; }

.char-card-name {
  font-family:   var(--font-display);
  font-size:     1rem;
  font-weight:   600;
  color:         var(--cream);
  margin-bottom: 5px;
}
.char-card-meta    { font-size: 0.8rem; color: var(--cream-muted); margin-bottom: 12px; }
.char-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Invite cards ───────────────────────────────────────────────── */
.invite-card {
  background:    var(--surface-2);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       14px 16px;
}
.invite-card + .invite-card { margin-top: 10px; }
.invite-card-title { font-size: 0.9rem; font-weight: 500; color: var(--cream); margin-bottom: 4px; }
.invite-card-sub   { font-size: 0.78rem; color: var(--cream-muted); margin-bottom: 12px; }
.invite-actions    { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Player row ─────────────────────────────────────────────────── */
.player-row {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  gap:             12px;
  padding:         10px 0;
  border-bottom:   1px solid var(--border-soft);
}
.player-row:last-child { border-bottom: none; }
.player-info { flex: 1; min-width: 0; }
.player-name { font-weight: 500; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-sub  { font-size: 0.75rem; color: var(--cream-muted); }

/* ── Inline form ────────────────────────────────────────────────── */
.inline-form {
  background:    var(--surface-2);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       16px 18px;
  margin-top:    14px;
}
.inline-form.hidden { display: none; }
.form-row           { display: flex; gap: 10px; align-items: flex-end; }
.form-row .input    { flex: 1; }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position:   fixed;
  inset:      0;
  background: rgba(0, 0, 0, 0.70);
  display:    flex;
  align-items: center;
  justify-content: center;
  padding:    16px;
  z-index:    500;
}
.modal-overlay.hidden { display: none; }

.modal {
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  width:         100%;
  max-width:     420px;
  max-height:    90dvh;
  overflow-y:    auto;
}
.modal-head {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         16px 20px;
  border-bottom:   1px solid var(--border);
}
.modal-head h3 {
  font-family:    var(--font-display);
  font-size:      0.88rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color:          var(--orange);
}
.modal-body    { padding: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Close button ───────────────────────────────────────────────── */
.close-btn {
  background:    transparent;
  border:        none;
  color:         var(--cream-muted);
  font-size:     1.5rem;
  line-height:   1;
  padding:       4px 8px;
  border-radius: var(--radius);
  transition:    color var(--transition), background var(--transition);
}
.close-btn:hover { color: var(--cream); background: var(--orange-glow); }

/* ── Icon button ────────────────────────────────────────────────── */
.icon-btn {
  display:         flex;
  align-items:     center;
  justify-content: center;
  width:           40px;
  height:          40px;
  background:      transparent;
  border:          none;
  border-radius:   var(--radius);
  color:           var(--orange);
  transition:      background var(--transition);
  flex-shrink:     0;
}
.icon-btn:hover { background: var(--orange-glow); }

/* ── Named-segment clocks ────────────────────────────────────────── */
.clock-tabs       { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.clock-tab-group  { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.clock-tab-label  {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--cream-dim); min-width: 68px; flex-shrink: 0;
}
.clock-tab {
  padding: 5px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--cream-muted);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.clock-tab:hover   { background: var(--surface-3); color: var(--cream); }
.clock-tab.is-active { background: var(--orange-glow); border-color: var(--orange-dim); color: var(--orange); font-weight: 600; }

.clock-viewer     { display: flex; flex-direction: column; align-items: center; }
.clock-display-row { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 380px; }
.clock-nav-btn {
  flex-shrink: 0; width: 44px; min-height: 88px;
  background: var(--surface-3); border: none; border-radius: var(--radius);
  color: var(--cream); font-size: 2rem; font-weight: 300; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.clock-nav-btn:hover:not(:disabled) { background: var(--orange); color: var(--bg); }
.clock-nav-btn:disabled { opacity: 0.22; cursor: not-allowed; }
.clock-svg-wrap { flex: 1; display: flex; justify-content: center; align-items: center; }

.clock-legend { margin-top: 28px; width: 100%; max-width: 380px; }
.clock-legend-row {
  display: grid; grid-template-columns: 96px 1fr; gap: 4px 14px;
  padding: 10px 0; border-bottom: 1px solid var(--border-soft); align-items: baseline;
}
.clock-legend-row:last-child { border-bottom: none; }
.clock-legend-name { font-weight: 600; font-size: 0.9rem; color: var(--cream-muted); }
.clock-legend-row.is-active .clock-legend-name { color: var(--orange); }
.clock-legend-desc { font-size: 0.875rem; line-height: 1.45; color: var(--cream-dim); }
.clock-legend-row.is-active .clock-legend-desc { color: var(--orange-dim); }

/* Smaller clock grid widgets */
.clocks-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.clock-widget {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.clock-face    { width: 90px; height: 90px; cursor: default; }
.clock-name    { font-family: var(--font-display); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em; color: var(--cream); text-align: center; }
.clock-controls { display: flex; align-items: center; gap: 10px; }
.clock-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--cream-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; line-height: 1;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.clock-btn:hover { border-color: var(--orange-dim); color: var(--orange); background: var(--orange-glow); }
.clock-btn:disabled { opacity: 0.35; pointer-events: none; }
.clock-count { font-family: var(--font-display); font-size: 0.82rem; color: var(--cream-muted); min-width: 28px; text-align: center; }

/* ── Dice roller ────────────────────────────────────────────────── */
.dice-tray-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
}
.dice-viewport {
  position: relative; width: 100%; aspect-ratio: 16/9;
  overflow: hidden; cursor: pointer;
}
#dice-canvas-container { position: absolute; inset: 0; }
.dice-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 0.78rem; letter-spacing: 0.1em;
  color: var(--cream-muted); text-transform: uppercase; pointer-events: none; transition: opacity var(--transition);
}
.dice-result { text-align: center; padding: 14px 16px 16px; border-top: 1px solid var(--border-soft); }
.dice-result-total     { font-family: var(--font-display); font-size: 2.2rem; font-weight: 700; color: var(--cream); line-height: 1.15; }
.dice-result-breakdown { font-size: 0.8rem; color: var(--cream-muted); }
.dice-pips { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; padding-bottom: 10px; }
.die-pip {
  width: 40px; height: 40px; background: var(--cream); border: 2px solid transparent;
  border-radius: var(--radius); display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; color: #00312F;
  animation: pip-pop 200ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.die-pip.is-max { border-color: var(--orange); color: #A33C0E; }
.die-pip.is-min { background: rgba(253, 250, 225, 0.55); }
@keyframes pip-pop { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.dice-controls-row { display: flex; gap: 10px; margin-top: 12px; }
.dice-seg {
  flex: 1; display: flex; gap: 4px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.dice-seg-btn {
  flex: 1; padding: 9px 0; border: none; border-radius: calc(var(--radius-lg) - 4px);
  background: transparent; color: var(--cream-muted);
  font-family: var(--font-display); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.06em;
  transition: background var(--transition), color var(--transition);
}
.dice-seg-btn:hover     { color: var(--cream); }
.dice-seg-btn.is-active { background: var(--orange); color: #002222; }
.dice-stepper {
  display: flex; align-items: stretch; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.dice-step-btn {
  width: 40px; border: none; border-radius: calc(var(--radius-lg) - 4px);
  background: transparent; color: var(--cream); font-size: 1.2rem; line-height: 1;
  transition: background var(--transition);
}
.dice-step-btn:hover:not(:disabled) { background: var(--orange-glow); }
.dice-step-btn:disabled { opacity: 0.35; cursor: default; }
.dice-count-label {
  min-width: 66px; display: flex; align-items: center; justify-content: center;
  font-size: 0.88rem; font-weight: 600; color: var(--cream);
}
.dice-roll-btn {
  margin-top: 12px; padding: 14px; border-radius: var(--radius-lg);
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; letter-spacing: 0.12em;
}

.dice-log { margin-top: 24px; }
.dice-log-entry {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border-soft); font-size: 0.83rem;
}
.dice-log-entry:first-child { border-top: 1px solid var(--border-soft); }
.log-notation {
  flex-shrink: 0; padding: 3px 8px; border-radius: var(--radius);
  background: var(--surface); color: var(--cream-muted);
  font-weight: 600; font-size: 0.7rem; letter-spacing: 0.04em; text-transform: uppercase;
}
.log-results { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; }
.log-die {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  background: var(--cream); color: #00312F; border-radius: 5px;
  font-size: 0.72rem; font-weight: 600;
}
.log-total {
  flex-shrink: 0; padding: 3px 10px; border-radius: var(--radius);
  background: var(--orange); color: #002222;
  font-family: var(--font-display); font-size: 0.9rem; font-weight: 700;
}
.log-time { flex-shrink: 0; font-size: 0.7rem; color: var(--cream-muted); }

/* ── Spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--orange);
  border-radius: 50%; animation: spin 700ms linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px; color: var(--cream-dim); font-size: 0.85rem; }

/* ── Utilities ──────────────────────────────────────────────────── */
.hidden         { display: none !important; }
.mt-sm          { margin-top: 8px; }
.mt-md          { margin-top: 14px; }
.mt-lg          { margin-top: 24px; }
.text-muted     { color: var(--cream-muted); }
.text-gold,
.text-orange    { color: var(--orange); }
.text-error     { color: var(--error); }
.text-sm        { font-size: 0.82rem; }
.text-xs        { font-size: 0.72rem; }
.flex           { display: flex; }
.flex-center    { display: flex; align-items: center; justify-content: center; }
.items-center   { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm         { gap: 8px; }
.gap-md         { gap: 14px; }
.flex-wrap      { flex-wrap: wrap; }
.divider        { height: 1px; background: var(--border); margin: 20px 0; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .card-body  { padding: 14px; }
  .auth-body  { padding: 18px; }
}

/* ══════════════════════════════════════════════════════════════════
   Apostle Character Sheet
   ══════════════════════════════════════════════════════════════════ */
.sheet-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  margin-bottom:   20px;
}
.sheet-name-input {
  display:       block;
  width:         100%;
  background:    transparent;
  border:        none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  padding:       4px 0 8px;
  font-family:   var(--font-display);
  font-size:     1.6rem;
  font-weight:   700;
  color:         var(--cream);
  letter-spacing: 0.04em;
  outline:       none;
  margin-bottom: 6px;
  transition:    border-color var(--transition);
}
.sheet-name-input:focus { border-bottom-color: var(--orange-dim); }

.sheet-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 420px) { .sheet-grid-2 { grid-template-columns: 1fr; } }

.btn-group        { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-group .btn.is-active { background: var(--orange-glow); border-color: var(--orange-dim); color: var(--orange); font-weight: 700; }

.sheet-counter-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sheet-counter     { display: flex; align-items: center; gap: 8px; }
.sheet-counter-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--cream); font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: border-color var(--transition), background var(--transition);
}
.sheet-counter-btn:hover:not(:disabled) { border-color: var(--orange-dim); background: var(--orange-glow); color: var(--orange); }
.sheet-counter-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.sheet-counter-val { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--orange); min-width: 32px; text-align: center; }

.faith-row    { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.faith-btn    { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); color: var(--cream); font-size: 1.4rem; font-weight: 300; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: border-color var(--transition), background var(--transition); }
.faith-btn:hover:not(:disabled) { border-color: var(--orange-dim); background: var(--orange-glow); color: var(--orange); }
.faith-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.faith-display { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.faith-value   { font-family: var(--font-display); font-size: 2rem; font-weight: 700; color: var(--orange); line-height: 1; }
.faith-track   { width: 100%; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.faith-bar     { height: 100%; background: var(--orange); border-radius: 3px; transition: width 200ms ease; }
.faith-labels  { display: flex; justify-content: space-between; padding: 0 56px; }

.legacy-row      { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.legacy-row:last-child { border-bottom: none; }
.legacy-label    { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--cream-muted); width: 82px; flex-shrink: 0; }
.track-pips      { display: flex; gap: 6px; flex: 1; }
.track-pip       { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--border); background: var(--surface-2); transition: background var(--transition), border-color var(--transition); }
.track-pip.is-filled { background: var(--orange); border-color: var(--orange); }
.track-controls  { display: flex; gap: 4px; flex-shrink: 0; }
.track-btn       { width: 26px; height: 26px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-2); color: var(--cream-muted); font-size: 0.9rem; display: flex; align-items: center; justify-content: center; transition: border-color var(--transition), color var(--transition); }
.track-btn:hover:not(:disabled) { border-color: var(--orange-dim); color: var(--orange); }
.track-btn:disabled { opacity: 0.25; cursor: not-allowed; }

.follower-row    { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.follower-row:last-child { border-bottom: none; }
.follower-name   { flex: 1; font-size: 0.9rem; color: var(--cream); }
.follower-actions { display: flex; gap: 6px; }

.save-indicator  { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--cream-dim); transition: color var(--transition); }
.save-indicator.is-dirty  { color: var(--warn); }
.save-indicator.is-saving { color: var(--cream-muted); }
.save-indicator.is-saved  { color: var(--success); }
.save-indicator.is-error  { color: var(--error); }

  .m-field { margin-bottom: 14px; }
  .m-field > label, .m-sec > label { display:block; font-size:0.82rem; color:var(--cream-muted); margin-bottom:6px; letter-spacing:0.03em; }
  .m-sec { margin: 18px 0; }

    /* ── Sidebar ── */
    .ap-sidebar {
      width: 240px; min-width: 240px;
      background: #1e1710;
      border-right: 1px solid #3a2e1e;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
    }
    .ap-sidebar-header {
      padding: 10px 12px;
      border-bottom: 1px solid #3a2e1e;
      display: flex;
      flex-direction: column;
      gap: 8px;
      flex-shrink: 0;
    }
    .ap-sidebar-body {
      flex: 1;
      overflow-y: auto;
      padding: 10px 10px 24px;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .ap-section {
      background: #2a2018;
      border: 1px solid #3a2e1e;
      border-radius: 8px;
      padding: 10px 10px 14px;
    }
    .ap-section-title {
      font-size: 9px;
      font-weight: bold;
      letter-spacing: 2px;
      color: #EDAA00;
      text-align: center;
      margin-bottom: 10px;
    }

    /* ── Sidebar buttons ── */
    .ap-hex-btn {
      width: 50px; height: 50px;
      background: #f0ebe0;
      border: 2px solid transparent;
      border-radius: 6px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 0;
      transition: border-color 0.15s;
    }
    .ap-hex-btn.selected { border-color: #EDAA00; }
    .ap-hex-btn.conflict { border-color: rgba(237,170,0,0.4); }
    .ap-hex-btn:disabled { opacity: 0.35; cursor: default; }
    .ap-hex-btn-label {
      font-size: 9px;
      color: #9a8870;
      text-align: center;
      white-space: nowrap;
      margin-top: 3px;
      user-select: none;
    }

    /* ── Action buttons ── */
    .ap-btn {
      height: 36px;
      border: none;
      border-radius: 6px;
      font-weight: bold;
      font-size: 12px;
      letter-spacing: 0.5px;
      cursor: pointer;
      transition: opacity 0.15s;
    }
    .ap-btn:disabled { opacity: 0.35; cursor: default; }
    .ap-btn-gold  { background: #EDAA00; color: #17110E; }
    .ap-btn-ghost { background: transparent; color: #FDFAE1; border: 1px solid #3a2e1e; }
    .ap-btn-danger { background: #8b3030; color: #fff; }
    .ap-btn-teal  { background: #2a5068; color: #FDFAE1; }

    /* ── Map area ── */
    .ap-map-area {
      flex: 1;
      overflow: auto;
      background: #f5f0e8;
    }

    /* ── Topbar ── */
    .ap-topbar {
      height: 44px;
      background: #17110E;
      border-bottom: 1px solid #3a2e1e;
      display: flex;
      align-items: center;
      padding: 0 12px;
      gap: 10px;
      flex-shrink: 0;
    }
    .ap-topbar-title {
      font-family: Georgia, 'Times New Roman', serif;
      font-size: 13px;
      font-weight: bold;
      color: #EDAA00;
      letter-spacing: 1px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .ap-back-btn {
      background: none;
      border: none;
      color: #EDAA00;
      cursor: pointer;
      display: flex;
      align-items: center;
      padding: 4px;
      flex-shrink: 0;
    }
    .ap-role-badge {
      font-size: 9px;
      font-weight: bold;
      letter-spacing: 1.5px;
      padding: 2px 8px;
      border-radius: 10px;
      flex-shrink: 0;
    }
    .ap-role-badge.creator { background: #3a2e0a; color: #EDAA00; }
    .ap-role-badge.player  { background: #252520; color: #9a9880; }

    /* ── Status banner ── */
    .ap-status {
      position: fixed;
      top: 12px; left: 50%;
      transform: translateX(-50%);
      padding: 7px 20px;
      border-radius: 6px;
      font-size: 13px;
      font-weight: bold;
      z-index: 2000;
      pointer-events: none;
      box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    }
    .ap-status.error   { background: #8b3030; color: #fff; }
    .ap-status.success { background: #3a6030; color: #fff; }
    .ap-status.info    { background: #3a4a20; color: #FDFAE1; }

    /* ── Full-screen loading ── */
    .ap-loading {
      display: flex; height: 100vh;
      align-items: center; justify-content: center;
      background: #17110E; color: #FDFAE1;
      font-size: 16px;
      flex-direction: column;
      gap: 12px;
    }

    /* ── Apostle marker chip ── */
    .apostle-chip {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      padding: 4px 8px 4px 6px;
      border-radius: 20px;
      border: 1.5px solid transparent;
      cursor: pointer;
      font-size: 11px;
      font-weight: bold;
      transition: border-color 0.15s, background 0.15s;
      user-select: none;
    }
    .apostle-chip.armed {
      border-color: #EDAA00;
      background: rgba(237,170,0,0.15);
    }

    /* ── Colour stepper ── */
    .ap-stepper {
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .ap-stepper-btn {
      width: 24px; height: 24px;
      background: #17110E;
      border: 1px solid #3a2e1e;
      border-radius: 4px;
      color: #FDFAE1;
      font-size: 14px;
      cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      flex-shrink: 0;
    }
    .ap-stepper-btn:disabled { opacity: 0.3; cursor: default; }
    .ap-stepper-val {
      font-size: 14px;
      font-weight: bold;
      color: #EDAA00;
      min-width: 26px;
      text-align: center;
    }

    /* ── Context menu ── */
    .ap-ctx {
      position: fixed;
      background: #2a2018;
      border: 1px solid #3a2e1e;
      border-radius: 6px;
      box-shadow: 0 4px 16px rgba(0,0,0,0.5);
      z-index: 1000;
      min-width: 180px;
      padding: 4px 0;
    }
    .ap-ctx-item {
      display: block;
      width: 100%;
      border: none;
      background: none;
      padding: 8px 14px;
      text-align: left;
      cursor: pointer;
      font-size: 13px;
      color: #FDFAE1;
    }
    .ap-ctx-item:hover { background: rgba(237,170,0,0.12); color: #EDAA00; }
    .ap-ctx-item.danger { color: #e06060; }
    .ap-ctx-item.danger:hover { background: rgba(180,60,60,0.15); }
    .ap-ctx-divider { height: 1px; background: #3a2e1e; margin: 4px 0; }

    /* ── Mobile sidebar overlay ── */
    .ap-mob-overlay { display: none; }
    .ap-mob-tab { display: none; }

    @media (max-width: 768px) {
      .ap-sidebar {
        position: fixed; top: 0; left: 0; bottom: 0;
        z-index: 900;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
      }
      .ap-sidebar.is-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
      }
      .ap-mob-overlay {
        display: block;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 899;
        opacity: 0; pointer-events: none;
        transition: opacity 0.3s;
      }
      .ap-mob-overlay.is-open { opacity: 1; pointer-events: auto; }
      .ap-mob-tab {
        display: flex; align-items: center; justify-content: center;
        position: fixed; top: 50%; left: 0;
        transform: translateY(-50%);
        z-index: 898;
        width: 24px; height: 60px;
        background: #1e1710;
        border: none; border-radius: 0 6px 6px 0;
        cursor: pointer;
        box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
        color: #EDAA00;
      }
    }

    /* ── Generate confirm modal ── */
    .ap-modal-bg {
      position: fixed; inset: 0;
      background: rgba(0,0,0,0.6);
      z-index: 2000;
      display: flex; align-items: center; justify-content: center;
      padding: 16px;
    }
    .ap-modal {
      background: #2a2018;
      border: 1px solid #3a2e1e;
      border-radius: 10px;
      padding: 24px 28px;
      max-width: 340px; width: 90%;
      text-align: center;
      box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    }
    .ap-modal h3 { font-size: 16px; color: #EDAA00; margin-bottom: 12px; }
    .ap-modal p  { font-size: 13px; color: #c0b8a0; line-height: 1.6; margin-bottom: 20px; }
    .ap-modal-btns { display: flex; gap: 10px; justify-content: center; }

    .demo { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 14px; }
    .demo h3 { font-family: var(--font-display); color: var(--orange); font-size: 0.9rem; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 12px; }
    .demo .row { margin: 10px 0; }
    .demo .cap { font-size: 0.78rem; color: var(--cream-muted); margin-bottom: 6px; }

    .ap-field { margin-bottom: 14px; }
    .ap-field > label, .ap-sec > label { display:block; font-size:0.82rem; color:var(--cream-muted); margin-bottom:6px; letter-spacing:0.03em; }
    .ap-sec { margin: 18px 0; }
    .ap-sec-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:6px; }
    .ap-sec-head span { font-size:0.82rem; color:var(--cream-muted); letter-spacing:0.03em; }
    .ap-help-toggle { border:none;background:var(--cream);color:#00312F;border-radius:5px;width:24px;height:24px;cursor:pointer;font-weight:700;margin-left:8px; }
    .ap-help { display:none; margin-top:8px; padding:10px 12px; background:var(--surface-2); border:1px solid var(--border); border-radius:8px; font-size:0.82rem; color:var(--cream-muted); line-height:1.5; }
    .ap-so { display:flex; gap:8px; }
    .ap-so button { flex:1; border:1px solid var(--border); background:var(--surface-2); color:var(--cream); border-radius:8px; padding:10px 0; cursor:pointer; font-weight:600; }
    .ap-so button.is-on { background:var(--orange); color:#00312F; border-color:var(--orange); }
    .ap-foll input { width:100%; margin-bottom:8px; }

    .field { margin-bottom: 14px; }
    .field label { display:block; font-size:0.78rem; color:var(--cream-muted); margin-bottom:5px; letter-spacing:0.04em; }
    .field .hint { font-size:0.74rem; color:var(--cream-dim); margin-top:4px; }
    .field-readonly { font-size:0.95rem; color:var(--cream); padding:10px 0; }
    .row2 { display:flex; gap:10px; }
    .row2 .field { flex:1; }

    .apostle-card-fields { font-size:0.82rem; color:var(--cream-muted); margin-bottom:12px; line-height:1.6; }
    .apostle-card-fields strong { color:var(--cream); font-weight:600; }