:root {
  --canvas: #F8F7F3;
  --paper: #FFFFFF;
  --ink: #142D36;
  --ink-2: #52616B;
  --teal: #0D4854;
  --teal-hover: #0A3942;
  --sage: #E9EFE2;
  --sage-ink: #2F4A2A;
  --border: #D9DED8;
  --chord: #174EA6;
  --alt: #0D4854;
  --warn-ink: #69430B;
  --warn-bg: #FFF4DF;
  --error: #9B1C1C;
  --focus: #174EA6;
  --radius: 10px;
  --chat-width: 34%;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.error { color: var(--error); min-height: 1.5em; margin: 8px 0; }

/* Header */
.app-header {
  height: 64px; display: flex; align-items: center; gap: 16px;
  padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--canvas);
}
.brand { font: 24px var(--serif); color: var(--ink); text-decoration: none; }
.header-set { flex: 1; text-align: center; font-size: 17px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.save-state { color: var(--ink-2); font-size: 14px; }

/* Buttons */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; background: none; text-decoration: none; font-size: 16px;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-hover); }
.btn-outline { border-color: var(--teal); color: var(--teal); background: var(--paper); }
.btn-quiet { color: var(--teal); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: 1px solid var(--border); background: var(--paper);
  border-radius: 8px; cursor: pointer; font-size: 18px;
}

