/* ===== Self-hosted Fonts ===== */
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/cinzel.woff2') format('woff2');
}
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url('fonts/cinzel-900.woff2') format('woff2');
}
@font-face {
  font-family: 'Alegreya';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/alegreya.woff2') format('woff2');
}
@font-face {
  font-family: 'Alegreya';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/alegreya-700.woff2') format('woff2');
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #000000;
  --header-bg: rgba(0, 0, 0, 0.45);
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #ffd700;
  --accent-glow: rgba(255, 215, 0, 0.5);
  --accent-dim: rgba(255, 215, 0, 0.15);
  --card-size: 220px;
  --card-height: 330px;
  --border: rgba(255, 255, 255, 0.1);
  --panel-bg: #16213e;
  --panel-border: rgba(255, 255, 255, 0.08);
  --danger: #e94560;
  --btn-bg: rgba(255, 255, 255, 0.08);
  --btn-bg-hover: rgba(255, 255, 255, 0.15);
  --transition-transform: 1.4s cubic-bezier(0.45, 0, 0.15, 1);
  --transition-opacity: 0.6s ease;
  --transition-filter: 0.6s ease;
  --font-display: 'Cinzel', 'Times New Roman', serif;
  --font-body: 'Alegreya', Georgia, serif;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease;
}

/* ===== Header / Top Bar ===== */
#topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 64px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  white-space: nowrap;
  text-shadow: 0 0 20px var(--accent-dim);
}

.round-display {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.round-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
}

.round-number {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-dim);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Buttons ===== */
.btn {
  font-family: var(--font-display);
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--btn-bg-hover);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn:active {
  transform: scale(0.96);
}

/* Instant hotkey tooltip — same style as the DM remote's data-tip prompts */
.controls .btn[data-tip] { position: relative; }
.controls .btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: rgba(20, 20, 30, 0.95);
  color: #fff;
  font-family: 'Alegreya', Georgia, serif;
  font-size: 0.7rem;
  font-weight: 400;
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid var(--accent-dim);
  white-space: nowrap;
  pointer-events: none;
  z-index: 999;
}

.btn-primary {
  background: linear-gradient(135deg, #ffd700, #ffa500);
  color: #1a1a2e;
  border: none;
  font-weight: 700;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #ffe44d, #ffb733);
  box-shadow: 0 0 20px var(--accent-dim);
}

.btn-danger {
  background: rgba(233, 69, 96, 0.15);
  border-color: rgba(233, 69, 96, 0.3);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(233, 69, 96, 0.25);
}

.btn-icon {
  padding: 8px 12px;
  font-size: 1.1rem;
  line-height: 1;
}

.btn-full {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
  margin-top: 8px;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.btn-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

/* ===== Position Display ===== */
.position-display {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  color: var(--text-dim);
  z-index: 50;
  letter-spacing: 1px;
}

/* ===== Stage / Carousel ===== */
#stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1400px;
  overflow: hidden;
}

#carousel {
  position: relative;
  width: var(--card-size);
  height: var(--card-height);
  transform-style: preserve-3d;
}

/* ===== Character Cards ===== */
.character-card {
  position: absolute;
  width: var(--card-size);
  height: var(--card-height);
  top: 0;
  left: 0;
  border-radius: 16px;
  overflow: hidden;
  cursor: default;
  transition:
    transform var(--transition-transform),
    opacity var(--transition-opacity),
    filter var(--transition-filter),
    box-shadow 0.4s ease,
    border-color 0.4s ease;
  border: 3px solid rgba(255, 255, 255, 0.08);
  background: #0d0d1a;
  will-change: transform, opacity;
  display: flex;
  flex-direction: column;
}

.character-card .card-image {
  flex: 1;
  width: 100%;
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  min-height: 0;
}

.character-card .card-overlay {
  flex-shrink: 0;
  padding: 10px 14px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.card-name {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 900;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.2s;
  flex: 1;
  min-width: 0;
  text-align: center;
  order: 2;
}

.card-name:empty::before {
  content: "Enter name...";
  color: rgba(255, 255, 255, 0.35);
  font-style: italic;
  font-weight: 400;
  font-size: 0.7em;
}

.card-name:hover {
  background: rgba(255, 255, 255, 0.15);
}

.card-init {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.6);
  padding: 3px 12px;
  border-radius: 10px;
  flex-shrink: 0;
  border: 1px solid var(--accent-dim);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  order: 1;
}

.card-init:hover {
  background: rgba(255, 215, 0, 0.15);
  border-color: var(--accent);
}

.card-remove {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.15s;
  order: 3;
}

.card-remove:hover {
  transform: scale(1.1);
}

/* Non-active card dimming */
.character-card:not(.active) {
  filter: brightness(0.45) saturate(0.6);
}

.character-card:not(.active):hover {
  filter: brightness(0.65) saturate(0.8);
}

/* Active card illumination (the static frame provides the glow) */
.character-card.active {
  border-color: var(--accent);
  filter: brightness(1.3) saturate(1.15);
  z-index: 250 !important;
}

.character-card.active .card-name {
  font-size: 1.6rem;
}

