:root {
  color-scheme: dark;
  --bg: #111111;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --secondary: #8a8a8a;
  --accent: #3d5afe;
  --accent-hover: #304ffe;
  --danger: #e05c4f;
  --danger-border: #c0392b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  accent-color: var(--accent);
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.gate-screen {
  --lamp-hex: #06b6d4;
  --lamp-rgb: 6, 182, 212;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #080a10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  transition: opacity 280ms ease;
}

.gate-screen.gate-leaving {
  opacity: 0;
  pointer-events: none;
}

.room-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 42%, rgba(var(--lamp-rgb), 0.16) 0%, rgba(var(--lamp-rgb), 0.05) 32%, transparent 65%),
    radial-gradient(ellipse at 50% 100%, rgba(15, 23, 42, 0.7) 0%, #06080d 70%);
  opacity: 0;
  transition: opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.gate-screen.lamp-on .room-backdrop {
  opacity: 1;
}

.desk-surface {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22vh;
  min-height: 110px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.16) 0%, rgba(4, 6, 11, 0.94) 100%);
  border-top: 1px solid rgba(148, 163, 184, 0.06);
  z-index: 1;
  pointer-events: none;
}

.lamp-stage {
  position: relative;
  width: 340px;
  height: 430px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  z-index: 2;
}

.lamp-beam-outer {
  position: absolute;
  top: 150px;
  left: 206px;
  width: 620px;
  height: 440px;
  pointer-events: none;
  transform-origin: 0% 0%;
  transform: rotate(-10deg);
  background: conic-gradient(
    from 118deg at 0px 0px,
    transparent 0deg,
    rgba(var(--lamp-rgb), 0.04) 8deg,
    rgba(var(--lamp-rgb), 0.28) 24deg,
    rgba(var(--lamp-rgb), 0.36) 36deg,
    rgba(var(--lamp-rgb), 0.24) 48deg,
    rgba(var(--lamp-rgb), 0.04) 64deg,
    transparent 74deg
  );
  filter: blur(16px);
  opacity: 0;
  transition: opacity 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 1;
}

.lamp-beam-core {
  position: absolute;
  top: 148px;
  left: 204px;
  width: 340px;
  height: 290px;
  pointer-events: none;
  transform-origin: 0% 0%;
  transform: rotate(-10deg);
  background: radial-gradient(
    ellipse 82% 62% at 22% 28%,
    rgba(255, 255, 255, 0.34) 0%,
    rgba(var(--lamp-rgb), 0.38) 26%,
    rgba(var(--lamp-rgb), 0.1) 56%,
    transparent 78%
  );
  filter: blur(13px);
  opacity: 0;
  transition: opacity 0.38s ease;
  z-index: 2;
}

.lamp-floor-pool {
  position: absolute;
  bottom: 18px;
  left: 65px;
  width: 380px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(var(--lamp-rgb), 0.38) 0%,
    rgba(var(--lamp-rgb), 0.14) 45%,
    transparent 75%
  );
  filter: blur(14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 1;
}

.gate-screen.lamp-on .lamp-beam-outer,
.gate-screen.lamp-on .lamp-beam-core,
.gate-screen.lamp-on .lamp-floor-pool {
  opacity: 1;
}

.lamp-svg {
  position: relative;
  width: 340px;
  height: 430px;
  overflow: visible;
  touch-action: none;
  z-index: 4;
}

.lamp-shade-top {
  pointer-events: none;
}

.lamp-bulb-glow {
  opacity: 0;
  transition: opacity 0.25s ease;
  fill: var(--lamp-hex);
  filter: drop-shadow(0 0 18px var(--lamp-hex)) drop-shadow(0 0 36px var(--lamp-hex));
}

.lamp-inner-glow {
  opacity: 0.08;
  fill: var(--lamp-hex);
  transition: opacity 0.3s ease;
}

.gate-screen.lamp-on .lamp-bulb-glow {
  opacity: 1;
}

.gate-screen.lamp-on .lamp-inner-glow {
  opacity: 0.92;
}

.lamp-cord-hit {
  cursor: grab;
  touch-action: none;
}

.lamp-cord-hit:active {
  cursor: grabbing;
}

.lamp-hint {
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  letter-spacing: 0.03em;
  color: #64748b;
  white-space: nowrap;
  z-index: 5;
}

.lamp-hint svg {
  color: var(--lamp-hex);
}