/* Screens */
.screen.narrow { max-width: 760px; margin: 0 auto; padding: 48px 24px; }
.eyebrow { letter-spacing: .18em; text-transform: uppercase; color: var(--ink-2); font-size: 13px; text-align: center; margin: 0 0 8px; }
.display { font: 44px/1.15 var(--serif); text-align: center; margin: 0 0 8px; }
.lede { font: 20px var(--serif); color: var(--ink-2); text-align: center; margin: 0 0 32px; }
.card { background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.form { display: grid; gap: 8px; max-width: 420px; margin: 24px auto; }
.form input { min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; }
.dropzone {
  background: var(--paper); border: 1.5px dashed #9EB29A; border-radius: 12px; padding: 40px 24px;
  text-align: center; display: grid; justify-items: center; gap: 8px;
}
.dropzone.over { background: var(--sage); }
.dropzone h2 { font: 28px var(--serif); margin: 0; }
.dropzone p { margin: 0; color: var(--ink-2); }
.page-icon { width: 48px; height: 48px; color: #7C9277; }
.divider { display: flex; align-items: center; gap: 16px; margin: 40px 0 16px; font: 20px var(--serif); }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.set-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.set-list a {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 20px;
  background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); color: var(--ink); text-decoration: none;
}
.set-list .name { font: 20px var(--serif); }

/* Workspace */
.workspace { display: flex; height: calc(100vh - 64px); height: calc(100dvh - 64px); }
.panel-chat { width: var(--chat-width); min-width: 300px; max-width: 50%; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.splitter { width: 8px; cursor: col-resize; background: transparent; margin-left: -4px; margin-right: -4px; z-index: 1; }
.splitter:hover, .splitter:focus-visible { background: var(--border); }
.panel-music { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tabs-narrow { display: none; }

.chat-head { padding: 24px 24px 8px; }
.panel-title { font: 26px var(--serif); margin: 0; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 8px 24px 24px; display: flex; flex-direction: column; gap: 16px; }
.messages { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.msg { padding: 12px 16px; border-radius: var(--radius); max-width: 92%; }
.msg.user { background: #ECEDEA; justify-self: end; }
.msg.assistant { background: var(--paper); border: 1px solid var(--border); }
.msg .meta { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.notice { padding: 12px 16px; border-radius: var(--radius); background: var(--paper); border: 1px solid var(--border); }
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: #F0D9A8; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }

.qcard { background: var(--sage); border-radius: 12px; padding: 20px; display: grid; gap: 12px; }
.qcard h2 { font-size: 17px; margin: 0; }
.qcard p { margin: 0; }
.qcard .options { display: flex; flex-wrap: wrap; gap: 8px; }
.qcard input[type=text], .qcard select { min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; flex: 1; min-width: 120px; }
.qcard .count { font-size: 13px; color: var(--sage-ink); }
.qcard .crop { max-width: 100%; max-height: 140px; justify-self: start; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.hand-note { display: flex; align-items: center; gap: 4px; margin: 6px 0 10px; }
.hand-note img { max-height: 72px; max-width: 70%; }
.hand-note .bracket { font-size: 48px; line-height: 1; color: #8A9399; }

.approve-card, .download-card { background: var(--sage); border-radius: 12px; padding: 20px; display: grid; gap: 12px; }
.approve-card h2, .download-card h2 { font: 22px var(--serif); margin: 0; }
.approve-card ul { margin: 0; padding-left: 20px; }
.format-choice { display: flex; flex-wrap: wrap; gap: 16px; }
.format-choice label { display: inline-flex; gap: 8px; align-items: center; min-height: 44px; }
.format-choice input { width: 20px; height: 20px; }
.download-card .btn { width: 100%; }
.download-card .older { font-size: 14px; color: var(--ink-2); }
.appearance { display: grid; gap: 8px; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--paper); }
.appearance-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.appearance-size { min-width: 7.5em; font-weight: 600; }
.appearance select { min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--paper); }

.chat-dock { border-top: 1px solid var(--border); padding: 16px 24px 20px; display: grid; gap: 12px; }
.live { display: flex; gap: 12px; align-items: center; }
.live-label { font-weight: 600; }
.orb {
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #fff 0, #CFE3E0 25%, #5E9A98 60%, #0D4854 100%);
  box-shadow: inset 0 0 0 1px rgba(13,72,84,.2);
}
.orb[disabled] { cursor: not-allowed; filter: grayscale(.6); opacity: .7; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-height: 52px; max-height: 160px; resize: none; padding: 13px 14px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--paper);
}
.dictate svg, .send svg { width: 20px; height: 20px; }
.send { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--teal); color: #fff; cursor: pointer; display: grid; place-items: center; }

/* Music panel */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 16px 24px 8px; }
.toolbar select { min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--paper); }
#song-select { min-width: 220px; max-width: 100%; }
.tool-group { display: flex; align-items: center; gap: 8px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--paper); }
.segmented button { min-height: 44px; padding: 0 16px; border: 0; background: none; cursor: pointer; }
.segmented button[aria-selected="true"] { background: var(--sage); font-weight: 600; }
.status-bar { margin: 0 24px 8px; padding: 10px 16px; border-radius: 8px; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.status-bar.draft { background: var(--warn-bg); color: var(--warn-ink); }
.status-bar.ready { background: var(--sage); color: var(--sage-ink); }
.status-bar.info { background: #EEF1F3; color: var(--ink-2); }
.status-bar:empty { display: none; }
.viewer { flex: 1; overflow: auto; padding: 8px 24px 24px; }
.music-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 24px 16px; }

.page-wrap { position: relative; margin: 0 auto 16px; background: var(--paper); box-shadow: 0 1px 3px rgba(20,45,54,.12); }
.page-wrap img { display: block; width: 100%; height: auto; }
.highlight { position: absolute; border: 3px solid #4C8B48; background: rgba(233,239,226,.45); border-radius: 4px; pointer-events: none; }

.sheet { background: var(--paper); margin: 0 auto; padding: 48px 56px; box-shadow: 0 1px 3px rgba(20,45,54,.12); max-width: 900px; transform-origin: top center; }
.sheet h2 { font: 30px var(--serif); margin: 0; }
.sheet .sub { color: var(--ink-2); margin: 4px 0 20px; }
.sheet .legend { font-size: 15px; margin-bottom: 12px; }
.sheet .section { font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin: 22px 0 6px; }
.line { display: flex; flex-wrap: wrap; align-items: flex-end; margin: 4px 0 10px; }
.seg { display: inline-flex; flex-direction: column; white-space: pre; }
.seg .ch { min-height: 1.25em; padding-right: .6em; line-height: 1.2; }
.seg .ly { line-height: 1.35; }
.ch .p { color: var(--chord); font-weight: 700; }
.ch .a { color: var(--alt); }
.ch .q { color: var(--warn-ink); background: var(--warn-bg); border-radius: 4px; padding: 0 4px; }
.ch.focus { outline: 3px solid #4C8B48; outline-offset: 2px; border-radius: 4px; }
.inst { display: flex; flex-wrap: wrap; gap: .5em; align-items: baseline; margin: 4px 0 12px; }
.inst .mark { color: var(--ink); }
.note { font-style: italic; color: var(--ink-2); margin: 4px 0; }
.sheet .attribution { margin-top: 28px; font-size: 12px; color: var(--ink-2); }
.draft-tag { font-size: 12px; color: var(--ink-2); margin-top: 24px; }
.empty-state { max-width: 560px; margin: 48px auto; text-align: center; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Narrow and portrait: tabs instead of side-by-side */
@media (max-width: 900px), (orientation: portrait) and (max-width: 1100px) {
  .workspace { flex-direction: column; }
  .tabs-narrow { display: flex; gap: 8px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--border); }
  .tabs-narrow button { min-height: 44px; padding: 0 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--paper); }
  .tabs-narrow button[aria-selected="true"] { background: var(--sage); font-weight: 600; }
  .narrow-song { margin-left: auto; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .panel-chat { width: 100%; max-width: none; min-width: 0; border-right: 0; flex: 1; min-height: 0; }
  .panel-music { flex: 1; min-height: 0; }
  .splitter { display: none; }
  .workspace[data-tab="music"] .panel-chat { display: none; }
  .workspace[data-tab="chat"] .panel-music { display: none; }
  .sheet { padding: 24px 20px; }
  .display { font-size: 34px; }
  .header-set { display: none; }
}

/* Conversation states */
.msg.pending .msg-text { color: var(--ink-2); }
.msg .meta .btn { min-height: 32px; padding: 0 8px; }
.dictate.recording { background: var(--warn-bg); border-color: var(--warn-ink); color: var(--warn-ink); }
.live { flex-wrap: wrap; }
.live-controls { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* Connections dialog */
dialog#connections { width: min(640px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 12px; padding: 24px; background: var(--paper); color: var(--ink); }
dialog#connections::backdrop { background: rgba(20, 45, 54, .35); }
.conn-head { display: flex; justify-content: space-between; align-items: center; }
.conn-head h2 { font: 24px var(--serif); margin: 0; }
#conn-body h3 { font-size: 16px; margin: 20px 0 6px; }
.conn-row { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-bottom: 1px solid #EEF0EC; }
.conn-label { color: var(--ink-2); }
.conn-value { text-align: right; }
.conn-value.ok { color: var(--sage-ink); font-weight: 600; }
.conn-value.bad { color: var(--warn-ink); font-weight: 600; }
pre.cmd { background: #F2F3F0; padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
table.usage { width: 100%; border-collapse: collapse; font-size: 13px; }
table.usage th, table.usage td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #EEF0EC; }

/* Orb canvas from voice-runtime */
.orb { padding: 0; overflow: hidden; background: transparent; box-shadow: none; }
.orb canvas { width: 52px; height: 52px; display: block; }

/* Whole-set view */
.set-overview { background: var(--paper); border-radius: 12px; padding: 24px; display: grid; gap: 20px; max-width: 1100px; margin: 0 auto; }
.set-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.set-head h2 { font: 26px var(--serif); margin: 0; }
.set-keys { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.inline-field { display: inline-flex; align-items: center; gap: 6px; }
.inline-field select { min-height: 44px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--paper); }
.set-table { width: 100%; border-collapse: collapse; }
.set-table th, .set-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #EEF0EC; vertical-align: top; }
.set-table input[type=checkbox] { width: 22px; height: 22px; }
.nowrap { white-space: nowrap; }
.icon-btn.small, .btn.small { min-height: 36px; min-width: 36px; padding: 0 8px; font-size: 14px; }
button.link { background: none; border: 0; padding: 0; color: var(--teal); font: inherit; font-weight: 600; text-align: left; cursor: pointer; text-decoration: underline; }
.file-actions { display: grid; grid-template-columns: 1fr; gap: 6px; padding-bottom: 8px; border-bottom: 1px solid rgba(0,0,0,.06); }
dialog#panel-dialog { width: min(760px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 12px; padding: 24px; background: var(--paper); color: var(--ink); }
dialog#panel-dialog::backdrop { background: rgba(20, 45, 54, .35); }
.pages-list { padding-left: 20px; display: grid; gap: 12px; }
.page-row { display: flex; gap: 12px; align-items: flex-start; }
.page-row .thumb { width: 90px; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.library-list { display: grid; gap: 10px; margin-top: 12px; }
.lib-version { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#panel-dialog input[type=search] { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; }
.history li { margin-bottom: 6px; }
.ch.editable { cursor: pointer; text-decoration: underline dotted; }
.line.editable .ly { cursor: text; background: #FFFBEF; }
.set-head .options { display: flex; flex-wrap: wrap; gap: 8px; }
.user-highlight { position: absolute; border: 3px solid #1f6feb; background: rgba(31, 111, 235, .12); border-radius: 4px; pointer-events: none; }
.ch.picked { outline: 3px solid #1f6feb; outline-offset: 2px; border-radius: 3px; }
.line.picked .ly { background: #E6F0FF; }
.set-approval-list > li { margin-bottom: 6px; }

/* ---------------------------------------------------------------------------------------------
   Phone layout (iPhone layout work, 28 October 2026). Elements that exist only for phones are hidden
   in the wider layouts; tablet and desktop rules above are unchanged.
   --------------------------------------------------------------------------------------------- */
.menu-btn, .phone-songbar, .phone-tool, .phone-nav, .panel-library, .focus-bar, .voice-strip { display: none; }
.reading-controls { display: contents; }  /* tablet and desktop: its controls sit in the toolbar as before */
.sheet-dialog { border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: var(--paper); color: var(--ink); width: min(560px, calc(100vw - 32px)); }
.sheet-dialog::backdrop { background: rgba(20, 45, 54, .35); }
.sheet-section h3 { font-size: 15px; margin: 18px 0 8px; color: var(--ink-2); }
.sheet-section .tool-group { flex-wrap: wrap; }
.sheet-section select { min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--paper); }
.more-actions { display: grid; gap: 10px; margin-top: 12px; }
.more-actions .btn { width: 100%; }

/* A live conversation on a panel that hides the conversation (narrow tabs and phones). */
@media (max-width: 900px), (orientation: portrait) and (max-width: 1100px) {
  .voice-strip.active { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 16px; background: #E6F1FF; border-bottom: 1px solid var(--border); }
  .voice-strip-status { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .workspace[data-tab="chat"] .voice-strip.active { display: none; }  /* the conversation shows its own controls */
}

@media (max-width: 600px), (max-height: 500px) and (orientation: landscape) {
  /* Header: brand, save state and one Menu button, inside the notch and rounded corners. */
  .app-header {
    height: calc(48px + env(safe-area-inset-top)); gap: 8px;
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .brand { font-size: 19px; white-space: nowrap; }
  .header-right { margin-left: auto; min-width: 0; gap: 4px; }
  #add-music, #open-connections, #sign-out { display: none; }
  .save-state { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .menu-btn:not([hidden]) { display: inline-flex; padding: 0 12px; }
  .screen.narrow { padding: 24px max(16px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom)); }
  .display { font-size: 30px; }
  .lede { font-size: 18px; margin-bottom: 20px; }
  .dropzone { padding: 24px 16px; }
  .set-list a { padding: 12px 14px; }
  .set-list .name { overflow-wrap: anywhere; }

  /* Workspace: one panel at a time, with the section bar at the bottom. */
  .workspace { height: calc(100dvh - 48px - env(safe-area-inset-top)); }
  .keyboard-open .workspace { height: calc(var(--visible-height, 100dvh) - 48px - env(safe-area-inset-top)); }
  .tabs-narrow { display: none; }
  .phone-nav {
    display: flex; order: 10; flex: none; border-top: 1px solid var(--border); background: var(--paper);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .phone-nav button { flex: 1; min-height: 52px; min-width: 0; border: 0; background: none; font-size: 14px; color: var(--ink-2); cursor: pointer; padding: 0 4px; }
  .phone-nav button[aria-current="page"] { color: var(--teal); font-weight: 700; box-shadow: inset 0 3px 0 var(--teal); }
  .keyboard-open .phone-nav { display: none; }
  .voice-strip.active { order: -1; padding: 6px max(12px, env(safe-area-inset-left)); }
  .voice-strip .btn { min-height: 44px; padding: 0 14px; }
  .workspace[data-tab="library"] .panel-chat, .workspace[data-tab="library"] .panel-music { display: none; }
  .workspace[data-tab="library"] .panel-library { display: block; }
  .workspace[data-tab="music"] .panel-chat, .workspace[data-tab="chat"] .panel-music { display: none; }
  .panel-music, .panel-chat, .panel-library { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

  /* Library panel. */
  .panel-library { flex: 1; min-height: 0; overflow-y: auto; padding-top: 16px; padding-bottom: 16px; }
  .panel-library > * { margin-left: 12px; margin-right: 12px; }
  .library-songs { list-style: none; padding: 0; display: grid; gap: 8px; }
  .library-song {
    width: 100%; min-height: 56px; display: grid; gap: 2px; text-align: left; padding: 8px 14px;
    background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
  }
  .library-song[aria-current="true"] { border-color: var(--teal); box-shadow: inset 4px 0 0 var(--teal); }
  .library-song-title { font-weight: 600; overflow-wrap: anywhere; }
  .library-actions { display: grid; gap: 8px; margin-top: 16px; }
  .library-actions .btn { width: 100%; }

  /* Music: song bar, views, then page / Tools / Focus. Key, zoom, appearance and files are in the Tools sheet. */
  .toolbar { gap: 6px; padding: 8px 12px 4px; }
  .phone-songbar { display: flex; width: 100%; gap: 6px; }
  .songbar-title {
    flex: 1; min-width: 0; min-height: 44px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--paper);
    font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
  }
  #song-select { display: none; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; min-width: 0; padding: 0 4px; font-size: 15px; }
  .reading-controls { display: flex; align-items: center; gap: 6px; width: 100%; }
  #page-group { flex: 1; }
  #page-group span { font-size: 14px; white-space: nowrap; }
  .phone-tool { display: inline-flex; padding: 0 12px; }
  .toolbar .phone-tool:first-of-type { margin-left: auto; }
  .status-bar { margin: 0 12px 4px; padding: 4px 10px; font-size: 13px; min-height: 0; }
  .status-bar .btn { min-height: 44px; margin-left: auto; padding: 0 12px; font-size: 14px; }
  .viewer { padding: 4px 8px 12px; }
  .music-foot { display: none; }
  .sheet { padding: 16px 12px; }

  /* Focus: the music fills the screen; the reading controls float over its bottom edge. */
  .workspace[data-focus="1"] .toolbar, .workspace[data-focus="1"] .status-bar, .workspace[data-focus="1"] .phone-nav { display: none; }
  .focus-reading .app-header { display: none; }
  .focus-reading .workspace { height: 100dvh; }
  .workspace[data-focus="1"] .panel-music { position: relative; }
  .workspace[data-focus="1"] .viewer { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .workspace[data-focus="1"] .focus-bar {
    display: flex; gap: 8px; position: absolute; left: 50%; transform: translateX(-50%);
    bottom: calc(10px + env(safe-area-inset-bottom)); padding: 6px; border-radius: 12px; background: rgba(255,255,255,.94);
    box-shadow: 0 1px 6px rgba(20,45,54,.25);
  }

  /* Conversation: the message box shrinks; Dictate becomes an icon with the same accessible name. */
  .chat-head { padding: 12px 12px 4px; }
  .panel-title { font-size: 21px; }
  .chat-scroll { padding: 4px 12px 12px; gap: 12px; }
  .chat-dock { padding: 8px 12px 10px; gap: 8px; }
  .live { gap: 8px; }
  .live-controls { margin-left: 0; flex-wrap: wrap; }
  .composer { gap: 6px; }
  .composer textarea { min-width: 0; min-height: 48px; padding: 12px; }
  .dictate { flex: none; width: 48px; min-width: 48px; padding: 0; }
  .dictate-label { display: none; }
  .send { flex: none; width: 48px; height: 48px; }
  .msg { max-width: 100%; }
  .approve-card, .download-card, .qcard { padding: 14px; }
  .qcard input[type=text], .qcard select { min-width: 0; }

  /* Sheets and dialogs: full-width, rising from the bottom, inside the home indicator. */
  .sheet-dialog, dialog#connections, dialog#panel-dialog {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 14px 14px 0 0; max-height: 88dvh; overflow-y: auto;
    padding: 16px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .conn-row { flex-wrap: wrap; }
  .conn-value { text-align: left; overflow-wrap: anywhere; }
  .page-row { flex-wrap: wrap; }

  /* Whole set: the table scrolls inside its own box rather than widening the page. */
  .set-overview { padding: 12px; gap: 14px; }
  .set-head h2 { font-size: 22px; overflow-wrap: anywhere; }
  /* Each song of the set becomes a card: choose / title, order, key, status, then its actions. */
  .set-table, .set-table tbody { display: block; }
  .set-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .set-table tr { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 4px 10px; padding: 12px 0; border-bottom: 1px solid #EEF0EC; }
  .set-table td { display: block; padding: 0; border: 0; min-width: 0; }
  .set-table td:nth-child(1) { grid-column: 1; grid-row: 1; display: flex; align-items: center; justify-content: center; min-height: 44px; }
  .set-table td:nth-child(3) { grid-column: 2; grid-row: 1; overflow-wrap: anywhere; align-self: center; }
  .set-table td:nth-child(2) { grid-column: 1; grid-row: 2 / span 2; display: flex; flex-direction: column; gap: 4px; }
  .set-table td:nth-child(4) { grid-column: 2; grid-row: 2; }
  .set-table td:nth-child(5) { grid-column: 2; grid-row: 3; }
  .set-table td:nth-child(6) { grid-column: 1 / -1; grid-row: 4; display: flex; flex-wrap: wrap; gap: 6px; white-space: normal; }
  .set-table td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-2); font-size: 14px; }
  .icon-btn.small, .btn.small { min-height: 44px; min-width: 44px; padding: 0 12px; font-size: 15px; }
  .set-keys { padding: 8px; }
}

/* A phone held sideways: no header row, everything on one toolbar row, a slimmer section bar. */
@media (max-height: 500px) and (orientation: landscape) {
  body[data-screen="workspace"] .app-header { display: none; }  /* Menu stays reachable as More */
  .workspace { height: 100dvh; }
  .keyboard-open .workspace { height: var(--visible-height, 100dvh); }
  .toolbar { flex-wrap: nowrap; padding: 4px 12px; }
  .phone-songbar { width: auto; flex: 1 1 140px; min-width: 110px; }
  #songbar-prev, #songbar-next { display: none; }  /* the title opens the song list */
  .segmented { width: auto; flex: 0 0 auto; }
  .segmented button { flex: 0 0 auto; padding: 0 10px; white-space: nowrap; }  /* labels never cut short */
  .reading-controls { width: auto; flex: none; }
  #page-group { flex: none; }
  .status-bar { padding: 0 10px; }
  .phone-nav button { min-height: 44px; }
  .screen.narrow { padding-top: max(16px, env(safe-area-inset-top)); }
}

/* Smaller phones held sideways (review M1: 667×375, 736×414): one row cannot hold the song, the four views,
   page turning, Tools and Focus. Page turning, Tools and Focus take a second row; nothing is hidden. */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 799px) {
  .toolbar { flex-wrap: wrap; row-gap: 4px; }
  .reading-controls { width: 100%; flex: 1 0 100%; }
}

/* Touch screens (iPad included): the whole-set table's small buttons get full-size touch targets. */
@media (pointer: coarse) {
  .icon-btn.small, .btn.small { min-height: 44px; min-width: 44px; }
}
