:root {
  color-scheme: dark;
  --bg: #070a0b;
  --surface: #0d1112;
  --surface-raised: #131718;
  --surface-input: #080b0c;
  --ink: #f1f6f5;
  --muted: #98a3a1;
  --faint: #66706f;
  --line: rgba(225, 242, 238, 0.12);
  --line-strong: rgba(116, 236, 255, 0.34);
  --cyan: #74ecff;
  --green: #7cf2b1;
  --amber: #ffd36b;
  --danger: #ff766d;
  --studio-header: 62px;
  --studio-footer: 32px;
  --rail-width: 336px;
  font-family: "Segoe UI", Inter, Arial, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea { font: inherit; }

button,
a,
input,
select,
textarea { outline: none; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: 0 0 0 1px var(--cyan), 0 0 0 3px rgba(116, 236, 255, 0.15);
}

.studio-header {
  position: relative;
  z-index: 10;
  height: var(--studio-header);
  display: grid;
  grid-template-columns: max-content minmax(330px, 460px) max-content 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 12, 13, 0.96);
}

.studio-brand {
  min-width: 156px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border: 1px solid var(--cyan);
  border-radius: 50%;
  box-shadow: inset 0 0 10px rgba(116, 236, 255, 0.28), 0 0 12px rgba(116, 236, 255, 0.18);
}

.studio-brand strong,
.studio-brand small { display: block; letter-spacing: 0; }
.studio-brand strong { font-size: 12px; font-weight: 650; }
.studio-brand small { margin-top: 2px; color: var(--faint); font: 8px/1.2 Consolas, monospace; }

.preset-suite,
.preset-name,
.preset-picker,
.token-search,
.version-section label { display: grid; gap: 5px; }

.preset-suite {
  grid-template-columns: minmax(128px, 0.72fr) minmax(190px, 1.28fr);
  align-items: end;
  gap: 8px;
}

.preset-name span,
.preset-picker span,
.token-search span,
.version-section label span {
  color: var(--faint);
  font: 9px/1 Consolas, monospace;
  text-transform: uppercase;
}

.preset-name input,
.preset-picker select,
.token-search input,
.version-section input,
.control-input,
.advanced-section textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-input);
  color: var(--ink);
}

.preset-name input,
.preset-picker select {
  height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.preset-picker select { cursor: pointer; }

.viewport-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(58px, 1fr));
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.viewport-switch button,
.studio-actions button,
.group-tabs button {
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.viewport-switch button {
  border-right: 1px solid var(--line);
  padding: 0 10px;
  font-size: 10px;
}

.viewport-switch button:last-child { border-right: 0; }
.viewport-switch button.active { background: rgba(116, 236, 255, 0.1); color: var(--cyan); }

.studio-actions {
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.studio-actions button {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-raised);
  font-size: 10px;
  white-space: nowrap;
}

.studio-actions button:hover { border-color: var(--line-strong); color: var(--ink); }
.studio-actions .primary { border-color: rgba(116, 236, 255, 0.38); background: rgba(32, 92, 101, 0.3); color: var(--cyan); }
.studio-actions .icon-action { width: 34px; padding: 0; font-size: 17px; }
.studio-actions .reset-action { color: var(--amber); }

.studio-shell {
  height: calc(100vh - var(--studio-header) - var(--studio-footer));
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  min-width: 0;
}

.token-rail {
  min-width: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  scrollbar-color: rgba(116, 236, 255, 0.24) transparent;
  scrollbar-width: thin;
}

.rail-tools {
  position: sticky;
  z-index: 3;
  top: 0;
  padding: 14px 14px 0;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 17, 18, 0.98);
}

.token-search input {
  height: 34px;
  padding: 0 10px;
  font-size: 11px;
}

.group-tabs {
  display: flex;
  gap: 0;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.group-tabs::-webkit-scrollbar { display: none; }

.group-tabs button {
  position: relative;
  height: 32px;
  padding: 0 9px;
  flex: 0 0 auto;
  font: 9px/1 Consolas, monospace;
  text-transform: uppercase;
}

.group-tabs button::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 0;
  left: 8px;
  height: 1px;
  background: transparent;
}

.group-tabs button.active { color: var(--cyan); }
.group-tabs button.active::after { background: var(--cyan); }

.token-group,
.advanced-section,
.version-section {
  padding: 17px 14px 8px;
  border-bottom: 1px solid var(--line);
}

.token-group[hidden],
.token-row[hidden] { display: none; }

.token-group > header,
.advanced-section > header,
.version-section > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.token-group h2,
.advanced-section h2,
.version-section h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 560;
}

.token-group header p,
.advanced-section header p,
.version-section header p {
  margin: 0;
  color: var(--faint);
  font: 8px/1 Consolas, monospace;
  text-transform: uppercase;
}

.token-list { display: grid; }

.token-row {
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(94px, 1fr) minmax(128px, 1.24fr);
  align-items: center;
  gap: 10px;
  border-top: 1px solid rgba(225, 242, 238, 0.07);
}

.token-row:first-child { border-top: 0; }
.token-label { min-width: 0; }
.token-label strong { display: block; overflow: hidden; color: var(--muted); font-size: 10px; font-weight: 520; text-overflow: ellipsis; white-space: nowrap; }
.token-label code { display: block; margin-top: 3px; overflow: hidden; color: var(--faint); font: 8px/1 Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }

