/* ============================================================
   Shell styles — sidebar, topbar, dice overlay
   ============================================================ */

/* ===== SIDEBAR ===== */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  min-height: 100vh;
  background: var(--bg-1);
  border-right: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
}

.brand {
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line-1);
  position: relative;
}
.brand-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--gold-0);
  background: radial-gradient(circle at 30% 30%, var(--gold-soft), transparent 70%);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold-1);
  margin-bottom: 8px;
}
.brand-word {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: var(--ink-0);
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  margin-top: 4px;
}

.character-pill {
  margin: 12px 14px 8px;
  padding: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.character-pill:hover { border-color: var(--gold-2); }
.character-pill .portrait {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-3), var(--bg-4));
  border: 1px solid var(--gold-2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--gold-1);
  flex: 0 0 38px;
  position: relative;
  overflow: hidden;
}
.character-pill .portrait::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid var(--gold-soft);
  border-radius: 50%;
}
.character-pill .name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-0);
  line-height: 1.15;
}
.character-pill .meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 2px;
}

/* ===== CHARACTER SWITCHER DROPDOWN ===== */
.char-switcher {
  position: relative;
}
.char-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 14px; right: 14px;
  background: var(--bg-elv);
  border: 1px solid var(--gold-2);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5), 0 0 24px var(--gold-glow);
  z-index: 60;
  max-height: 460px;
  overflow-y: auto;
  padding: 6px;
}
.char-dropdown-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--line-1);
  margin-bottom: 4px;
}
.char-row {
  position: relative;
  border-radius: var(--radius);
  margin-bottom: 2px;
  transition: background 0.12s;
}
.char-row:hover { background: var(--bg-2); }
.char-row.active {
  background: var(--gold-soft);
  box-shadow: inset 0 0 0 1px var(--gold-2);
}
.char-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
}
.char-row-portrait {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--gold-2);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--gold-1);
  flex: 0 0 32px;
}
.char-row-portrait img {
  width: 100%; height: 100%; object-fit: cover;
}
.char-row-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-0);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.char-row-meta {
  display: flex;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 2px;
}
.char-row-meta .crimson { color: var(--crimson-1); }
.char-row-del {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  border-radius: var(--radius);
  background: var(--bg-1);
  border: 1px solid transparent;
  color: var(--ink-3);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.char-row:hover .char-row-del {
  display: flex;
}
.char-row-del:hover {
  color: var(--crimson-1);
  border-color: var(--crimson);
  background: var(--crimson-soft);
}
.char-dropdown-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 6px;
  margin-top: 6px;
  border-top: 1px solid var(--line-1);
}
.char-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--gold-1);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.12s;
}
.char-action:hover { background: var(--gold-soft); }

.nav {
  padding: 10px 0;
  flex: 1 1 0;
}
.nav-section-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 12px 22px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px 9px 18px;
  margin: 1px 8px;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--ink-1);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.nav-item:hover { background: var(--bg-2); color: var(--gold-1); }
.nav-item.active {
  background: linear-gradient(90deg, var(--gold-soft), transparent);
  color: var(--gold-1);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--gold-0);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--gold-glow);
}
.nav-item .nav-icon { color: var(--ink-3); }
.nav-item:hover .nav-icon, .nav-item.active .nav-icon { color: var(--gold-1); }
.nav-item .nav-shortcut {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  padding: 1px 5px;
  border-radius: 3px;
}

.sidebar-bottom {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dice-launcher {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: linear-gradient(180deg, var(--bg-3), var(--bg-2));
  border: 1px solid var(--gold-2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  color: var(--ink-0);
}
.dice-launcher:hover {
  border-color: var(--gold-0);
  box-shadow: 0 0 12px var(--gold-glow);
}
.dice-launcher .dice-launch-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-1);
}
.dice-launcher .dice-launch-key {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  background: var(--bg-1);
  border: 1px solid var(--line-1);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ===== TOPBAR ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-1);
  flex-wrap: nowrap;
  min-width: 0;
}
.topbar::after {
  content: '';
  position: absolute;
  left: 24px; right: 24px; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-2) 30%, var(--gold-0) 50%, var(--gold-2) 70%, transparent);
  opacity: 0.4;
}

.topbar-identity {
  display: flex; flex-direction: column;
  line-height: 1.1;
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
}
.topbar-name {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hp-meter {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  background: var(--bg-2);
  border: 1px solid var(--crimson-soft);
  border-left: 3px solid var(--crimson);
  border-radius: var(--radius);
  position: relative;
}
.hp-meter .hp-icon { color: var(--crimson-1); }
.hp-meter .hp-num {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-0);
}
.hp-meter .hp-num .hp-max { color: var(--ink-2); font-weight: 400; font-size: 14px; }
.hp-meter .hp-bar-wrap { width: 110px; }
.hp-meter .hp-temp {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--azure-1);
  border: 1px solid var(--azure-soft);
  background: var(--azure-soft);
  padding: 1px 6px;
  border-radius: 3px;
}

.action-chips {
  display: flex;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-2);
  border: 1px dashed var(--line-1);
  border-radius: var(--radius);
}
.action-chip {
  font-family: var(--font-display);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--gold-2);
  color: var(--gold-1);
  background: var(--gold-soft);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.action-chip:hover { background: var(--gold-0); color: var(--bg-0); }
