:root {
  --bg-1: #f7f2ea;
  --bg-2: #e7dfd1;
  --ink: #1f1b16;
  --ink-soft: #514739;
  --accent: #0d7f73;
  --accent-2: #d9603b;
  --card: rgba(255, 251, 245, 0.88);
  --border: rgba(31, 27, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at 10% 10%, rgba(217, 96, 59, 0.2), transparent 38%),
    radial-gradient(circle at 90% 0%, rgba(13, 127, 115, 0.2), transparent 32%),
    linear-gradient(165deg, var(--bg-1), var(--bg-2));
}

.page {
  width: min(1120px, 92vw);
  margin: 2rem auto 3rem auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.hero {
  padding: 1.4rem 1.6rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--card);
  backdrop-filter: blur(6px);
}

.hero h1 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(1.8rem, 3vw, 2.8rem);
}

.hero p {
  margin: 0.6rem 0 0 0;
  color: var(--ink-soft);
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--card);
  padding: 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.full-width {
  margin-top: 0.9rem;
}

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

input,
select,
textarea {
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  padding: 0.55rem 0.65rem;
  background: #fff;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.actions {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

button {
  border-radius: 999px;
  padding: 0.55rem 1rem;
  border: none;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

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

.primary {
  background: var(--accent);
  color: #fff;
}

.secondary {
  background: var(--accent-2);
  color: #fff;
}

.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
}

.output-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr 1fr;
}
.output-grid article { min-width: 0; }

h2 {
  margin: 0 0 0.6rem 0;
  font-size: 1.05rem;
}

.legend {
  margin: 0 0 0.6rem 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.viz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.viz-actions {
  display: flex;
  align-items: end;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.rain-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(13, 127, 115, 0.12), rgba(255, 255, 255, 0.95) 52%),
    repeating-linear-gradient(
      90deg,
      rgba(31, 27, 22, 0.06) 0px,
      rgba(31, 27, 22, 0.06) 1px,
      transparent 1px,
      transparent 24px
    );
}