.control-wrap {
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.control-input,
select.control-input {
  height: 30px;
  min-width: 0;
  padding: 0 8px;
  font-size: 10px;
}

select.control-input { cursor: pointer; }

.color-input {
  width: 31px;
  height: 30px;
  flex: 0 0 31px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-input);
  cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 1px; }

.range-input {
  width: 100%;
  min-width: 60px;
  accent-color: var(--cyan);
}

.number-input {
  width: 58px;
  height: 28px;
  flex: 0 0 58px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-input);
  color: var(--ink);
  font: 9px/1 Consolas, monospace;
}

.unit-label { width: 24px; flex: 0 0 24px; color: var(--faint); font: 8px/1 Consolas, monospace; }

.toggle-input {
  position: relative;
  width: 34px;
  height: 18px;
  flex: 0 0 34px;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #050708;
  cursor: pointer;
}

.toggle-input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--faint);
  transition: transform 160ms ease, background 160ms ease;
}

.toggle-input:checked { border-color: rgba(116, 236, 255, 0.45); background: rgba(34, 93, 100, 0.35); }
.toggle-input:checked::after { transform: translateX(16px); background: var(--cyan); }

.advanced-section textarea {
  min-height: 190px;
  resize: vertical;
  padding: 10px;
  color: #bcebf0;
  font: 10px/1.55 Consolas, monospace;
  tab-size: 2;
}

.metadata-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.version-section input { height: 32px; padding: 0 8px; font-size: 10px; }
.tag-field { margin-top: 9px; }

.lineage-list { margin: 14px 0 8px; }
.lineage-list div { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 8px; padding: 7px 0; border-top: 1px solid rgba(225, 242, 238, 0.07); }
.lineage-list dt { color: var(--faint); font: 8px/1.35 Consolas, monospace; text-transform: uppercase; }
.lineage-list dd { min-width: 0; margin: 0; overflow: hidden; color: var(--muted); font: 9px/1.35 Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }

.preview-workspace {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #030505;
}

.preview-meta {
  position: absolute;
  z-index: 2;
  top: 10px;
  right: 14px;
  left: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  color: rgba(230, 242, 239, 0.58);
  font: 8px/1 Consolas, monospace;
  text-transform: uppercase;
  text-shadow: 0 1px 4px #000;
}

.preview-meta span { display: flex; align-items: center; gap: 7px; }
.preview-meta i { width: 5px; height: 5px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px currentColor; }
.preview-meta i.live { background: var(--green); }

.preview-stage {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
  background: #020608;
  transition: width 220ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.preview-stage[data-viewport="tablet"] { width: min(820px, 100%); border-right: 1px solid var(--line); border-left: 1px solid var(--line); }
.preview-stage[data-viewport="mobile"] { width: min(390px, 100%); border-right: 1px solid var(--line); border-left: 1px solid var(--line); }

.preview-stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #020608;
}

.studio-status {
  height: var(--studio-footer);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  background: #090c0d;
  color: var(--faint);
  font: 8px/1 Consolas, monospace;
  text-transform: uppercase;
}

.studio-status span:first-child { margin-right: auto; }
.studio-status strong { color: var(--cyan); font-weight: 500; }

dialog {
  width: min(430px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #101415;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(5px); }
dialog form { padding: 22px; }
dialog header p { margin: 0 0 5px; color: var(--faint); font: 8px/1 Consolas, monospace; text-transform: uppercase; }
dialog h2 { margin: 0; font-size: 18px; font-weight: 560; }
dialog p { color: var(--muted); font-size: 12px; line-height: 1.55; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 22px 0 0; padding: 0; }
dialog button { height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface-raised); color: var(--muted); cursor: pointer; }
dialog button.danger { border-color: rgba(255, 118, 109, 0.4); color: var(--danger); }

.studio-toast {
  position: fixed;
  z-index: 30;
  right: 16px;
  bottom: 46px;
  width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: rgba(12, 17, 18, 0.96);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.46);
}

.studio-toast strong,
.studio-toast span { display: block; }
.studio-toast strong { color: var(--cyan); font: 8px/1 Consolas, monospace; text-transform: uppercase; }
.studio-toast span { margin-top: 6px; color: var(--muted); font-size: 11px; line-height: 1.4; }

@media (max-width: 1180px) {
  :root { --rail-width: 310px; }
  .studio-header { grid-template-columns: max-content minmax(300px, 1fr) max-content; gap: 10px; }
  .studio-actions { grid-column: 1 / -1; position: absolute; right: 12px; bottom: -44px; z-index: 4; padding: 5px; border: 1px solid var(--line); background: rgba(9, 12, 13, 0.92); }
}

@media (max-width: 760px) {
  :root { --studio-header: 108px; --rail-width: 100%; }
  .studio-header { grid-template-columns: 1fr max-content; grid-template-rows: 50px 48px; padding: 4px 10px; }
  .preset-suite { grid-column: 1; grid-row: 2; grid-template-columns: minmax(118px, 0.8fr) minmax(150px, 1.2fr); }
  .viewport-switch { grid-column: 2; grid-row: 2; }
  .studio-actions { right: 10px; bottom: auto; top: 8px; }
  .studio-actions button:not(.primary):not(.icon-action) { display: none; }
  .studio-shell { grid-template-columns: 1fr; grid-template-rows: minmax(290px, 46%) minmax(0, 1fr); }
  .token-rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-meta { top: 7px; }
  .studio-status { gap: 10px; }
  .studio-status #save-status { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