.gate-screen.lamp-on .lamp-hint {
  color: #94a3b8;
}

.secondary {
  color: var(--secondary);
  font-size: 13px;
}

.page {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.editor-page {
  max-width: 1120px;
}

.home-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.brand-logo {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  flex-shrink: 0;
}

.home-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.import-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.text-input,
.title-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 15px;
  width: 100%;
  transition: border-color 150ms;
}

.text-input:focus,
.title-input:focus {
  border-color: var(--accent);
  outline: none;
}

.title-input {
  font-size: 20px;
  font-weight: 600;
  padding: 4px 10px;
  min-width: 0;
  flex: 1;
}

.drop-zone {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 28px 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  transition: border-color 150ms, background-color 150ms;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: #161926;
}

.drop-text {
  margin: 0;
  font-size: 15px;
}

.drop-sub {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--secondary);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 7px 14px;
  font-size: 15px;
  font-weight: 500;
  transition: background-color 150ms, border-color 150ms;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 13px;
  transition: background-color 150ms, border-color 150ms;
}

.btn-outline:hover {
  background: var(--surface);
  border-color: #444444;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text);
  text-decoration: none;
  padding: 4px 6px;
  font-size: 13px;
  border-radius: 4px;
  transition: background-color 150ms;
}

.link-btn:hover {
  background: var(--surface);
}

.link-danger {
  background: none;
  border: none;
  color: var(--danger);
  padding: 4px 6px;
  font-size: 13px;
  border-radius: 4px;
  transition: background-color 150ms;
}

.link-danger:hover {
  background: #241414;
}

.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

progress {
  width: 100%;
  height: 6px;
  border-radius: 3px;
}

.error-text {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}

.deck-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.deck-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.deck-thumb {
  width: 72px;
  height: 44px;
  object-fit: cover;
  background: #000000;
  border: 1px solid var(--border);
  border-radius: 2px;
  flex-shrink: 0;
}

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

.deck-name {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deck-meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--secondary);
}

.deck-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.storage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  padding-top: 12px;
  flex-wrap: wrap;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.editor-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 220px;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.slide-grid {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.slide-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  cursor: grab;
  transition: border-color 150ms;
}

.slide-card:hover {
  border-color: #444444;
}

.slide-card.dragging {
  opacity: 0.4;
}

.slide-card.drag-target {
  border-color: var(--accent);
}

.slide-open-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: #000000;
  aspect-ratio: 16 / 9;
}

.slide-open-btn img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.slide-num {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(17, 17, 17, 0.85);
  border: 1px solid var(--border);
  padding: 1px 5px;
  font-size: 13px;
  line-height: 1.2;
  pointer-events: none;
}

.stroke-dot {
  position: absolute;
  right: 30px;
  top: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  pointer-events: none;
}

.slide-del-btn {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 17, 0.85);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--secondary);
  padding: 0;
  transition: border-color 150ms, color 150ms;
}

.slide-del-btn:hover {
  border-color: var(--danger-border);
  color: var(--danger);
}

.present-stage {
  --notes-h: 0px;
  position: fixed;
  inset: 0;
  background: #000000;
  overflow: hidden;
  user-select: none;
}

.present-stage.has-notes {
  --notes-h: 120px;
}

.present-stage.hide-cursor {
  cursor: none;
}

.present-stage.can-pan {
  cursor: grab;
}

.present-stage.panning,
.present-stage.panning * {
  cursor: grabbing !important;
}

.slide-img,
.draw-canvas {
  position: absolute;
  display: block;
}

.slide-img {
  z-index: 1;
  pointer-events: none;
}

.board-screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--notes-h);
  z-index: 2;
  background: #000000;
}

.board-screen.white {
  background: #ffffff;
}

.draw-canvas {
  z-index: 3;
  pointer-events: none;
}

.draw-canvas.drawing {
  pointer-events: auto;
  touch-action: none;
}

.draw-canvas.grabbing {
  cursor: grabbing !important;
}

.present-timer {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 5;
  font-size: 13px;
  color: rgba(232, 232, 232, 0.72);
  background: rgba(17, 17, 17, 0.65);
  border: 1px solid rgba(42, 42, 42, 0.7);
  padding: 2px 7px;
  border-radius: 3px;
  pointer-events: none;
}

