:root {
  color-scheme: light;
  --ink: #26231f;
  --muted: #756f67;
  --paper: #f7f3ec;
  --surface: rgba(255, 255, 255, 0.86);
  --line: #ded6ca;
  --orange: #e96f32;
  --orange-dark: #c9501d;
  --orange-pale: #fff0e4;
  --indigo: #5652a4;
  --shadow: 0 12px 35px rgba(76, 54, 34, 0.09);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Hiragino Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 0%, rgba(255, 196, 120, 0.24), transparent 30rem),
    linear-gradient(155deg, #fbf8f3, var(--paper));
  padding-bottom: calc(94px + var(--safe-bottom));
}

button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(86, 82, 164, 0.35);
  outline-offset: 2px;
}

.skip-link { position: fixed; left: 1rem; top: -4rem; z-index: 100; }
.skip-link:focus { top: 1rem; background: white; padding: .7rem 1rem; border-radius: .5rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

.topbar {
  height: 62px;
  padding: 0 max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(120, 100, 80, 0.12);
  background: rgba(250, 247, 242, 0.76);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: .55rem; font-weight: 850; letter-spacing: .04em; }
.brand-mark { display: grid; place-items: center; width: 31px; height: 31px; color: white; background: var(--orange); border-radius: 9px; }
.web-badge { font-size: .62rem; color: var(--orange-dark); background: var(--orange-pale); padding: .22rem .4rem; border-radius: 999px; }
.save-state { color: var(--muted); font-size: .77rem; }

.app-shell { width: min(1080px, 100%); margin: 0 auto; padding: 24px 20px 50px; }
.song-heading, .card-title-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.song-heading { margin-bottom: 16px; }
.song-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.85rem, 5vw, 2.7rem); }
h2 { margin-bottom: 0; font-size: 1.25rem; }
.eyebrow { margin: 0 0 .18rem; color: var(--orange-dark); font-size: .65rem; font-weight: 850; letter-spacing: .14em; }