[hidden] { display: none !important; }
button:disabled { cursor: default; opacity: 0.5; transform: none; }
.export-settings { grid-template-columns: 1fr 1fr; margin-top: 1rem; }
.export-help { margin-top: 0.8rem; }
.download-link { display: inline-flex; align-items: center; border-radius: 999px; padding: 0.55rem 1rem; background: var(--accent-2); color: white; text-decoration: none; }
.exported-video { display: block; width: 100%; max-height: 70vh; border-radius: 0.75rem; background: #182e2a; }
#exportProgress { width: 100%; accent-color: var(--accent); }
#exportStatus { color: var(--ink-soft); line-height: 1.5; }
.library-row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: end; margin-top: 0.8rem; }
.library-row label { flex: 1 1 240px; }
#songSaveStatus, #songStatus { color: var(--ink-soft); line-height: 1.4; overflow-wrap: anywhere; }
.editor-navigation { margin-top: 1rem; align-items: end; margin-bottom: 0.8rem; }
.song-timeline { max-width: 100%; max-height: 430px; overflow: auto; border: 1px solid var(--border); border-radius: 0.75rem; background: white; }
.song-timeline svg { display: block; max-width: none; touch-action: manipulation; }
.song-timeline rect[data-note-id] { cursor: pointer; }
.song-timeline rect[data-note-id]:focus { outline: 3px solid var(--accent-2); }
.note-controls { margin-top: 0.8rem; }
.note-controls select, .grid input, .grid select { min-width: 0; width: 100%; }
.live-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0.8rem 0; }
.live-tines { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 0.75rem; margin: 0.8rem 0; }
.live-tines > div { min-width: 0; }
.live-row { display: flex; min-width: 0; max-width: 100%; align-items: stretch; gap: 0.4rem; overflow-x: auto; padding: 0.3rem 0.2rem 0.7rem; }
.live-tine { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 0.7rem; flex: 0 0 64px; min-height: 160px; padding: 0.7rem 0.3rem; border-radius: 0.6rem 0.6rem 1rem 1rem; border: 1px solid var(--border); background: linear-gradient(#f1e5d0, #d8c6a7); color: var(--ink); user-select: none; touch-action: pan-x; }
.live-tine:hover { transform: none; }
.live-tine strong { font-size: 1.05rem; }
.live-tine small { font-size: 0.68rem; overflow-wrap: anywhere; max-width: 58px; }
.live-tine kbd { background: white; border: 1px solid #bfb3a1; border-radius: 0.3rem; padding: 0.25rem; font-family: inherit; font-size: 0.8rem; }
.live-tine.is-playback { background: #b8e3d6; box-shadow: inset 0 -6px var(--accent); }
.live-tine.is-held { background: #fff1ba; box-shadow: inset 0 -7px var(--accent-2); transform: translateY(2px); }
.live-tine:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.live-bindings { border-top: 1px solid var(--border); padding-top: 0.8rem; }
.live-bindings summary { cursor: pointer; margin-bottom: 0.7rem; }
.live-help { margin-top: 0.8rem; }
.instrument-diagram { max-width: 100%; max-height: 460px; overflow: auto; border: 1px solid var(--border); border-radius: 0.75rem; background: #fffdf9; margin: 0.8rem 0; }
.instrument-diagram svg { display: block; width: 100%; height: auto; min-width: 620px; }
.instrument-diagram [role=button] { cursor: pointer; }
.instrument-diagram [role=button]:focus-visible rect { stroke: #d9603b; stroke-width: 4px; }
.instrument-diagram text { pointer-events: none; }
.instrument-storage { border-top: 1px solid var(--border); margin-top: 0.8rem; padding: 0.8rem 0; }
.instrument-storage summary { cursor: pointer; margin-bottom: 0.8rem; }
.instrument-impact { border-top: 1px solid var(--border); margin-top: 0.8rem; padding-top: 0.8rem; }
#instrumentStatus, #instrumentImpact, #instrumentTineInfo { overflow-wrap: anywhere; line-height: 1.5; }
#instrumentResolutions label, #instrumentResolutions select { min-width: 0; max-width: 100%; }
.song-exports { border-block:1px solid var(--border); padding:0.8rem 0; margin:0.8rem 0; }
.song-exports summary { cursor:pointer; font-weight:500; }
.song-exports .legend { margin-top:0.8rem; }
.song-exports .checkbox-row { flex:0 1 auto; }
#songExportStatus { color:var(--ink-soft); line-height:1.5; overflow-wrap:anywhere; }
.practice-transport { border:1px solid var(--border); border-radius:0.75rem; padding:0.9rem; margin:0.8rem 0; background:rgba(255,255,255,0.55); }
.practice-transport .grid { align-items:end; }
.practice-click-controls { margin-bottom:0.7rem; }
.practice-follow { display:grid; gap:0.5rem; min-width:0; }
.practice-follow button { font-size:0.85rem; }
.practice-transport input[type=range] { width:100%; padding-inline:0; accent-color:var(--accent); }
.practice-position { font-variant-numeric:tabular-nums; color:var(--ink); margin:0.35rem 0 0.8rem; }
#vizTransportStatus { line-height:1.4; color:var(--ink-soft); overflow-wrap:anywhere; }
.phrase-tools { border-top:1px solid var(--border); padding-top:0.9rem; margin-top:0.9rem; }
.phrase-tools summary { cursor:pointer; margin-bottom:0.8rem; font-weight:500; }
.phrase-tools .grid { align-items:end; }
#songMultiSelect { width:100%; min-width:0; max-width:100%; }
#songSelectionStatus { color:var(--ink-soft); line-height:1.45; }
.thumb-calibration { border-block:1px solid var(--border); padding:0.8rem 0; margin:0.8rem 0; }
.thumb-calibration summary { cursor:pointer; margin-bottom:0.7rem; }
.thumb-hands { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:0.8rem; margin:0.8rem 0; }
.thumb-hands fieldset { min-width:0; border:1px solid var(--border); border-radius:0.7rem; padding:0.8rem; }
.thumb-hands .grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
#thumbProgress { width:100%; accent-color:var(--accent); }
#thumbStatus, #thumbSummary, #thumbContext { overflow-wrap:anywhere; line-height:1.5; }
#thumbRefinement > details:last-of-type summary { cursor:pointer; margin-bottom:0.7rem; }
@media(max-width:650px) { .thumb-hands { grid-template-columns:minmax(0,1fr); } }

pre {
  margin: 0;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  padding: 0.8rem;
  background: rgba(255, 255, 255, 0.8);
  font-family: "Consolas", "Courier New", monospace;
  line-height: 1.45;
  max-height: 360px;
  overflow: auto;
  white-space: pre;
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .output-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .export-settings { grid-template-columns: 1fr; }
}
