:root {
  --bg: #f3f4f6;
  --text: #111827;
  --muted: #6b7280;
  --brand: #1f2937;
  --brand-2: #0f766e;
  --brand-neutral: #d1d5db;
  --danger: #b91c1c;
  --accent: #ca8a04;
  --shadow: 0 18px 45px rgba(17, 24, 39, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  transition: background 180ms ease;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.14), transparent 30%),
    radial-gradient(circle at bottom right, rgba(202, 138, 4, 0.18), transparent 25%),
    var(--bg);
}

body.presentation-mode {
  background: #2b2f36;
}

button, input, select, textarea { font: inherit; }

button {
  border: 0;
  border-radius: 999px;
  background: var(--brand);
  color: white;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}

button:hover { transform: translateY(-1px); }
button.secondary { background: var(--brand-neutral); color: var(--text); }
button.accent { background: var(--accent); }
button.danger { background: var(--danger); }
button.mini { padding: 0.45rem 0.7rem; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.hidden { display: none !important; }

.topbar,
.topbar-actions,
.button-row,
.slide-item-actions,
.tray-header,
.section-header {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.topbar,
.section-header,
.tray-header,
.slide-item {
  justify-content: space-between;
}

.topbar { padding: 1.2rem 1.5rem 0; }
.topbar.hidden-main-menu { display: none; }
.button-row.wrap { flex-wrap: wrap; }
.shell { padding: 1.5rem; }
.view { min-height: calc(100vh - 6rem); }
body.presentation-main-menu-hidden .shell { padding-top: 1rem; }
body.presentation-main-menu-hidden .view { min-height: calc(100vh - 2rem); }
body.presentation-mode.presentation-main-menu-hidden {
  overflow: hidden;
}
body.presentation-mode.presentation-main-menu-hidden .shell {
  padding: 0;
}
body.presentation-mode.presentation-main-menu-hidden #presentationView {
  height: 100dvh;
}

.menu-dropdown {
  position: relative;
}

.menu-trigger {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: var(--brand-neutral);
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.menu-trigger::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  min-width: 13rem;
  display: grid;
  gap: 0.45rem;
  padding: 0.6rem;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 5;
}

.menu-item {
  width: 100%;
  justify-content: flex-start;
}

.menu-close {
  justify-self: end;
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.menu-close:hover {
  background: rgba(17, 24, 39, 0.08);
  color: var(--text);
}

.topbar-actions button.active-nav {
  background: var(--brand);
  color: white;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.8rem, 3vw, 2.6rem); }

#brandTitle {
  color: var(--brand-title-color, var(--text));
}

.brand-logo {
  display: block;
  max-height: 68px;
  max-width: min(320px, 45vw);
  object-fit: contain;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.subcard {
  padding: 1rem;
  box-shadow: none;
  background: rgba(243, 244, 246, 0.92);
}

.prompt-page {
  padding: 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
}

#editorView {
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  gap: 1.5rem;
}

.sidebar, .editor-main { padding: 1rem; }

.field, .dynamic-fields, .import-export {
  display: grid;
  gap: 0.4rem;
}

.field { margin-bottom: 1rem; }
.field span, .muted { color: var(--muted); }
.small { font-size: 0.84rem; }

.checkbox-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.checkbox-row input {
  width: auto;
}

input, select, textarea {
  width: 100%;
  border: 1px solid rgba(17, 24, 39, 0.14);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  background: #fff;
  color: var(--text);
}

textarea { resize: vertical; }

input[type="color"] {
  padding: 0.25rem;
  min-height: 3rem;
  background: transparent;
  cursor: pointer;
}

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

input[type="color"]::-webkit-color-swatch,
input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 9px;
}

.slide-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

.slide-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.slide-item-main {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 14px;
  background: white;
  color: var(--text);
  border: 1px solid rgba(17, 24, 39, 0.08);
  padding: 0.8rem;
}

.slide-item.active .slide-item-main { background: var(--brand); color: white; }
.slide-item.drag-over .slide-item-main { outline: 2px dashed var(--brand-2); }

.status-pill {
  font-size: 0.8rem;
  color: white;
  background: var(--brand-2);
  border-radius: 999px;
  padding: 0.3rem 0.6rem;
}

.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 40vh;
  text-align: center;
}

#presentationView { position: relative; overflow: hidden; }

.presentation-stage {
  min-height: calc(100vh - 7rem);
  border-radius: 28px;
  overflow: hidden;
  position: relative;
  background: #0f172a;
  box-shadow: var(--shadow);
}

