:root {
  --bg: #0b0d12;
  --panel: #121821;
  --panel-2: #1a2230;
  --panel-3: #0f141d;
  --text: #ebf0f8;
  --muted: #97a4b5;
  --line: #283244;
  --accent: #e8bf52;
  --accent-2: #3c82f6;
  --danger: #df5b5b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top left, #1b2331 0%, #0c1017 42%, #07090d 100%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button,
input,
textarea,
.section,
.topbar,
.stage,
.sidebar,
.timeline-sidebar,
.home-shell,
.modal-card {
  border: 1px solid rgba(255, 255, 255, 0.05);
}

button,
input,
textarea {
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

button {
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

button:hover {
  transform: translateY(-1px);
}

.pill-btn {
  border-radius: 999px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.14);
}

button.primary {
  background: var(--accent-2);
  border-color: #2f6bd0;
}

button.accent {
  background: var(--accent);
  color: #261f0a;
  border-color: #cda233;
  font-weight: 700;
}

button.danger {
  background: rgba(223, 91, 91, 0.14);
  border-color: rgba(223, 91, 91, 0.4);
}

.topbar {
  margin: 16px 16px 0;
  padding: 10px 14px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: rgba(18, 24, 33, 0.92);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
}

.topbar-brand,
.topbar-actions,
.topbar-copy {
  min-width: 0;
}

.topbar-brand,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex: 1 1 auto;
  justify-content: center;
  flex-wrap: wrap;
}

.topbar-logo {
  display: block;
  width: auto;
  max-width: 64px;
  max-height: 64px;
}

.topbar-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.language-toggle {
  white-space: nowrap;
  background: rgba(18, 24, 33, 0.94);
}

.language-toggle[aria-pressed="true"] {
  border-color: rgba(60, 130, 246, 0.75);
  box-shadow: 0 14px 28px rgba(60, 130, 246, 0.18);
}

.is-hidden {
  display: none !important;
}

.home {
  min-height: 100vh;
  padding: 16px 20px 26px;
  display: grid;
  place-items: start center;
}

.home-shell,
.stage,
.sidebar,
.timeline-sidebar {
  background: rgba(18, 24, 33, 0.92);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

.home-shell {
  width: min(1080px, 100%);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app {
  display: grid;
  grid-template-columns: 300px minmax(320px, 1fr) 380px;
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.timeline-sidebar,
.sidebar {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.stage {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.section {
  background: var(--panel-2);
  border-radius: 14px;
  padding: 14px;
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section h3 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.section-head h3 {
  margin-bottom: 0;
}

.toolbar,
.home-actions,
.selection-actions,
.layer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.toolbar label,
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.toolbar input,
.field input,
.field textarea {
  width: 100%;
  min-width: 0;
}

.selection-actions button,
.layer-actions button {
  flex: 1 1 128px;
}

.menu-bar {
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-center {
  display: flex;
  justify-content: center;
  width: 100%;
}

.project-badge {
  font-size: 22px;
  line-height: 1.2;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(100%, 760px);
}

.canvas-wrap {
  background: linear-gradient(180deg, #0d1118, #0a0d13);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  min-height: 420px;
}

canvas {
  display: block;
  background: #f6f0df;
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08), 0 20px 40px rgba(0, 0, 0, 0.28);
}

.stage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  justify-content: space-between;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.status,
.hint,
.project-meta,
.timeline-subtitle,
.layer-subtitle {
  color: var(--muted);
}

.status,
.hint {
  font-size: 12px;
  line-height: 1.5;
}

.timeline-list,
.layer-list,
.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline-list,
.layer-list {
  max-height: 320px;
  overflow: auto;
}

.timeline-item,
.layer-item,
.project-row {
  border-radius: 12px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  min-width: 0;
}

.timeline-item,
.layer-item {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timeline-item.is-selected,
.layer-item.is-selected {
  border-color: var(--accent-2);
  background: rgba(60, 130, 246, 0.12);
}

.timeline-title,
.layer-title,
.project-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-subtitle,
.layer-subtitle,
.project-meta {
  font-size: 11px;
}

.kv {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px 12px;
  font-size: 13px;
}

.kv div {
  background: var(--panel-3);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 36px;
  display: flex;
  align-items: center;
  overflow-wrap: anywhere;
}

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

.field.full,
.field-grid .full {
  grid-column: 1 / -1;
}

textarea {
  resize: vertical;
}

.color-input,
.import-textarea {
  width: 100%;
}

.color-input {
  min-height: 44px;
  padding: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
}

.layer-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

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

.color-chip {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.project-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
}

.project-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.project-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.project-actions .pill-btn {
  padding: 8px 12px;
  font-size: 12px;
  min-width: 88px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 6, 12, 0.72);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  background: rgba(18, 24, 33, 0.98);
  border-radius: 20px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.45);
  padding: 18px;
}

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

.modal-title {
  margin: 0;
  font-size: 18px;
}

.modal-text {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.6;
}

.modal-link {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 700;
}

.modal-link:hover {
  text-decoration: underline;
}

.modal-close {
  padding: 8px 12px;
}

.import-textarea {
  min-height: 260px;
}

@media (max-width: 1280px) {
  .app {
    grid-template-columns: 280px minmax(320px, 1fr);
  }

  .sidebar {
    grid-column: 1 / -1;
  }
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
  }

  .timeline-sidebar {
    order: 2;
  }

  .stage {
    order: 1;
  }

  .sidebar {
    order: 3;
  }
}

@media (max-width: 520px) {
  .topbar {
    margin: 12px 12px 0;
    padding: 10px 12px;
    gap: 10px;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .field-grid,
  .kv {
    grid-template-columns: 1fr;
  }

  .app,
  .home {
    padding-left: 12px;
    padding-right: 12px;
  }

  .modal {
    padding: 14px;
  }
}