.project-name-field { display: block; margin-bottom: 18px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.project-name-field input {
  display: block; width: 100%; margin-top: .35rem; border: 0; border-bottom: 2px solid var(--line);
  border-radius: 0; padding: .35rem 0 .55rem; color: var(--ink); background: transparent;
  font-size: clamp(1.35rem, 4vw, 1.9rem); font-weight: 750;
}
.project-name-field input:focus { border-color: var(--orange); outline: none; }

.workspace-grid { display: grid; grid-template-columns: 1.45fr .85fr; gap: 16px; margin-bottom: 16px; }
.card { border: 1px solid rgba(126, 103, 78, 0.15); border-radius: 20px; padding: 20px; background: var(--surface); box-shadow: var(--shadow); }
.tempo-card { background: linear-gradient(150deg, rgba(255,255,255,.94), rgba(255,243,228,.88)); }
.bpm-number input { width: 4.2ch; border: 0; color: var(--ink); background: transparent; text-align: right; font-size: 2.3rem; font-weight: 850; font-variant-numeric: tabular-nums; }
.tempo-controls { display: grid; grid-template-columns: 46px 1fr 46px; align-items: center; gap: 12px; margin-top: 16px; }
.bpm-range, .volume-control input { width: 100%; accent-color: var(--orange); }
.icon-button { display: grid; place-items: center; min-width: 44px; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: rgba(255,255,255,.82); font-size: 1.35rem; }
.icon-button.small { min-width: 38px; min-height: 38px; font-size: 1rem; }
.icon-button[aria-pressed="true"] { color: white; border-color: var(--orange); background: var(--orange); }
.tempo-actions { display: grid; grid-template-columns: .65fr 1.35fr; gap: 10px; margin-top: 14px; }

.button { min-height: 44px; border: 1px solid transparent; border-radius: 12px; padding: .62rem 1rem; font-weight: 750; }
.button-primary { color: white; background: var(--orange); box-shadow: 0 6px 18px rgba(233,111,50,.24); }
.button-primary:hover { background: var(--orange-dark); }
.button-secondary { color: var(--ink); border-color: var(--line); background: white; }
.button-subtle { min-height: 38px; color: var(--orange-dark); background: var(--orange-pale); }
.button-indigo { color: white; background: var(--indigo); }
.button-dashed { width: 100%; margin-top: 16px; color: var(--orange-dark); border: 1.5px dashed rgba(201,80,29,.45); background: var(--orange-pale); }
.full-width { width: 100%; margin-top: 10px; }

.volume-control { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 22px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.volume-control input { grid-column: 1 / -1; }
.part-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.part-toggle { min-height: 36px; border: 1px solid var(--line); border-radius: 999px; padding: .35rem .75rem; color: var(--muted); background: white; font-size: .75rem; font-weight: 800; }
.part-toggle[aria-pressed="true"] { color: white; border-color: var(--indigo); background: var(--indigo); }
.helper { margin: 18px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.55; }
.audio-diagnostics { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.audio-diagnostics > summary { color: var(--muted); cursor: pointer; font-size: .72rem; font-weight: 750; }
.audio-diagnostic-note { margin: 8px 0 0; color: var(--muted); font-size: .68rem; line-height: 1.45; }
.audio-diagnostic-summary {
  margin-top: 8px; padding: 9px; border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink); background: rgba(255,255,255,.72); font-size: .68rem;
}
.audio-diagnostic-summary strong { display: block; color: var(--orange-dark); line-height: 1.45; }
.audio-diagnostic-summary dl { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; margin: 7px 0 0; }
.audio-diagnostic-summary dt { color: var(--muted); }
.audio-diagnostic-summary dd { margin: 0; font-weight: 750; text-align: right; }
.audio-diagnostic-tests { display: grid; gap: 5px; margin-top: 8px; }
.audio-diagnostics .button { width: 100%; margin-top: 3px; }
.audio-diagnostic-tests output {
  display: block; padding: 0 3px 3px; color: var(--muted);
  font-size: .65rem; font-weight: 750;
}
.audio-diagnostic-tests output[data-result="OK"] { color: #2f765d; }
.audio-diagnostic-tests output[data-result="NG"] { color: #a83628; }
.audio-diagnostics pre {
  max-height: 210px; margin: 9px 0 0; padding: 9px; overflow: auto;
  border-radius: 9px; color: #dcebd7; background: #242722;
  font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; user-select: text; -webkit-user-select: text;
}
.field-message { min-height: 1.1rem; margin: .45rem 0 0; color: var(--muted); font-size: .78rem; }
.field-message.error { color: #a83628; }

.mixer-card { margin-bottom: 16px; padding: 0; overflow: clip; }
.mixer-card > summary {
  min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px; cursor: pointer; list-style: none; touch-action: manipulation;
}
.mixer-card > summary::-webkit-details-marker { display: none; }
.mixer-card > summary::after { content: "＋"; color: var(--orange-dark); font-size: 1.1rem; font-weight: 850; }
.mixer-card[open] > summary::after { content: "−"; }
.mixer-card > summary > :first-child { display: flex; flex-direction: column; min-width: 0; }
.mixer-summary-value { margin-left: auto; color: var(--muted); font-size: .76rem; white-space: nowrap; }
.mixer-body { padding: 0 20px 20px; border-top: 1px solid var(--line); }
.mixer-body > .helper { margin: 12px 0; }
.mixer-parts { display: grid; gap: 8px; }
.mixer-channel { padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.72); }
.mixer-channel.part-disabled { background: rgba(239,236,231,.58); }
.mixer-channel.part-disabled .mixer-channel-heading strong::after { content: " · Part OFF"; color: var(--muted); font-size: .65rem; font-weight: 650; }
.mixer-channel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mixer-channel-heading strong { font-size: .88rem; }
.mixer-channel-actions { display: flex; gap: 6px; }
.mixer-channel-actions button {
  min-width: 44px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px;
  color: var(--muted); background: white; font-size: .74rem; font-weight: 850;
}
.mixer-channel-actions button.active[data-mixer-button="mute"] { color: white; border-color: #b43b2e; background: #b43b2e; }
.mixer-channel-actions button.active[data-mixer-button="solo"] { color: white; border-color: var(--indigo); background: var(--indigo); }
.mixer-sliders { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 7px; }
.mixer-slider { display: grid; grid-template-columns: 1fr auto; gap: 3px 6px; color: var(--muted); font-size: .68rem; font-weight: 750; }
.mixer-slider output { font-variant-numeric: tabular-nums; }
.mixer-slider input { grid-column: 1 / -1; width: 100%; min-height: 32px; margin: 0; accent-color: var(--orange); }

.export-card, .project-file-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 16px;
  background: linear-gradient(145deg, rgba(244,243,255,.96), rgba(255,255,255,.91));
}
.export-card .helper, .project-file-card .helper { margin-top: 8px; }
.export-status, .project-file-status { grid-column: 1 / -1; margin: 0; }
.project-file-card { background: linear-gradient(145deg, rgba(238,248,245,.96), rgba(255,255,255,.91)); }
.project-file-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.export-actions { display: grid; gap: 8px; min-width: min(100%, 250px); }

.progression-card { background: linear-gradient(145deg, rgba(255,248,240,.96), rgba(255,255,255,.91)); }
.progression-heading { margin-bottom: 14px; }
.count-badge { color: var(--muted); background: rgba(90,70,50,.07); border-radius: 999px; padding: .3rem .65rem; font-size: .76rem; }
.empty-state { min-height: 150px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: .35rem; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); }
.empty-icon { font-size: 2rem; color: var(--orange); }
.progression-list { display: flex; align-items: stretch; gap: 10px; margin: 0; padding: 4px 2px 10px; list-style: none; overflow-x: auto; scroll-snap-type: x proximity; }
.chord-item { flex: 0 0 auto; min-width: 130px; scroll-snap-align: start; border: 2px solid transparent; border-radius: 14px; background: white; box-shadow: 0 5px 16px rgba(71,53,35,.08); overflow: hidden; }
.chord-item.playing { color: white; background: var(--orange); border-color: var(--orange-dark); }
.chord-main { width: 100%; min-height: 76px; padding: 10px; border: 0; color: inherit; background: transparent; text-align: left; }
.chord-symbol { display: block; font-size: 1.28rem; font-weight: 850; }
.chord-duration { display: block; margin-top: .18rem; opacity: .7; font-size: .72rem; }
.chord-actions { display: flex; border-top: 1px solid rgba(120,100,80,.12); }
.chord-actions button { flex: 1; min-height: 34px; border: 0; border-right: 1px solid rgba(120,100,80,.12); color: inherit; background: transparent; }
.chord-actions button:last-child { border-right: 0; }
.chord-actions button:hover { background: rgba(120,100,80,.08); }
.quick-entry { margin-top: 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.quick-entry > label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.quick-entry-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 6px; }
.quick-entry input, .form-grid select { min-height: 44px; width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: .6rem .72rem; color: var(--ink); background: white; }

.transport { position: fixed; z-index: 30; left: 50%; bottom: max(12px, var(--safe-bottom)); transform: translateX(-50%); width: min(720px, calc(100% - 24px)); display: flex; align-items: center; gap: 15px; padding: 10px 10px 10px 16px; border: 1px solid rgba(120,90,60,.18); border-radius: 18px; color: white; background: rgba(37,33,29,.94); box-shadow: 0 16px 45px rgba(24,20,16,.28); backdrop-filter: blur(18px); }
.transport-copy { min-width: 82px; flex: 1; overflow: hidden; }
.transport-copy span, .transport-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transport-copy span { color: rgba(255,255,255,.65); font-size: .69rem; }
.transport-button { min-width: 210px; }

.chord-dialog { width: min(560px, calc(100% - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 0; border-radius: 22px; color: var(--ink); background: #fffdf9; box-shadow: 0 24px 80px rgba(30,22,15,.3); }
.chord-dialog::backdrop { background: rgba(36,30,25,.5); backdrop-filter: blur(5px); }
.chord-dialog form { padding: 22px; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.form-grid select { display: block; margin-top: .35rem; color: var(--ink); font-size: 1rem; }
.chord-preview { display: flex; flex-direction: column; align-items: center; margin: 20px 0 12px; padding: 16px; border-radius: 14px; background: var(--orange-pale); }
.chord-preview span { color: var(--muted); font-size: .75rem; }
.chord-preview strong { font-size: 2.5rem; }

body.keyboard-open { overflow: hidden; padding-bottom: 0; overscroll-behavior: none; }
.keyboard-mode {
  position: fixed; z-index: 100; inset: 0; display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  color: #f8f6f1; background: linear-gradient(155deg, #24211e, #121110);
  touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
.keyboard-mode-header {
  min-height: 66px; display: grid; grid-template-columns: 1fr minmax(150px, 1.3fr) 48px;
  align-items: center; gap: 12px; padding-bottom: 9px;
}
.keyboard-mode-brand h2 { font-size: clamp(1rem, 4vh, 1.35rem); }
.keyboard-detection { min-width: 0; text-align: center; }
.keyboard-detection strong { display: block; color: #ff9b61; font-size: clamp(1.75rem, 9vh, 3.4rem); line-height: 1; }
.keyboard-detection span { display: block; margin-top: 3px; color: rgba(255,255,255,.56); font-size: .72rem; }
.keyboard-close { justify-self: end; color: white; border-color: rgba(255,255,255,.25); background: rgba(255,255,255,.09); }
.keyboard-keys {
  --white-key-count: 14; position: relative; display: flex; min-height: 160px; width: 100%;
  border-radius: 12px; overflow: hidden; background: #151413; touch-action: none;
  box-shadow: 0 16px 44px rgba(0,0,0,.38);
}
.keyboard-key { margin: 0; padding: 0; border-radius: 0; touch-action: none; -webkit-tap-highlight-color: transparent; }
.white-key {
  position: relative; z-index: 1; flex: 1 1 calc(100% / var(--white-key-count));
  height: 100%; border: 0; border-right: 1px solid #bcb7af;
  background: linear-gradient(#fff, #ece8e1 78%, #d4cec4);
}
.white-key span { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); color: #8c857b; font-size: .62rem; font-weight: 750; }
.black-key {
  position: absolute; z-index: 3; top: 0;
  height: 62%;
  border: 0; border-radius: 0 0 7px 7px;
  background: linear-gradient(90deg, #090909, #2f2d2a 58%, #080808);
  box-shadow: 0 5px 7px rgba(0,0,0,.5);
}
.keyboard-key.is-active.white-key { background: linear-gradient(#ffd9bb, #ee8d50); }
.keyboard-key.is-active.black-key { background: linear-gradient(90deg, #733014, #e96f32 58%, #6a270e); }
.keyboard-message { min-height: 1rem; margin: 5px 0 0; color: #ffb28b; text-align: center; font-size: .72rem; }

@media (max-width: 700px) {
  .topbar { height: 56px; }
  .save-state { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-shell { padding: 18px 14px 36px; }
  .workspace-grid { grid-template-columns: 1fr; }
  .sound-card { display: grid; grid-template-columns: 1fr; }
  .export-card, .project-file-card { grid-template-columns: 1fr; }
  .export-status, .project-file-status { grid-column: 1; }
  .project-file-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .export-actions { width: 100%; }
  .card { padding: 17px; border-radius: 17px; }
  .mixer-card { padding: 0; }
  .mixer-card > summary { padding: 14px 17px; }
  .mixer-body { padding: 0 10px 12px; }
  .transport { bottom: max(8px, var(--safe-bottom)); }
  .transport-button { min-width: 0; }
}

@media (max-width: 470px) {
  .brand { font-size: .88rem; }
  .web-badge { display: none; }
  .tempo-actions, .quick-entry-row { grid-template-columns: 1fr; }
  .project-file-actions { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .transport-copy { display: none; }
  .transport-button { width: 100%; }
  .mixer-sliders { gap: 7px; }
  .mixer-channel { padding: 9px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  body { padding-bottom: 72px; }
  .topbar { position: static; }
  .app-shell { padding-top: 12px; }
  .workspace-grid { grid-template-columns: 1fr 1fr; }
  .transport { bottom: 6px; }
  .chord-dialog { max-height: calc(100vh - 12px); overflow-y: auto; }
  .keyboard-mode { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .keyboard-mode-header { min-height: 52px; padding-bottom: 5px; }
  .keyboard-mode-brand .eyebrow { display: none; }
  .keyboard-detection strong { font-size: clamp(1.5rem, 10vh, 2.8rem); }
  .keyboard-message { margin-top: 2px; }
}

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