.character-card.active .card-init {
  font-size: 1.35rem;
}

/* Static center frame — always present, characters slide into it */
.center-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-size);
  height: var(--card-height);
  border-radius: 16px;
  border: 3px solid var(--accent);
  box-shadow:
    0 0 50px var(--accent-glow),
    0 0 110px rgba(255, 215, 0, 0.2),
    inset 0 0 25px rgba(255, 215, 0, 0.08);
  pointer-events: none;
  z-index: 200;
  background: transparent;
  animation: framePulse 3s ease-in-out infinite;
}

.center-frame.hidden {
  display: none;
}

@keyframes framePulse {
  0%, 100% {
    box-shadow:
      0 0 50px var(--accent-glow),
      0 0 110px rgba(255, 215, 0, 0.2),
      inset 0 0 25px rgba(255, 215, 0, 0.08);
  }
  50% {
    box-shadow:
      0 0 70px rgba(255, 215, 0, 0.6),
      0 0 150px rgba(255, 215, 0, 0.3),
      inset 0 0 35px rgba(255, 215, 0, 0.12);
  }
}

/* Empty state */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-dim);
  font-size: 1.2rem;
  white-space: nowrap;
}

/* ===== Overlay & Drawers ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 200;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 90vw;
  height: 100%;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 300;
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.drawer-header h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ===== Image Upload Area ===== */
.image-upload-area {
  width: 100%;
  height: 220px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color 0.2s, background 0.2s;
  background: rgba(0, 0, 0, 0.2);
}

.image-upload-area.small {
  height: 140px;
}

.image-upload-area:hover {
  border-color: var(--accent);
  background: rgba(255, 215, 0, 0.05);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.upload-icon {
  font-size: 2rem;
}

.upload-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== Color Input ===== */
.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-input-wrapper input[type="color"] {
  width: 50px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: none;
}

.color-input-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 4px;
}

.color-input-wrapper input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.color-value {
  font-family: monospace;
  font-size: 0.95rem;
  color: var(--text-dim);
}

/* ===== Character Count ===== */
.char-count {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-align: center;
}

/* ===== Settings Sections ===== */
.settings-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--panel-border);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-section h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 16px;
}

/* ===== Character List ===== */
.char-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.char-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s;
}

.char-list-item:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.char-list-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  background-color: #333;
}

.char-list-info {
  flex: 1;
  min-width: 0;
}

.char-list-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-list-init {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.char-list-remove {
  background: rgba(233, 69, 96, 0.15);
  border: 1px solid rgba(233, 69, 96, 0.3);
  color: var(--danger);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.char-list-remove:hover {
  background: rgba(233, 69, 96, 0.3);
}

.empty-list-msg {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  padding: 16px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--panel-bg);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 400;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Fullscreen ===== */
/* In fullscreen, hide all top-bar chrome (brand + controls) so only the
   round counter is left at the top of the screen. */
:fullscreen #topbar {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-bottom: none;
}

:fullscreen #topbar .brand,
:fullscreen #topbar .controls {
  display: none;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  :root {
    --card-size: 160px;
    --card-height: 240px;
  }

  .brand-text {
    display: none;
  }

  .controls {
    gap: 4px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.85rem;
  }
}

@media (max-width: 600px) {
  :root {
    --card-size: 120px;
    --card-height: 180px;
  }

  .round-display {
    display: none;
  }

  .drawer {
    width: 100vw;
  }
}

/* ===== Scrollbar ===== */
.drawer-body::-webkit-scrollbar {
  width: 6px;
}

.drawer-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}

.drawer-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.drawer-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ===== Lair Action Overlay ===== */
#lair-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 1.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

#lair-overlay.visible {
  opacity: 1;
}

#lair-overlay .lair-text {
  font-family: var(--font-display);
  font-size: clamp(4rem, 12vw, 10rem);
  font-weight: 900;
  color: #8B0000;
  text-shadow: 0 0 30px rgba(255, 80, 80, 0.8), 0 0 80px rgba(255, 80, 80, 0.4);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  animation: lair-pulse 2s ease-in-out infinite;
  line-height: 1;
  will-change: transform;
}

@keyframes lair-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* Dim carousel cards when lair action is active */
body.lair-active .character-card,
body.legendary-active .character-card {
  filter: brightness(0.4) blur(3px);
}

body.lair-active #center-frame,
body.legendary-active #center-frame {
  filter: brightness(0.3) blur(4px);
}

/* ===== Legendary Action Overlay ===== */
#legendary-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 1.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

#legendary-overlay.visible {
  opacity: 1;
}

#legendary-overlay .lair-text {
  font-family: var(--font-display);
  font-size: clamp(4rem, 12vw, 10rem);
  font-weight: 900;
  color: #ffd700;
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.8), 0 0 80px rgba(255, 215, 0, 0.4);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  animation: lair-pulse 2s ease-in-out infinite;
  line-height: 1;
  will-change: transform;
}

/* Dim carousel cards when legendary action is active */
body.legendary-active .character-card {
  filter: brightness(0.4) blur(3px);
}

body.legendary-active #center-frame {
  filter: brightness(0.3) blur(4px);
}
