:root {
  --bg: #050506;
  --panel: #0d0d0f;
  --panel-2: #151518;
  --sunken: #0a0a0c;
  --ink: #f2ecec;
  --ink-dim: #85878d;
  --line: #ffffff17;
  --line-strong: #ffffff2b;
  --ui-accent: #ff6674;
  --ui-accent-2: #ff8a94;
  --ui-accent-ink: #2a0c10;
  --ui-accent-soft: #33171b;
  --ok: #7de4b8;
  --warn: #e0b85a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  overflow-x: hidden;
  background:
    radial-gradient(720px 440px at 48% -16%, #2d151833 0%, transparent 62%),
    var(--bg);
  color: var(--ink);
  font: 14px/1.55 "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button, input, select { font: inherit; }

.bar {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border: 1px solid #ffffff0e;
  border-radius: 12px;
  margin: 14px 14px 0;
  background:
    linear-gradient(90deg, #0b090b 0%, #070708 48%, #0b090b 100%),
    var(--bg);
  box-shadow: inset 0 -1px 0 #ffffff0a, 0 12px 36px #00000026;
}

.bar h1 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  margin: 0;
  color: #ffd7a6;
  font-size: 0;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}

.bar h1::before {
  content: "夜兔譜";
  font-size: 22px;
  background: linear-gradient(92deg, #ffe0ad 0%, #ff8a94 48%, #f5ecff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 18px #ff667455, 0 0 34px #ffd08a22;
}

.bar h1::after {
  content: "簡易模式";
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  color: var(--ui-accent-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  border: 1px solid #ff667455;
  border-radius: 6px;
  background: var(--ui-accent-soft);
  -webkit-text-fill-color: initial;
  text-shadow: none;
}

.bar .hint {
  min-width: 0;
  margin: 0;
  color: var(--ink-dim);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-link {
  order: 3;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid #ff66743a;
  border-radius: 8px;
  background: linear-gradient(135deg, #2b1519 0%, #151518 58%, #0d0d0f 100%);
  box-shadow: inset 0 1px 0 #ffffff12, 0 8px 22px #00000026;
}

.mode-link:hover,
.mode-link:focus-visible {
  color: #ffd5d9;
  border-color: var(--ui-accent);
  outline: none;
  box-shadow: inset 0 1px 0 #ffffff18, 0 0 0 3px #ff66741f, 0 8px 24px #00000030;
}

main {
  min-height: 0;
  height: calc(100vh - 86px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 340px);
  gap: 12px;
  padding: 12px 14px 14px;
  align-items: start;
}

.stage-wrap {
  position: relative;
  min-width: 0;
  width: min(100%, calc((100vh - 200px) * 16 / 9));
  max-height: 100%;
  justify-self: center;
}

.stage-action-row {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.template-picker,
.template-options {
  display: flex;
  align-items: center;
}

.template-picker { gap: 9px; }

.template-picker-label {
  color: var(--ink-dim);
  font-size: 12px;
  white-space: nowrap;
}

.template-options {
  gap: 3px;
  padding: 3px;
  border: 1px solid #ffffff17;
  border-radius: 9px;
  background: #0a0a0ccc;
  box-shadow: inset 0 1px 0 #ffffff08;
}

button.template-option {
  min-width: 38px;
  min-height: 30px;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-dim);
  font-weight: 700;
}

button.template-option:hover,
button.template-option:focus-visible {
  color: var(--ink);
  background: #ffffff0c;
}

button.template-option[aria-pressed="true"] {
  color: var(--ui-accent-ink);
  border-color: transparent;
  background: var(--ui-accent-2);
  box-shadow: 0 4px 14px #ff66742e, inset 0 1px 0 #ffffff42;
}

.action-group-export {
  display: flex;
  align-items: center;
  gap: 8px;
}

#stage {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
  border: 1px solid #ffffff12;
  border-radius: 12px;
  max-height: calc(100vh - 200px);
  object-fit: contain;
  background: var(--sunken);
  box-shadow: 0 20px 60px #00000066, inset 0 0 0 1px #0005;
}

.stage-empty {
  position: absolute;
  inset: 46px 0 44px;
  display: grid;
  place-items: center;
  color: var(--ink-dim);
  pointer-events: none;
  font-size: 15px;
}

.stage-empty[hidden] { display: none; }

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}

.transport span {
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

#play {
  min-width: 112px;
  min-height: 38px;
  color: var(--ink);
  border-color: #ff667455;
  background: linear-gradient(180deg, #25181b 0%, var(--ui-accent-soft) 100%);
  box-shadow: inset 0 1px 0 #ffffff12;
  font-weight: 650;
}

#play:hover:not(:disabled),
#play:focus-visible {
  color: #fff;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px #ff66741f, inset 0 1px 0 #ffffff18;
}

.panel {
  min-width: 0;
  display: grid;
  gap: 0;
  padding: 2px 12px 12px;
  background: var(--panel);
  border: 1px solid #ffffff12;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px #0005;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb {
  background: #ffffff1f;
  border-radius: 99px;
}
.panel::-webkit-scrollbar-thumb:hover { background: #ffffff36; }

.group {
  display: grid;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid #ffffff12;
}

.group:last-child { border-bottom: 0; }

.group h2 {
  margin: 0;
  color: var(--ui-accent-2);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .08em;
}

.pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  cursor: pointer;
  border: 1px dashed #ffffff22;
  border-radius: 7px;
  background: var(--sunken);
}

.pick:hover,
.pick.is-over {
  border-color: var(--ui-accent);
  background: var(--ui-accent-soft);
}

.pick input[type="file"] { display: none; }
.pick-title { display: grid; min-width: 0; }
.pick-title small { color: var(--ink-dim); font-size: 11px; font-weight: 400; }
.pick-state {
  max-width: 130px;
  color: var(--ink-dim);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pick.is-loaded .pick-state { color: var(--ok); }

.field { display: grid; gap: 5px; }
.field[hidden], .pick[hidden] { display: none; }
.field.inline { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.field span { color: var(--ink-dim); font-size: 12px; }
.field b { color: var(--ui-accent-2); font-weight: 600; font-variant-numeric: tabular-nums; }

input[type="text"], select {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid #ffffff1f;
  border-radius: 7px;
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px #ff66741f;
}

input[type="color"] {
  width: 46px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  border: 1px solid #ffffff1f;
  border-radius: 7px;
  background: var(--panel-2);
}

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

input[type="range"] {
  width: 100%;
  accent-color: var(--ui-accent-2);
  cursor: pointer;
}

button {
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid #ffffff1f;
  border-radius: 7px;
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: var(--ui-accent);
  outline: none;
}

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

button.primary {
  color: var(--ui-accent-ink);
  background: var(--ui-accent);
  border-color: transparent;
  font-weight: 650;
}

button.primary:hover:not(:disabled),
button.primary:focus-visible { background: var(--ui-accent-2); }

#export-fast {
  color: var(--ui-accent);
  border-color: var(--ui-accent);
  background: transparent;
  font-weight: 600;
}

#export-fast:hover:not(:disabled),
#export-fast:focus-visible { background: var(--ui-accent-soft); }

button.danger {
  color: #e58c93;
  border-color: #d35f5f66;
}

button.ghost {
  min-height: 30px;
  padding: 0 10px;
  color: var(--ink-dim);
  font-size: 12px;
  background: transparent;
}

.progress {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: #ffffff1a;
}

.progress i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--ui-accent), var(--ui-accent-2));
}

.note { margin: 0; color: var(--ink-dim); font-size: 12px; }

@media (max-width: 1000px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  main {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
  }
  .stage-wrap {
    width: 100%;
    max-height: none;
    justify-self: stretch;
  }
  #stage { max-height: none; }
  .panel {
    max-height: none;
    margin-top: 2px;
    overflow: visible;
  }
}

@media (max-width: 600px) {
  .bar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 12px;
  }

  .bar h1 { order: 1; }
  .bar .hint { order: 3; flex: 1 0 100%; }
  .mode-link { order: 0; margin-left: 0; }
  main { padding: 10px 12px 12px; }
  .stage-action-row { align-items: flex-end; }
  .template-picker { align-items: flex-start; flex-direction: column; gap: 3px; }
  .template-picker-label { font-size: 11px; }
}
