* {
  box-sizing: border-box;
}

:root {
  color-scheme: light dark;
  --ts-bg: #f4f6f0;
  --ts-card: #ffffff;
  --ts-surface: #f8faf6;
  --ts-surface-hover: #e8efe4;
  --ts-text: #0f172a;
  --ts-muted: #64748b;
  --ts-accent: #7a9468;
  --ts-accent-hover: #5c7350;
  --ts-border: #c5d4bc;
  --ts-header: linear-gradient(135deg, #5c7350, #b8cdb0);
  --ts-on-accent: #ffffff;
  --ts-save-error: #b91c1c;
  --ts-slide-shadow: 0 8px 32px rgba(92, 115, 80, 0.12);
  --ts-thumb-active-bg: #dbeafe;
  --ts-canvas-bg: #ffffff;
  --ts-canvas-text: #0f172a;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ts-bg: #0f172a;
    --ts-card: #1e293b;
    --ts-surface: #1e293b;
    --ts-surface-hover: #334155;
    --ts-text: #ffffff;
    --ts-muted: #94a3b8;
    --ts-accent: #9bb389;
    --ts-accent-hover: #b8cdb0;
    --ts-border: #334155;
    --ts-header: linear-gradient(135deg, #3d4f36, #5c7350);
    --ts-on-accent: #ffffff;
    --ts-save-error: #fecaca;
    --ts-slide-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --ts-thumb-active-bg: rgba(122, 148, 104, 0.28);
    --ts-canvas-bg: #000000;
    --ts-canvas-text: #ffffff;
  }
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--ts-bg);
  color: var(--ts-text);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--ts-accent);
  color: var(--ts-on-accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  background: var(--ts-accent-hover);
}

.btn.secondary {
  background: var(--ts-surface-hover);
  color: var(--ts-text);
}

.btn.secondary:hover {
  background: var(--ts-border);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  gap: 0;
}

.btn-icon.btn-sm {
  width: 32px;
  height: 32px;
}

.btn-icon svg {
  display: block;
  width: 18px;
  height: 18px;
}

.btn-icon.btn-sm svg {
  width: 16px;
  height: 16px;
}

.btn-icon.is-busy {
  opacity: 0.55;
  cursor: wait;
}

.btn-icon img {
  display: block;
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 6px;
}

.editor-header .btn-icon.secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.editor-header .btn-icon.secondary:hover {
  background: rgba(255, 255, 255, 0.28);
}

.editor-header .btn.btn-icon:not(.secondary) {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ts-accent-hover);
}

.editor-header .btn.btn-icon:not(.secondary):hover {
  background: #fff;
}

.editor-hint kbd {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--ts-border);
  background: var(--ts-card);
}

.login-wrap,
.home-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  text-align: center;
}

.card {
  background: var(--ts-card);
  border: 1px solid var(--ts-border);
  border-radius: 16px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--ts-slide-shadow);
}

.login-card h1,
.home-card h1 {
  margin: 0 0 8px;
}

.ts-brand-logo {
  display: block;
  object-fit: contain;
  border-radius: 12px;
}

.ts-brand-logo--login {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
}

.subtitle {
  margin: 0;
  color: var(--ts-muted);
  line-height: 1.5;
}

.editor-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

html:has(body.editor-page) {
  height: 100%;
  overflow: hidden;
}

.ts-editor-chrome {
  flex-shrink: 0;
  z-index: 20;
  background: var(--ts-card);
  max-height: var(--ts-chrome-height, 48px);
  overflow: hidden;
  transition:
    max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.24s ease;
}

body.ts-chrome-hidden .ts-editor-chrome {
  max-height: 0 !important;
  opacity: 0;
  pointer-events: none;
}

#toggleChromeButton svg {
  transition: transform 0.24s ease;
}

body.ts-chrome-hidden #toggleChromeButton svg {
  transform: rotate(180deg);
}

.deck-mount {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.editor-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--ts-header);
  color: #fff;
  flex-shrink: 0;
  z-index: 21;
}

.editor-header-left,
.editor-header-right,
.editor-header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-header-tools {
  flex-wrap: wrap;
}

.slide-title-input {
  min-width: 220px;
  max-width: 420px;
  max-height: 120px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
  field-sizing: content;
}

.slide-title-input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

.save-status {
  font-size: 13px;
  opacity: 0.95;
}

.save-status.error {
  color: #fecaca;
}

.editor-hint {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--ts-muted);
  background: var(--ts-surface);
  border-bottom: 1px solid var(--ts-border);
}

