:root {
  color-scheme: dark;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --bg: #11141b;
  --surface: #1a1e27;
  --raised: #242a35;
  --line: #343c49;
  --text: #f5f7ef;
  --muted: #aeb6c3;
  --lime: #b7f34a;
  --lime-soft: #30401f;
  --cyan: #61d9e6;
  --danger: #ff8d8d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; min-height: 100dvh; overscroll-behavior: none; }
button, input, select { font: inherit; }
button, .file-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raised);
  color: var(--text);
  padding: .65rem .9rem;
  cursor: pointer;
}
button.primary, .file-button.primary { background: var(--lime); border-color: var(--lime); color: #11180a; font-weight: 750; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
button[disabled] { opacity: .45; cursor: wait; }
h1, h2, h3, p { margin-top: 0; }
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 14px) calc(var(--safe-bottom) + 14px) calc(var(--safe-left) + 14px);
}
.topbar { display: flex; align-items: center; gap: .75rem; margin-bottom: .8rem; }
.topbar h1 { font-size: 1.05rem; margin: 0; flex: 1; }
.version { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.home { min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 28px); display: grid; place-items: center; }
.hero { width: min(620px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: clamp(1.2rem, 5vw, 2.5rem); }
.hero h1 { font-size: clamp(1.8rem, 7vw, 3rem); line-height: 1.02; }
.hero p { color: var(--muted); line-height: 1.65; }
.actions { display: flex; gap: .65rem; flex-wrap: wrap; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.status { color: var(--muted); min-height: 1.5rem; margin-top: .8rem; }
.error { color: var(--danger); }
.privacy-note { margin-top: 1.3rem; font-size: .82rem; color: var(--muted); }
.workspace { display: grid; grid-template-rows: auto minmax(220px, 1fr) auto; gap: .7rem; min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 28px); }
.summary { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.summary .chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .4rem .7rem; font-size: .8rem; }
.main-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(245px, 320px); gap: .7rem; min-height: 0; }
.timeline-card, .editor, .controlbar { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.timeline-card { overflow: hidden; display: grid; grid-template-rows: auto minmax(150px, 1fr); min-height: 0; }
.timeline-heading { padding: .65rem .8rem; display: flex; justify-content: space-between; color: var(--muted); font-size: .82rem; }
.timeline-scroll { overflow: auto; min-height: 150px; -webkit-overflow-scrolling: touch; }
#timeline-content { position: relative; min-height: 100%; display: grid; grid-template-rows: minmax(140px, 1fr) 56px; }
#melody-canvas { display: block; height: 100%; min-height: 150px; }
.chord-lane { position: relative; height: 56px; min-width: 100%; border-top: 1px solid var(--line); background: #151922; overflow: hidden; }
.chord-cell { position: absolute; top: 5px; bottom: 5px; min-width: 42px; padding: 4px 7px; min-height: 44px; border-radius: 8px; border-color: #4c5869; background: #242b36; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chord-cell.selected { border-color: var(--lime); background: var(--lime-soft); color: var(--lime); }
.editor { padding: .85rem; overflow: auto; -webkit-overflow-scrolling: touch; }
.editor h2 { font-size: 1rem; }
.candidate-list { display: grid; gap: .5rem; }
.candidate { width: 100%; display: flex; justify-content: space-between; text-align: left; }
.candidate.current { border-color: var(--lime); color: var(--lime); }
.score { color: var(--muted); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.controlbar { padding: .65rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; overflow-x: auto; }
.control-group { display: flex; gap: .4rem; align-items: center; white-space: nowrap; }
.control-label { color: var(--muted); font-size: .75rem; }
select { min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--raised); color: var(--text); padding: .4rem .6rem; }
.update-banner { position: fixed; z-index: 20; left: calc(var(--safe-left) + 12px); right: calc(var(--safe-right) + 12px); bottom: calc(var(--safe-bottom) + 12px); display: flex; align-items: center; gap: .7rem; padding: .7rem; border: 1px solid var(--lime); border-radius: 14px; background: #202719; box-shadow: 0 8px 30px #000a; }
.update-banner span { flex: 1; }
.track-list { display: grid; gap: .6rem; }

@media (max-width: 720px) {
  .main-grid { grid-template-columns: 1fr; grid-template-rows: minmax(280px, 54vh) auto; }
  .editor { max-height: 34vh; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app-shell { padding-top: calc(var(--safe-top) + 6px); padding-bottom: calc(var(--safe-bottom) + 6px); }
  .workspace { grid-template-rows: auto minmax(180px, 1fr) auto; gap: .4rem; }
  .topbar { margin-bottom: .35rem; }
  .main-grid { grid-template-columns: minmax(0, 1fr) minmax(220px, 28vw); grid-template-rows: minmax(180px, 1fr); gap: .4rem; }
  .timeline-card { min-height: 180px; }
  #melody-canvas { min-height: 112px; }
  .editor { max-height: none; padding: .6rem; }
  .summary .secondary { display: none; }
  .controlbar { flex-wrap: nowrap; padding: .4rem; }
  .controlbar button, .controlbar select { min-height: 38px; padding-top: .4rem; padding-bottom: .4rem; }
}
