:root {
  /* Solarized Dark Palette */
  --base03: #002b36;
  --base02: #073642;
  --base01: #586e75;
  --base00: #657b83;
  --base0: #839496;
  --base1: #93a1a1;
  --base2: #eee8d5;
  --base3: #fdf6e3;
  --yellow: #b58900;
  --orange: #cb4b16;
  --red: #dc322f;
  --magenta: #d33682;
  --violet: #6c71c4;
  --blue: #268bd2;
  --cyan: #2aa198;
  --green: #859900;

  /* App Variables */
  --bg: var(--base03);
  --panel: var(--base02);
  --panel-strong: var(--base02); /* Using same base02 but could be adjusted if needed */
  --text: var(--base0);
  --muted: var(--base01);
  --border: var(--base02); /* Borders same as panels for subtlety, or could use base01 */
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.4); /* Kept slightly stronger shadow for depth */
  --radius: 16px;
  --accent: var(--cyan);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg); /* Removed radial gradients for clean flat look */
  color: var(--text);
}

.app {
  height: 100vh;
  width: 100vw;
  padding: 18px;
  display: grid;
  grid-template-rows: 1fr;
  gap: 14px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(0, 3fr) minmax(220px, 1.2fr);
  gap: 18px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* backdrop-filter: blur(10px); Removed as we have solid colors mostly */
  overflow: hidden;
  min-height: 0; /* enables internal scroll areas */
}

/* LEFT: Form */
.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
}

.sidebar__header {
  padding: 18px 18px 10px;
  border-bottom: 1px solid var(--base03); /* Darker border for contrast */
}

.title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--base1); /* Slightly brighter title */
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.jump-buttons {
  display: none;
  gap: 10px;
  margin-top: 12px;
}

.icon-button {
  border: 1px solid var(--base03);
  background: var(--base03);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.icon-button:hover {
  background: var(--base01);
  color: var(--base3);
}

.icon-button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.sample-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--cyan);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.sample-link:hover {
  color: var(--base1);
}

.sample-link:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.sidebar__body {
  padding: 16px 18px 18px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  flex: 1;
  min-height: 0;
}

label {
  font-size: 12px;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  background: var(--base03);
  border: 1px solid var(--base01);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue);
}

textarea {
  resize: none;
  min-height: 0;
  flex: 1;
}

.text-input {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.text-input__area {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

.text-highlight {
  position: absolute;
  inset: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--base03);
  color: var(--text);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
  line-height: inherit;
  pointer-events: none;
  scrollbar-width: none;
}

.text-highlight:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.text-highlight::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.text-highlight__mark {
  background: rgba(220, 50, 47, 0.25); /* red alpha */
  color: #ffb3b3; /* keep light red text for contrast on dark bg */
  border-radius: 0;
  padding: 0;
  margin: 0;
  display: inline;
  line-height: inherit;
}

.text-highlight__mark--search {
  background: rgba(133, 153, 0, 0.25); /* green alpha */
  color: #d4ffe4;
}

.text-highlight__mark--search-and-hover {
  background: rgba(38, 139, 210, 0.25); /* blue alpha */
  color: #d49ff4;
}

.text-input__area textarea {
  position: relative;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  font: inherit;
  line-height: inherit;
  z-index: 1;
}

.text-input__area textarea::placeholder {
  color: transparent;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* RIGHT: Canvas */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  align-items: stretch;
}

.stage__toolbar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--base03);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--base01);
  background: var(--base03);
  white-space: nowrap;
}

.canvasWrap {
  position: relative;
  min-height: 0;
  flex: 1;
  width: 100%;
  height: 100%;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 14px;
  background: var(--base03);
  border: 1px solid var(--base01);
  touch-action: pan-y;
}

/* Bottom timeline */
.timeline {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.timeline__header {
  padding: 12px 16px 0;
}

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

.timeline__header-row .icon-button {
  display: none;
}

.timeline__frames {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 8px 0 10px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--base01) var(--base03);
}

.timeline__frames::-webkit-scrollbar {
  width: 10px;
}

.timeline__frames::-webkit-scrollbar-track {
  background: var(--base03);
  border-radius: 999px;
}

.timeline__frames::-webkit-scrollbar-thumb {
  background: var(--base01);
  border-radius: 999px;
}

.timeline__frame {
  width: 100%;
  min-height: 58px;
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid var(--base03);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 2px;
  align-items: start;
  padding: 10px 16px;
  text-align: left;
  cursor: pointer;
  user-select: none;
  appearance: none;
  font-family: inherit;
}

.timeline__frame:first-child {
  border-top: 1px solid var(--base03);
}

.timeline__frame:hover {
  background: var(--base02); /* slightly lighter than base03 */
  color: var(--text);
}

.timeline__frame:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.timeline__frame--active {
  background: rgba(42, 161, 152, 0.1); /* active cyan tint */
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.timeline__frame__label__char {
  background: rgba(133, 153, 0, 0.3); /* green tint */
}
.timeline__frame__label__cont-char {
  background: rgba(181, 137, 0, 0.3); /* yellow tint */
}

.timeline__frame__index {
  grid-row: 1 / span 2;
  align-self: start;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.timeline__frame__label {
  grid-column: 2;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.timeline__frame__meta {
  grid-column: 2;
  font-size: 11px;
  color: var(--muted);
}

.timeline__frame__details {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px dashed var(--base01);
}

.timeline__frame__detail {
  display: grid;
  grid-template-columns: minmax(0, 140px) minmax(0, 1fr);
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}

.timeline__frame__detail-key {
  color: var(--muted);
}

.timeline__frame__detail-value {
  color: var(--text);
  overflow-wrap: anywhere;
}

.timeline__empty {
  color: var(--muted);
  font-size: 12px;
  padding: 12px 0;
}

/* Responsive: stack on small screens */
@media (max-width: 900px) {
  .app {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(100vh, auto) minmax(100vh, auto) minmax(100vh, auto);
  }

  .panel {
    min-height: 100vh;
  }

  .jump-buttons {
    display: flex;
  }

  .timeline {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }

  .timeline__header-row .icon-button {
    display: inline-flex;
  }
}

#dialog-message::backdrop {
  backdrop-filter: blur(2px);
  background: rgba(0, 43, 54, 0.8);
}
#dialog-message {
  background: var(--base02);
  border: 1px solid var(--cyan);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
}

#dialog-message-inner-wrapper {
  padding: 18px;
  background: var(--base02);
  border-radius: 9px;
}