.action-chip.used {
  border-color: var(--line-1);
  color: var(--ink-3);
  background: transparent;
  text-decoration: line-through;
}
.action-chip.used:hover { color: var(--ink-2); background: var(--bg-3); text-decoration: none; }

.topbar-divider {
  width: 1px;
  height: 36px;
  background: var(--line-1);
}

/* ===== SAVE INDICATOR ===== */
.save-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-0);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}
.save-indicator .save-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  opacity: 0.6;
  transition: all 0.3s;
}
.save-indicator .save-dot.fresh {
  background: var(--emerald-1);
  opacity: 1;
  box-shadow: 0 0 8px var(--emerald-soft);
  animation: save-pulse 0.4s ease-out;
}
@keyframes save-pulse {
  0%   { transform: scale(0.5); opacity: 0; }
  60%  { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}

/* ===== FORMULA TOOLTIP ===== */
[data-tooltip] {
  position: relative;
  cursor: help;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3, #1a1a2e);
  color: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  font-family: var(--font-mono, monospace);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
[data-tooltip]:hover::after {
  opacity: 1;
}
/* Tooltip вниз — для елементів у топбарі де зверху немає місця */
[data-tooltip-down]::after {
  content: attr(data-tooltip-down);
  position: absolute;
  top: calc(100% + 6px);
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3, #1a1a2e);
  color: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  font-family: var(--font-mono, monospace);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
[data-tooltip-down] {
  position: relative;
  cursor: help;
}
[data-tooltip-down]:hover::after {
  opacity: 1;
}

/* ===== DICE OVERLAY ===== */
.dice-overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  z-index: 100;
  /* Scrollable backdrop — modal never gets clipped by viewport height */
  overflow-y: auto;
  padding: 28px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  animation: backdrop-in 0.2s ease-out;
}
@keyframes backdrop-in { from { opacity: 0 } to { opacity: 1 } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}
@keyframes login-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.dice-overlay {
  width: min(720px, 92vw);
  /* Vertically center short modals; tall ones just stack from top with backdrop scroll */
  margin: auto;
  flex-shrink: 0;
  /* Body scrolls internally — cap so header stays pinned */
  max-height: calc(100vh - 56px);
  background: var(--bg-elv);
  border: 1px solid var(--gold-2);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 80px var(--gold-glow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: overlay-in 0.32s cubic-bezier(.2,.8,.2,1.05);
}
@keyframes overlay-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dice-overlay-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gold-2);
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-elv));
  /* Header always visible — never scrolls away */
  flex-shrink: 0;
  position: relative;
}
.dice-overlay-head h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: var(--gold-1);
  text-transform: uppercase;
}
.dice-overlay-head::after {
  content: '';
  position: absolute;
  left: 20px; right: 20px; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-0), transparent);
}

/* Body scrolls when content overflows the modal height cap */
.dice-overlay-body { padding: 20px; flex: 1 1 0; min-height: 0; overflow-y: auto; }

.dice-result {
  display: flex; flex-direction: column;
  align-items: center;
  padding: 22px 20px;
  background: radial-gradient(ellipse at center, var(--gold-soft) 0%, transparent 70%), var(--bg-2);
  border: 1px solid var(--gold-2);
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}
.dice-result.crit { border-color: var(--gold-1); }
.dice-result.crit::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--gold-glow) 0%, transparent 60%);
  animation: crit-pulse 1.4s ease-in-out infinite;
}
@keyframes crit-pulse {
  0%, 100% { opacity: 0.4 } 50% { opacity: 1 }
}
.dice-result-eyebrow {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--gold-1);
  text-transform: uppercase;
}
.dice-result-big {
  font-family: var(--font-display);
  font-size: 72px;
  font-weight: 700;
  color: var(--ink-0);
  line-height: 1;
  margin: 8px 0;
  text-shadow: 0 0 24px var(--gold-glow);
  position: relative;
}
.dice-result-formula {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
}
.dice-result-verdict {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 8px;
  position: relative;
}

.dice-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.die-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 14px 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  color: var(--ink-0);
  cursor: pointer;
  transition: all 0.15s;
}
.die-btn:hover {
  border-color: var(--gold-0);
  background: var(--bg-3);
  color: var(--gold-1);
  transform: translateY(-1px);
  box-shadow: var(--shadow-gold);
}
.die-btn .die-name {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.dice-mode-toggle {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: 999px;
  padding: 2px;
}
.dice-mode-toggle button {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 999px;
  color: var(--ink-2);
  transition: all 0.15s;
}
.dice-mode-toggle button.active {
  background: var(--gold-soft);
  color: var(--gold-1);
  box-shadow: inset 0 0 0 1px var(--gold-2);
}

.dice-history {
  border-top: 1px solid var(--line-1);
  padding: 14px 20px 18px;
  max-height: 200px;
  overflow-y: auto;
}
.dice-history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line-0);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-1);
}
.dice-history-row:last-child { border-bottom: none; }
.dice-history-row .dhr-formula { color: var(--ink-3); width: 90px; }
.dice-history-row .dhr-result { flex: 1; }
.dice-history-row .dhr-total {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--gold-1);
  font-weight: 600;
  min-width: 30px; text-align: right;
}
.dice-history-row .dhr-time { color: var(--ink-4); font-size: 10px; }
.dice-history-row .dhr-tag { font-size: 10px; color: var(--ink-2); }