.presentation-stage::before {
  content: "";
  position: absolute;
  inset: 0;
}

.presentation-stage.overlay-full::before {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.82), rgba(17, 24, 39, 0.42));
}

.presentation-stage.overlay-none::before {
  background: transparent;
}

.presentation-stage.overlay-text.overlay-align-left::before {
  background: linear-gradient(90deg,
    rgba(15, 23, 42, 0.84) 0%,
    rgba(17, 24, 39, 0.74) 36%,
    rgba(17, 24, 39, 0.28) 58%,
    rgba(17, 24, 39, 0) 76%);
}

.presentation-stage.overlay-text.overlay-align-center::before {
  background: linear-gradient(90deg,
    rgba(17, 24, 39, 0.08) 0%,
    rgba(15, 23, 42, 0.54) 28%,
    rgba(15, 23, 42, 0.82) 50%,
    rgba(15, 23, 42, 0.54) 72%,
    rgba(17, 24, 39, 0.08) 100%);
}

.presentation-stage.overlay-text.overlay-align-right::before {
  background: linear-gradient(270deg,
    rgba(15, 23, 42, 0.84) 0%,
    rgba(17, 24, 39, 0.74) 36%,
    rgba(17, 24, 39, 0.28) 58%,
    rgba(17, 24, 39, 0) 76%);
}

.presentation-content {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - 7rem);
  padding: clamp(1.5rem, 4vw, 3rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: white;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.3);
}

body.presentation-main-menu-hidden #presentationView .presentation-stage,
body.presentation-main-menu-hidden #presentationView .presentation-content {
  min-height: 100dvh;
}

.align-left { align-items: flex-start; text-align: left; }
.align-center { align-items: center; text-align: center; }
.align-right { align-items: flex-end; text-align: right; }

.presentation-kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.presentation-title {
  font-size: var(--presentation-title-size, clamp(2rem, 5vw, 4.8rem));
  line-height: 1.04;
  margin-bottom: 1rem;
  max-width: var(--presentation-title-max-width, 14ch);
}

.presentation-content.type-image .presentation-title {
  margin-bottom: 0.7rem;
}

.presentation-body, .presentation-answer {
  font-size: clamp(1.15rem, 2.2vw, 1.8rem);
  max-width: 48rem;
}

.presentation-answer, .answer-card {
  margin-top: 1.2rem;
  padding: 1rem 1.2rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
}

.presentation-answer {
  font-size: clamp(1.45rem, 2.8vw, 2.35rem);
}

.presentation-answer.concealed-answer {
  visibility: hidden;
  opacity: 0;
}

.answers-grid {
  display: grid;
  gap: 1rem;
  width: min(100%, 64rem);
  margin-top: 1.4rem;
}

.scores-board {
  display: grid;
  gap: 0.9rem;
  width: min(100%, 52rem);
  margin-top: 1.4rem;
}

.score-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.95rem 1.2rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: clamp(1.1rem, 2vw, 1.5rem);
}

.score-rank,
.score-points {
  font-weight: 700;
}

.answer-card {
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  line-height: 1.3;
}

.answer-card.hidden-answer {
  opacity: 0.05;
}

.image-frame {
  margin-top: 1.4rem;
  width: min(100%, 58rem);
  max-height: 52vh;
  object-fit: contain;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
}

.presentation-content.type-image .image-frame {
  margin-top: 0.9rem;
  max-height: min(38vh, calc(100dvh - 26rem));
}

.presentation-content.type-image .presentation-answer {
  margin-top: 0.9rem;
  flex-shrink: 0;
}

