/* Layout: 左に「選ぶ」ステップの縦列、右に組み上がる依頼文（スマホでは下に） */
:root {
  --bg: #F4F4F2;
  --surface: #FFFFFF;
  --sunken: #ECEBE8;
  --fg: #1C1A18;
  --muted: #6B6660;
  --line: #DEDBD6;
  --accent: #F26B1D;
  --accent-ink: #B9480A;
  --accent-soft: #FDE7D9;
  --on-accent: #FFFFFF;
  --ok: #2F7D4F;
  --warn: #9A6A00;
  --font-display: "Dela Gothic One", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131211; --surface: #1C1B19; --sunken: #252321; --fg: #EDEAE6; --muted: #A39D96;
    --line: #34312E; --accent: #F26B1D; --accent-ink: #FF9A5C; --accent-soft: #3A2316; --on-accent: #FFFFFF;
    --ok: #6CC495; --warn: #E0B04A; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.6;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: calc(env(safe-area-inset-top, 0px) + 28px) calc(env(safe-area-inset-bottom, 0px) + 48px);
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 1160px; margin: 0 auto; }
header.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 24px; }
.brand { margin: 0 0 4px; font-family: var(--font-mono); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }
.brand a { color: var(--accent-ink); text-decoration: none; font-weight: 500; }
.brand a:hover { text-decoration: underline; }
h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(28px, 4.4vw, 40px); line-height: 1.15; margin: 0; letter-spacing: .01em; text-wrap: balance; }
h1 .dot { color: var(--accent); }
.lede { margin: 8px 0 0; color: var(--muted); max-width: 60ch; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.steps { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.step-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.step-head h2 { font-size: 16px; font-weight: 700; margin: 0; }
.step-head .en { font-family: var(--font-mono); font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.step-head .hint { font-size: 12.5px; color: var(--muted); margin-left: auto; }
.hint.warn { color: var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 13px; font-size: 14px; line-height: 1.3; display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
.chip .x { font-size: 13px; opacity: .75; padding-left: 2px; }
.chip.custom { border-style: dashed; }
.chip.custom[aria-pressed="true"] { border-style: solid; }

.custom-row { display: flex; gap: 8px; }
.custom-row input { flex: 1; min-width: 0; }
input[type="text"], textarea {
  background: var(--sunken); border: 1px solid transparent; border-radius: 8px; padding: 8px 11px; width: 100%;
}
input[type="text"]:focus, textarea:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 14px;
  font-size: 14px; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  text-decoration: none; color: var(--fg);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.sub { border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.sub-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
#lyricsBox { display: flex; flex-direction: column; gap: 6px; }

/* Tempo */
.tempo { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px 22px; align-items: center; }
@media (max-width: 520px) { .tempo { grid-template-columns: minmax(0, 1fr); } }
.bpm-read { display: flex; flex-direction: column; align-items: flex-start; min-width: 120px; }
.bpm-num { font-family: var(--font-display); font-size: 52px; line-height: 1; font-variant-numeric: tabular-nums; }
.bpm-unit { font-family: var(--font-mono); font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.tempo-name { font-size: 13px; margin-top: 6px; }
.tempo-name i { font-family: var(--font-mono); font-style: italic; color: var(--accent-ink); margin-right: 6px; }
.beats { display: flex; gap: 6px; margin-top: 10px; }
.beats span { width: 10px; height: 10px; border-radius: 50%; background: var(--line); transition: background .06s; }
.beats span.on { background: var(--accent); }
.beats span.on.down { box-shadow: 0 0 0 3px var(--accent-soft); }
.slider-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
.scale { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -6px; }
.tempo-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.toggle-line { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.toggle-line input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

/* References */
.ref-tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.ref-tool { border: 1px dashed var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ref-tool h3 { font-size: 14px; margin: 0; }
.ref-tool p { margin: 0; font-size: 12.5px; color: var(--muted); }
.ref-tool .row { display: flex; gap: 8px; }
.ref-tool .row input { flex: 1; min-width: 0; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
p.small-note { font-size: 12px; color: var(--muted); margin: 0; }
.status { font-size: 12.5px; color: var(--muted); min-height: 1em; }
.status.err { color: var(--warn); }
.status.ok { color: var(--ok); }

/* Output */
.out { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--sunken); border-radius: 9px; padding: 3px; gap: 3px; width: 100%; }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 7px 8px; font-size: 13.5px; font-weight: 500; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
#out { font-family: var(--font-mono); font-size: 13px; line-height: 1.65; min-height: 260px; resize: vertical; }
.meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.out-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn.lg { padding: 10px 14px; font-size: 15px; }
.howto { margin: 0; padding-left: 20px; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.share { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.share-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.note { font-size: 12px; color: var(--muted); margin: 0; }
details.hist { border-top: 1px solid var(--line); padding-top: 10px; }
details.hist summary { cursor: pointer; font-size: 13.5px; font-weight: 500; }
.hist-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; max-height: 320px; overflow: auto; }
.hist-item { background: var(--sunken); border-radius: 8px; padding: 8px 10px; font-family: var(--font-mono); font-size: 12px; display: flex; flex-direction: column; gap: 6px; white-space: pre-wrap; word-break: break-word; }
.hist-item .ops { display: flex; gap: 6px; justify-content: flex-end; font-family: var(--font-body); white-space: normal; }
.hist-item .ops .btn { padding: 3px 10px; font-size: 12.5px; }
.hist-item time { color: var(--muted); font-family: var(--font-body); margin-right: auto; }

.foot { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px 32px; font-size: 13px; }
@media (max-width: 700px) { .foot { grid-template-columns: minmax(0, 1fr); } }
.foot p { margin: 0 0 6px; }
.foot-title { font-weight: 700; }
.foot-notes { color: var(--muted); font-size: 12.5px; }
.foot-notes .foot-title { color: var(--fg); }
.foot-notes ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }

.mbar { display: none; }
@media (max-width: 900px) {
  .mbar {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 10px) max(16px, env(safe-area-inset-left, 0px));
  }
  .mbar .btn { padding: 10px; font-size: 15px; }
  body { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 96px); }
  .toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 76px) !important; }
  .out { position: static; scroll-margin-top: 16px; }
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  background: var(--fg); color: var(--bg); border-radius: 10px; padding: 10px 14px; font-size: 14px;
  display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); z-index: 10;
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