.ts-sidebar {
  width: 180px;
  flex-shrink: 0;
  border-right: 1px solid var(--ts-border);
  background: var(--ts-surface);
  display: flex;
  flex-direction: column;
}

.ts-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--ts-border);
}

.ts-thumbs {
  flex: 1;
  overflow: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ts-thumb {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 6px;
  background: var(--ts-card);
  cursor: pointer;
  text-align: left;
}

.ts-thumb.active {
  border-color: var(--ts-accent);
  background: var(--ts-thumb-active-bg);
}

.ts-thumb-num {
  font-size: 11px;
  color: var(--ts-muted);
  min-width: 14px;
}

.ts-thumb-preview {
  flex: 1;
  min-width: 0;
}

.ts-mini {
  display: block;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  border: 1px solid var(--ts-border);
  padding: 4px;
  overflow: hidden;
  font-size: 8px;
  line-height: 1.2;
}

.ts-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ts-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--ts-border);
  background: var(--ts-card);
  flex-shrink: 0;
  overflow: hidden;
  max-height: var(--ts-toolbar-height, 120px);
  transition:
    max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.24s ease,
    padding 0.24s ease,
    border-width 0.24s ease;
}

body.ts-chrome-hidden .ts-toolbar {
  max-height: 0 !important;
  opacity: 0;
  pointer-events: none;
  padding-top: 0;
  padding-bottom: 0;
  border-bottom-width: 0;
}

.ts-toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--ts-border);
  margin: 0 2px;
}

.ts-build-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ts-muted);
  padding: 4px 6px;
  border: 1px solid var(--ts-border);
  border-radius: 4px;
  user-select: none;
}

.ts-toolbar-spacer {
  flex: 1;
}

.ts-stage-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}

.ts-stage {
  width: min(960px, 100%);
  outline: none;
}

.ts-slide-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  box-shadow: var(--ts-slide-shadow);
  border: 1px solid var(--ts-border);
  overflow: hidden;
  color: var(--ts-canvas-text);
}

@media (prefers-color-scheme: dark) {
  .ts-stage-wrap {
    background: #0f172a;
  }

  .ts-slide-canvas,
  .ts-present-canvas {
    border-color: #334155;
  }
}

.ts-element {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 4px;
  padding: 4px;
  min-height: 0;
}

.ts-element.selected {
  border-color: var(--ts-accent);
}

.ts-element.dragging {
  opacity: 0.92;
  cursor: grabbing;
}

.ts-drag-handle {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 10px;
  border-radius: 4px 4px 0 0;
  background: var(--ts-accent);
  cursor: grab;
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 2;
}

.ts-element.selected .ts-drag-handle,
.ts-element:hover .ts-drag-handle {
  opacity: 1;
}

.ts-drag-handle:active {
  cursor: grabbing;
}

.ts-text {
  width: 100%;
  min-height: 1em;
  height: auto;
  outline: none;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
}

.ts-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.ts-mini-image {
  font-size: 10px;
  line-height: 1;
}

.ts-present-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.ts-present-close {
  position: absolute;
  top: 16px;
  right: 16px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  cursor: pointer;
}

.ts-present-close svg {
  width: 20px;
  height: 20px;
}

.ts-present-stage {
  width: min(1200px, 96vw);
}

.ts-present-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.ts-present-el {
  position: absolute;
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
}

.ts-present-image {
  padding: 0;
}

.ts-present-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ts-export-host {
  position: fixed;
  left: -10000px;
  top: 0;
  pointer-events: none;
}

.ts-export-slide {
  position: relative;
  width: 960px;
  height: 540px;
  overflow: hidden;
}

.ts-export-el {
  position: absolute;
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
  box-sizing: border-box;
}

.ts-export-image {
  padding: 0;
}

.ts-export-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.ts-present-nav {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: #fff;
}

.ts-present-nav .btn-icon {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.ts-present-nav .btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

dialog {
  border: 1px solid var(--ts-border);
  border-radius: 12px;
  padding: 20px;
  max-width: 480px;
  background: var(--ts-card);
  color: var(--ts-text);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

@media (prefers-color-scheme: dark) {
  dialog::backdrop {
    background: rgba(0, 0, 0, 0.62);
  }
}

.dialog-hint {
  color: var(--ts-muted);
  font-size: 14px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

label {
  display: block;
  margin-top: 12px;
  font-size: 14px;
}

label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--ts-border);
  background: var(--ts-surface);
  color: var(--ts-text);
}

@media (max-width: 800px) {
  .ts-sidebar {
    width: 120px;
  }

  .editor-header {
    flex-wrap: wrap;
  }
}
