:root {
  color-scheme: dark;
  --bg: #070b14;
  --surface: #0b1220;
  --surface-2: #0f172a;
  --surface-3: #111827;
  --border: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.36);
  --text: #e5edf8;
  --muted: #94a3b8;
  --subtle: #64748b;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.16);
  --q1: #3b82f6;
  --q2: #22c55e;
  --q3: #facc15;
  --q4: #ef4444;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button,
select {
  font: inherit;
}

button,
select,
.cte-back {
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: rgba(15, 23, 42, 0.76);
}

button {
  min-height: 36px;
  padding: 0 11px;
  cursor: pointer;
}

button:hover,
button:focus-visible,
select:focus-visible,
.cte-back:focus-visible {
  border-color: rgba(56, 189, 248, 0.72);
  outline: none;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

select {
  min-height: 36px;
  padding: 0 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.76rem;
}

[hidden] {
  display: none !important;
}

.cte-app {
  display: grid;
  grid-template-rows: 66px minmax(0, 1fr) 64px;
  width: 100vw;
  height: 100vh;
}

.cte-topbar,
.cte-bottom {
  display: flex;
  align-items: center;
  gap: 14px;
  border-color: var(--border);
  background: rgba(3, 7, 18, 0.92);
}

.cte-topbar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.cte-bottom {
  min-width: 0;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.cte-back {
  display: inline-grid;
  place-items: center;
  min-width: 72px;
  min-height: 40px;
  color: inherit;
  text-decoration: none;
}

.cte-title-block {
  display: grid;
  gap: 2px;
  min-width: 300px;
}

.cte-title-block h1 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.cte-title-block p,
.cte-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.cte-top-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.cte-workbench {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 330px;
  min-height: 0;
}

.cte-rail,
.cte-inspector {
  min-height: 0;
  overflow: auto;
  background: rgba(3, 7, 18, 0.58);
}

.cte-rail {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 12px;
  border-right: 1px solid var(--border);
}

.cte-inspector {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 12px;
  border-left: 1px solid var(--border);
}

.cte-tool-block,
.cte-panel-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.56);
}

.cte-mode-stack,
.cte-tool-grid,
.cte-events,
.cte-suggestions,
.cte-summary,
.cte-selection {
  display: grid;
  gap: 8px;
}

.cte-mode-stack button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 48px;
  text-align: left;
}

.cte-mode-stack button span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border-radius: 6px;
  color: #dbeafe;
  background: rgba(59, 130, 246, 0.18);
  font-size: 0.78rem;
  font-weight: 900;
}

.cte-mode-stack button strong {
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cte-tool-grid {
  grid-template-columns: 1fr;
}

.cte-row {
  display: flex;
  gap: 8px;
}

.cte-row button {
  flex: 1;
}

.cte-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.cte-check {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.58);
}

.cte-check input {
  accent-color: var(--accent);
}

.cte-mode-stack button.is-active,
.cte-tool-grid button.is-active,
.cte-timeline button.is-active {
  border-color: rgba(56, 189, 248, 0.82);
  background: var(--accent-soft);
}

.cte-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #070b14;
}

.cte-canvas-wrap {
  position: absolute;
  inset: 0;
}

.cte-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.cte-loading,
.cte-fallback {
  position: absolute;
  z-index: 8;
  top: 50%;
  left: 50%;
  display: grid;
  gap: 8px;
  min-width: min(360px, calc(100vw - 32px));
  padding: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.96);
  transform: translate(-50%, -50%);
}

.cte-loading span,
.cte-fallback span {
  color: var(--muted);
}

.cte-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 8px;
  color: var(--text);
  background: rgba(3, 7, 18, 0.92);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
}

.cte-tooltip strong,
.cte-tooltip span {
  display: block;
}

.cte-tooltip span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
}

.cte-flip-card {
  display: grid;
  place-items: center;
  min-height: 80px;
  border: 1px solid rgba(56, 189, 248, 0.36);
  border-radius: 8px;
  color: #f8fafc;
  background: rgba(56, 189, 248, 0.11);
  font-size: 2.1rem;
  font-weight: 900;
}

.cte-event {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 54px;
  padding: 9px 10px;
  text-align: left;
}

.cte-event strong {
  font-size: 0.9rem;
}

.cte-event span,
.cte-summary span,
.cte-selection span {
  color: var(--muted);
  font-size: 0.78rem;
}

.cte-summary strong,
.cte-selection strong {
  color: #f8fafc;
  font-size: 0.95rem;
}

.cte-summary p,
.cte-selection p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.cte-transition-phase {
  display: block;
  min-height: 28px;
  color: #e5edf8;
  font-size: 0.98rem;
}

.cte-timeline {
  display: flex;
  flex: 1;
  gap: 7px;
  min-width: 0;
  overflow: auto;
}

.cte-timeline button {
  min-width: 70px;
}

.cte-scale {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.cte-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.cte-dot.q1 {
  background: var(--q1);
}

.cte-dot.q2 {
  background: var(--q2);
}

.cte-dot.q3 {
  background: var(--q3);
}

.cte-dot.q4 {
  background: var(--q4);
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .cte-app {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto auto auto;
  }

  .cte-topbar,
  .cte-top-controls {
    align-items: stretch;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .cte-title-block {
    min-width: 0;
  }

  .cte-workbench {
    grid-template-columns: 1fr;
  }

  .cte-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .cte-stage {
    min-height: 64vh;
  }

  .cte-inspector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 720px) {
  .cte-top-controls label,
  .cte-top-controls select {
    width: 100%;
  }

  .cte-rail,
  .cte-inspector {
    grid-template-columns: 1fr;
  }

  .cte-row,
  .cte-bottom {
    align-items: stretch;
    flex-direction: column;
  }

  .cte-scale {
    flex-wrap: wrap;
    white-space: normal;
  }
}