.jump-indicator {
  position: fixed;
  top: 12px;
  left: 14px;
  z-index: 5;
  font-size: 13px;
  color: var(--text);
  background: rgba(17, 17, 17, 0.85);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 3px;
  pointer-events: none;
}

.present-hud {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + var(--notes-h));
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.present-left-hud {
  display: flex;
  align-items: center;
  gap: 6px;
}

.present-counter {
  font-size: 13px;
  color: rgba(232, 232, 232, 0.65);
  background: rgba(17, 17, 17, 0.6);
  padding: 2px 6px;
  border-radius: 3px;
}

.zoom-indicator {
  font-size: 13px;
  color: var(--text);
  background: rgba(26, 26, 26, 0.8);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: auto;
  transition: border-color 150ms, background-color 150ms;
}

.zoom-indicator:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.present-controls {
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.nav-arrow {
  position: fixed;
  top: calc((100% - var(--notes-h)) / 2);
  transform: translateY(-50%);
  z-index: 5;
  width: 36px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 26, 0.7);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0;
  opacity: 0.25;
  transition: opacity 150ms, background-color 150ms, border-color 150ms;
}

.nav-arrow:hover,
.nav-arrow:focus-visible {
  opacity: 0.95;
  background: var(--surface);
  border-color: #444444;
}

.nav-prev {
  left: 12px;
}

.nav-next {
  right: 12px;
}

.hud-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 26, 0.75);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: rgba(232, 232, 232, 0.85);
  padding: 0;
  opacity: 0.35;
  transition: opacity 150ms, background-color 150ms, border-color 150ms;
}

.hud-btn:hover,
.hud-btn:focus-visible {
  opacity: 1;
  background: var(--surface);
  border-color: #444444;
  color: var(--text);
}

.present-progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--notes-h);
  height: 2px;
  z-index: 5;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.present-progress-fill {
  height: 100%;
  width: 0;
  background: rgba(61, 90, 254, 0.85);
}

.speaker-notes {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 120px;
  z-index: 7;
  background: #141414;
  border-top: 1px solid var(--border);
  display: flex;
  user-select: text;
}

.speaker-note-input {
  width: 100%;
  height: 100%;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding: 10px 16px;
  outline: none;
}

.speaker-note-input::placeholder {
  color: var(--secondary);
}

.draw-toolbar {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--notes-h));
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.tb-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text);
  padding: 0;
  transition: background-color 150ms, border-color 150ms;
}

.tb-btn:hover {
  background: #242424;
  border-color: var(--border);
}

.tb-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.tb-btn.tb-danger:hover {
  border-color: var(--danger-border);
  color: var(--danger);
}

.tb-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.color-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  padding: 0;
  transition: border-color 150ms;
}

.color-btn[data-color="#ff1744"] { background: #ff1744; }
.color-btn[data-color="#ffea00"] { background: #ffea00; }
.color-btn[data-color="#00e676"] { background: #00e676; }
.color-btn[data-color="#2979ff"] { background: #2979ff; }
.color-btn[data-color="#ffffff"] { background: #ffffff; }
.color-btn[data-color="#000000"] { background: #000000; }

.color-btn[aria-pressed="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.size-slider {
  width: 76px;
  cursor: pointer;
}

.help-dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 20px;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
}

.help-dialog:modal {
  overscroll-behavior: contain;
}

.help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
  overflow: hidden;
  overscroll-behavior: contain;
}

.help-dialog h1 {
  margin: 0 0 14px;
  font-size: 20px;
  font-weight: 600;
}

.help-dialog h2 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.hotkey-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hotkey-list > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.hotkey-list dt {
  color: var(--text);
  white-space: nowrap;
}

.hotkey-list dd {
  margin: 0;
  color: var(--secondary);
  text-align: right;
}

.help-note {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.help-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

@supports not (accent-color: #3d5afe) {
  .size-slider {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
  }

  .size-slider::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
  }

  .size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -5px;
  }

  .size-slider::-moz-range-track {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
  }

  .size-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
  }

  progress {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border: none;
    background: var(--border);
  }

  progress::-webkit-progress-bar {
    background: var(--border);
  }

  progress::-webkit-progress-value {
    background: var(--accent);
  }

  progress::-moz-progress-bar {
    background: var(--accent);
  }
}

@media (max-width: 560px) {
  .deck-row {
    flex-wrap: wrap;
    gap: 10px;
  }

  .deck-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .slide-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}