.upload-status {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.audio-status {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.audio-status p {
  margin-bottom: 0;
}

.audio-preview {
  width: 100%;
  margin: 0.75rem 0 0.25rem;
}

.spinner {
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  border: 2px solid rgba(17, 24, 39, 0.18);
  border-top-color: var(--brand-2);
  animation: spin 0.8s linear infinite;
}

.presentation-tray {
  position: absolute;
  top: 1rem;
  width: min(300px, calc(100vw - 2rem));
  padding: 1rem;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow: var(--shadow);
  z-index: 2;
}

.presentation-tray.left {
  right: 1rem;
  left: auto;
  top: auto;
  bottom: 1rem;
}
.presentation-tray.collapsed {
  width: 3.5rem;
  min-width: 3.5rem;
  padding: 0.45rem;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  opacity: 0.78;
}

.presentation-tray.collapsed:hover {
  opacity: 0.95;
}

.presentation-tray.collapsed > :not(.tray-header) { display: none; }
.presentation-tray.collapsed .tray-header {
  justify-content: center;
}

.presentation-tray.collapsed .tray-header h2 {
  display: none;
}

.tray-toggle {
  padding: 0.45rem 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  min-height: 2.75rem;
}

.presentation-tray.collapsed .tray-toggle {
  padding: 0.3rem;
  width: 2.55rem;
  min-width: 2.55rem;
  min-height: 2.4rem;
  border-radius: 12px;
  background: rgba(31, 41, 55, 0.28);
}

.presentation-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  max-width: min(90vw, 34rem);
  padding: 0.8rem 1.15rem;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.9);
  color: white;
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.22);
  text-align: center;
  pointer-events: none;
}

.presentation-tray.collapsed .tray-toggle-label {
  display: none;
}

.presentation-tray.collapsed .icon-menu {
  display: inline-flex !important;
}

.icon-menu {
  flex-direction: column;
  gap: 0.22rem;
}

.icon-menu span {
  display: block;
  width: 1.1rem;
  height: 0.12rem;
  border-radius: 999px;
  background: white;
}

@media (max-width: 980px) {
  #editorView, .grid.two { grid-template-columns: 1fr; }
  .presentation-tray {
    position: static;
    width: 100%;
    margin-top: 1rem;
  }
  #presentationView { display: grid; gap: 1rem; }
  .presentation-stage, .presentation-content { min-height: 60vh; }
}

.settings-dialog {
  border: 0;
  padding: 0;
  background: transparent;
}

.settings-dialog::backdrop {
  background: rgba(17, 24, 39, 0.45);
}

.settings-panel {
  width: min(760px, calc(100vw - 2rem));
  padding: 1.25rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(17, 24, 39, 0.08);
  box-shadow: var(--shadow);
}

.compact-dialog {
  width: min(520px, calc(100vw - 2rem));
}

.crop-preview-wrap {
  margin: 1rem 0;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(17, 24, 39, 0.08);
  background: rgba(17, 24, 39, 0.04);
}

#cropCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
}

.settings-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(17, 24, 39, 0.08);
}

.countdown-overlay {
  --countdown-gap: 0.75rem;
  --countdown-padding-y: 0.55rem;
  --countdown-padding-x: 0.9rem;
  --countdown-font-size: 1rem;
  --countdown-pie-size: 2.4rem;
  --countdown-pie-inner-size: 1.4rem;
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: var(--countdown-gap);
  padding: var(--countdown-padding-y) var(--countdown-padding-x);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.56);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  color: white;
  font-size: var(--countdown-font-size);
}

.countdown-overlay.countdown-small {
  --countdown-gap: 0.75rem;
  --countdown-padding-y: 0.55rem;
  --countdown-padding-x: 0.9rem;
  --countdown-font-size: 1rem;
  --countdown-pie-size: 2.4rem;
  --countdown-pie-inner-size: 1.4rem;
}

.countdown-overlay.countdown-medium {
  --countdown-gap: 0.9rem;
  --countdown-padding-y: 0.7rem;
  --countdown-padding-x: 1.1rem;
  --countdown-font-size: 1.2rem;
  --countdown-pie-size: 3rem;
  --countdown-pie-inner-size: 1.8rem;
}

.countdown-overlay.countdown-large {
  --countdown-gap: 1rem;
  --countdown-padding-y: 0.8rem;
  --countdown-padding-x: 1.25rem;
  --countdown-font-size: 1.45rem;
  --countdown-pie-size: 3.6rem;
  --countdown-pie-inner-size: 2.2rem;
}

.points-overlay {
  position: absolute;
  left: 50%;
  bottom: 1.1rem;
  transform: translateX(-50%);
  z-index: 3;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.56);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  color: white;
  font-weight: 700;
  font-size: clamp(1.15rem, 2.2vw, 1.65rem);
  letter-spacing: 0.08em;
}

.countdown-pie {
  width: var(--countdown-pie-size);
  height: var(--countdown-pie-size);
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--countdown-progress, 1) * 1turn), rgba(255, 255, 255, 0.16) 0);
  display: grid;
  place-items: center;
  position: relative;
}

.countdown-pie::after {
  content: "";
  width: var(--countdown-pie-inner-size);
  height: var(--countdown-pie-inner-size);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.9);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
