/* Unified landscape workbench. This file loads last so legacy route-specific
   mobile rules cannot change the global orientation contract. */
@media (max-width: 1000px) and (orientation: landscape) {
  body { overflow: hidden; }
  .app-shell { width: 100dvw !important; }

  .display-mode-switch { flex: 0 0 auto; }

  .site-header {
    display: grid !important;
    grid-template-columns: minmax(96px, auto) minmax(0, 1fr) auto !important;
    grid-template-rows: 1fr !important;
    width: 100% !important;
    max-width: none !important;
    height: 52px !important;
    min-height: 52px !important;
    gap: 8px !important;
    padding: 0 10px !important;
  }

  .wordmark-symbol { width: 23px; height: 23px; font-size: 12px; }
  .wordmark-name { font-size: 11px; }
  .wordmark-caption { display: none; }
  .main-nav { grid-column: 2 !important; grid-row: 1 !important; min-width: 0; overflow-x: auto; }
  .nav-link { padding: 6px 7px; font-size: 10px; }
  .header-status { grid-column: 3 !important; grid-row: 1 !important; font-size: 9px; }
  .header-status > span:not(.header-route):not(.status-dot) { display: none; }

  main {
    width: 100% !important;
    max-width: none !important;
    height: calc(100dvh - 52px) !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 10px 10px !important;
  }

  body[data-page-layout="teaching"] main,
  body[data-page-layout="workspace"] main,
  body[data-page-layout="interactive"] main { overflow: hidden !important; }

  .view-heading { margin-bottom: 14px; }
  .view-heading h1 { font-size: 28px; }
  .view-heading .lead { font-size: 11px; }

  .home-hero { grid-template-columns: minmax(0, 1.1fr) minmax(220px, .9fr) !important; gap: 24px; min-height: 0; }
  .entry-row { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 10px; }
  .ear-layout, .lab-layout { grid-template-columns: minmax(0, 1fr) minmax(190px, .72fr) !important; gap: 18px; }
  .ear-visual { min-height: 0; }
  .hardware-controls { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px; }
  .hardware-controls .hardware-field:first-child { grid-column: auto; }
  .about-layout { max-width: 760px; }
}

/* A real landscape phone/tablet uses the same top-to-bottom workspace as a
   desktop window, just with tighter dimensions. */
@media (max-width: 1000px) and (orientation: landscape) {
  .app-shell { width: 100%; height: 100dvh; min-height: 100dvh; }
  .view { padding-top: 16px; }

  body[data-page-layout="teaching"] .teaching-workspace {
    grid-template-rows: minmax(0, 1fr) 132px !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body[data-page-layout="teaching"] .teaching-content { min-height: 0; }
  body[data-page-layout="teaching"] .teaching-instrument { min-width: 0; }
  body[data-page-layout="teaching"] .teaching-instrument [data-teaching-keyboard] { height: 108px; }

  body[data-route="theory"] .teaching-workspace:has(.teaching-instrument.is-hidden) {
    grid-template-rows: minmax(0, 1fr) 0 !important;
  }

}

/* Portrait phone viewports still render a landscape workbench. The shell is
   sized in the phone's landscape dimensions before the quarter-turn, so the
   user gets one consistent horizontal surface across every route. */
@media (max-width: 700px) and (orientation: portrait) {
  html, body { width: 100%; height: 100%; overflow: hidden !important; }
  body { background: var(--bg); }
  body[data-page-kind] .app-shell,
  body[data-page-layout] .app-shell,
  .app-shell {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    width: 100dvh !important;
    height: 100dvw !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    transform: translate(-50%, -50%) rotate(90deg) !important;
    transform-origin: center !important;
    overflow: hidden !important;
  }
  .site-header {
    display: grid !important;
    grid-template-columns: 102px minmax(0, 1fr) auto !important;
    grid-template-rows: 1fr !important;
    width: 100% !important;
    height: 52px !important;
    min-height: 52px !important;
    padding: 0 14px !important;
  }
  .main-nav { grid-column: 2 !important; grid-row: 1 !important; }
  .header-status { grid-column: 3 !important; grid-row: 1 !important; }
  main {
    width: 100% !important;
    min-width: 0 !important;
    height: calc(100% - 52px) !important;
    max-height: none !important;
    padding: 0 14px 18px !important;
  }
  body[data-page-layout="teaching"] .teaching-workspace { grid-template-rows: minmax(0, 1fr) 128px !important; grid-template-columns: minmax(0, 1fr) !important; }

}

@media (prefers-reduced-motion: reduce) {
  .app-shell { transition: none !important; }
}

/* Preserve each interactive page's upper left/right work area on compact
   landscape screens. Only the bottom instrument or falling board is capped. */
@media (max-width: 1000px) and (orientation: landscape),
       (max-width: 700px) and (orientation: portrait) {
  body[data-route="practice"][data-page-kind="workspace"] .practice-shell {
    grid-template-rows: 38px minmax(0, 1fr) 128px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"] .practice-instrument-panel,
  body[data-route="theory"][data-page-kind="teaching"] .piano-surface,
  body[data-route="practice"][data-page-kind="workspace"] .practice-keyboard .piano-surface,
  body[data-route="practice"][data-page-kind="workspace"] .practice-hardware-device .keyboard {
    height: 128px !important;
    min-height: 0 !important;
  }

  body[data-route="theory"] .teaching-workspace:has(.teaching-instrument.is-hidden) {
    grid-template-rows: minmax(0, 1fr) 0 !important;
  }

  body[data-route="rhythm"][data-page-kind="interactive"] .rhythm-shell {
    grid-template-rows: 38px minmax(0, 1fr) 148px !important;
  }

  body[data-route="rhythm"][data-page-kind="interactive"] .rhythm-stage {
    height: 148px !important;
    min-height: 0 !important;
    max-height: 148px !important;
  }

  /* Keep the theory lesson as a real two-pane workbench after all legacy
     phone rules have run. The catalog and lesson each own their scroll area. */
  body[data-route="theory"] .teaching-content .theory-layout {
    display: grid !important;
    grid-template-columns: 228px minmax(0, 1fr) !important;
    grid-template-rows: minmax(0, 1fr) !important;
    gap: 24px !important;
    align-items: stretch !important;
    height: 100% !important;
  }

  body[data-route="theory"] .teaching-content .lesson-sidebar {
    position: static !important;
    height: 100% !important;
    max-height: none !important;
    overflow-y: auto !important;
    padding: 0 20px 0 0 !important;
    border-right: 1px solid var(--line) !important;
    border-bottom: 0 !important;
    background: transparent !important;
  }

  body[data-route="theory"] .lesson-sidebar-head {
    position: static !important;
    min-height: 0 !important;
    padding: 0 2px 13px !important;
    border-bottom: 2px solid var(--accent) !important;
    background: transparent !important;
  }

  body[data-route="theory"] .lesson-sidebar-title {
    display: flex !important;
  }

  body[data-route="theory"] .lesson-sidebar-title strong {
    display: inline !important;
    font-size: 17px !important;
  }

  body[data-route="theory"] .lesson-sidebar-title small {
    display: inline !important;
    margin-top: 0 !important;
    font-size: 11px !important;
  }

  body[data-route="theory"] .lesson-catalog-toggle {
    display: none !important;
  }

  body[data-route="theory"] .teaching-content .theory-panel {
    display: flex !important;
    height: 100% !important;
    min-height: 0 !important;
    border-top: 2px solid var(--accent) !important;
  }

  body[data-route="theory"] .theory-head {
    display: flex !important;
    align-items: baseline !important;
    gap: 16px !important;
    padding: 12px 0 10px !important;
  }

  body[data-route="theory"] .theory-head > div:first-child {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  body[data-route="theory"] .theory-head h2 {
    font-size: 25px !important;
  }

  body[data-route="theory"] .theory-head p {
    font-size: 11px !important;
  }

  body[data-route="theory"] .theory-head .formula {
    flex: 0 1 170px !important;
    max-width: 170px !important;
    white-space: normal !important;
    text-align: right !important;
  }

  body[data-route="theory"] .theory-visual {
    min-height: 0 !important;
    overflow-y: auto !important;
    padding: 14px 0 24px !important;
  }
}

/* Each teaching route owns two complete surfaces. The hardware surface does
   not reserve space for the software keyboard, so the lesson fills that row. */
body[data-route="theory"][data-display-mode="software"] .teaching-instrument[data-software-instrument] {
  display: block !important;
}

body[data-route="theory"][data-display-mode="hardware"] .teaching-workspace {
  grid-template-rows: minmax(0, 1fr) 0 !important;
}

body[data-route="theory"][data-display-mode="hardware"] .teaching-instrument[data-software-instrument] {
  display: none !important;
}

body[data-route="practice"][data-display-mode="software"] .practice-keyboard {
  display: block !important;
}

body[data-route="practice"][data-display-mode="software"] .practice-hardware-device {
  display: none !important;
}

body[data-route="practice"][data-display-mode="hardware"] .practice-keyboard {
  display: none !important;
}

body[data-route="practice"][data-display-mode="hardware"] .practice-hardware-device {
  display: block !important;
}

/* Practice teaches note names; computer-key bindings belong only in the
   dedicated settings surface and are intentionally absent from both layouts. */
body[data-route="practice"] .practice-keyboard .key-binding,
body[data-route="practice"] .practice-keyboard .keyboard-label,
body[data-route="practice"] .practice-keyboard .binding-opacity {
  display: none !important;
}

body[data-route="practice"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction {
  display: block !important;
  min-height: 0 !important;
  height: auto !important;
  margin: 0 !important;
  padding: 5px 0 0;
  color: var(--muted);
  font-size: 10px;
}

/* With no simulated keyboard to anchor the row, the physical surface only
   uses the height required by its status/controls and the lesson expands. */
body[data-route="practice"][data-display-mode="hardware"] .practice-instrument-panel {
  min-height: 0 !important;
  height: auto !important;
}

@media (max-width: 1000px) and (orientation: landscape),
       (max-width: 700px) and (orientation: portrait) {
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-shell {
    grid-template-rows: 38px minmax(0, 1fr) auto !important;
  }
}

/* Physical-piano practice is a separate workspace, not the software layout
   with its keyboard removed. The lesson owns the full left side while every
   relevant setup, action and device status is grouped in the right rail. */
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-shell {
  grid-template-columns: minmax(0, 1.55fr) minmax(340px, .65fr) !important;
  grid-template-rows: auto auto minmax(0, 1fr) !important;
  gap: 10px 24px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-app-bar {
  grid-column: 1 / -1 !important;
  grid-row: 1 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .local-score-bar,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .guitar-source-bar {
  display: none !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-workspace {
  display: contents !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-learning-panel {
  grid-column: 1 !important;
  grid-row: 2 / 4 !important;
  min-width: 0;
  height: 100%;
  overflow: hidden !important;
  border-top: 2px solid var(--accent);
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar {
  display: grid !important;
  grid-column: 2 !important;
  grid-row: 2 !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: auto auto auto !important;
  align-content: start;
  gap: 14px !important;
  min-width: 0;
  padding: 16px 0 18px 20px !important;
  border-top: 2px solid var(--accent);
  border-right: 0;
  border-bottom: 1px solid var(--line);
  border-left: 1px solid var(--line) !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-config-instrument-switch,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-config-actions {
  display: none !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar {
  display: grid !important;
  grid-row: 1 !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 11px 10px !important;
  width: 100%;
  padding: 0 !important;
  overflow: visible !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar .practice-field {
  display: grid !important;
  align-items: center !important;
  gap: 5px !important;
  min-width: 0;
  color: var(--muted);
  font-size: 10px !important;
  white-space: normal !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar .practice-field:nth-child(-n+2) {
  grid-column: 1 / -1;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar select {
  width: 100%;
  min-width: 0;
  min-height: 40px !important;
  padding: 7px 10px !important;
  font-size: 12px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar input[type="range"] {
  width: 100%;
  height: 20px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch {
  display: grid !important;
  grid-row: 2 !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  width: 100%;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch button {
  min-width: 0;
  min-height: 42px !important;
  padding: 8px 7px !important;
  font-size: 11px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .hardware-config-actions {
  display: grid !important;
  grid-row: 3 !important;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .hardware-config-actions button {
  min-width: 0;
  min-height: 42px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
  font-size: 11px;
  font-weight: 700;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .hardware-config-actions button.is-active,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .hardware-config-actions button[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-instrument-panel {
  display: grid !important;
  grid-column: 2 !important;
  grid-row: 3 !important;
  align-content: start !important;
  align-self: stretch;
  height: 100% !important;
  min-height: 0 !important;
  padding: 18px 0 0 20px;
  overflow: hidden !important;
  border-top: 0;
  border-left: 1px solid var(--line);
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-status {
  padding: 11px 0 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-stage {
  min-height: 0;
  overflow: auto;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-actions {
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device {
  display: grid !important;
  align-content: start;
  gap: 16px;
  width: 100%;
  height: 100%;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 6px 14px;
  margin: 0 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head > div {
  grid-column: 1 / -1;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head h2 {
  margin: 0 0 5px;
  font-size: 18px;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-transport,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device [data-hardware-battery] {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: var(--surface);
  font-size: 10px;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-mode,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-help {
  display: none !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction {
  padding: 12px 14px;
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  background: var(--accent-soft);
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction {
  min-height: 0;
  margin: 0;
  color: var(--text);
  font-size: 11px;
  line-height: 1.6;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-actions .button,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-actions input[type="number"] {
  min-height: 38px;
}

@media (max-width: 1000px) and (orientation: landscape),
       (max-width: 700px) and (orientation: portrait) {
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-shell {
    grid-template-columns: minmax(0, 1fr) minmax(286px, .6fr) !important;
    grid-template-rows: 38px auto minmax(0, 1fr) !important;
    gap: 5px 10px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar {
    gap: 6px !important;
    padding: 7px 0 9px 10px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar {
    grid-template-columns: minmax(0, 1.15fr) minmax(110px, .85fr) !important;
    align-items: end;
    gap: 7px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar .practice-field:nth-child(-n+2) {
    grid-column: auto;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar .practice-field:nth-child(n+3) {
    display: none !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar select {
    min-height: 32px !important;
    padding: 4px 7px !important;
    font-size: 10px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar input[type="range"] {
    height: 16px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch button,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .hardware-config-actions button {
    min-height: 34px !important;
    padding: 5px 4px !important;
    font-size: 9px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-instrument-panel {
    padding: 9px 0 0 10px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device {
    gap: 8px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 5px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head > div {
    grid-column: 1;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head h2 {
    margin: 0;
    font-size: 12px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head p {
    display: none;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-transport,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device [data-hardware-battery] {
    min-height: 24px;
    padding: 3px 6px;
    font-size: 8px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction {
    padding: 8px 10px;
    font-size: 9px;
    line-height: 1.4;
  }
}

/* The hardware layout gives the lesson the full height of its left work area.
   Sequence cards grow with the available room instead of leaving a blank lower half. */
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-stage {
  display: flex;
  align-items: stretch;
  overflow: hidden;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-learning {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  align-content: stretch;
  gap: 12px;
  width: 100%;
  min-height: 0;
  height: 100%;
  padding: 14px 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-focus,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-head {
  margin: 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-note-grid {
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  grid-auto-rows: minmax(82px, 1fr);
  align-content: stretch;
  min-height: 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-note {
  display: grid;
  min-height: 0;
  align-content: center;
}

@media (max-width: 1000px) and (orientation: landscape),
       (max-width: 700px) and (orientation: portrait) {
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-learning {
    gap: 5px;
    padding: 6px 0;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-note-grid {
    grid-template-columns: repeat(auto-fit, minmax(54px, 1fr));
    grid-auto-rows: minmax(42px, 1fr);
    gap: 4px;
  }
}

/* The global header is the only navigation and display-mode control. */
body[data-route="practice"][data-page-kind="workspace"] .practice-app-bar {
  display: none !important;
}

body[data-route="practice"][data-page-kind="workspace"] .practice-shell {
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  gap: 8px !important;
}

body[data-route="practice"][data-page-kind="workspace"] .practice-controlbar {
  grid-column: 1 !important;
  grid-row: 1 !important;
}

body[data-route="practice"][data-page-kind="workspace"] .practice-workspace {
  grid-column: 1 !important;
  grid-row: 2 !important;
}

/* Entity controls are grouped by intent instead of sharing one undifferentiated row. */
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-shell {
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  gap: 8px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar {
  display: grid !important;
  grid-column: 1 !important;
  grid-row: 1 !important;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, .7fr) !important;
  grid-template-rows: auto !important;
  align-items: stretch;
  gap: 16px !important;
  min-width: 0;
  padding: 10px 0 12px !important;
  border-top: 2px solid var(--accent);
  border-right: 0;
  border-bottom: 1px solid var(--line);
  border-left: 0 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-config-instrument-switch,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-config-actions {
  display: none !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch {
  position: relative;
  min-width: 0;
  padding-top: 20px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar::before,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch::before {
  content: attr(data-section-label);
  position: absolute;
  top: 0;
  left: 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar {
  display: grid !important;
  grid-column: 1 !important;
  grid-row: 1 !important;
  grid-template-columns: minmax(170px, 1.6fr) minmax(130px, 1.1fr) repeat(3, minmax(86px, .8fr)) !important;
  align-items: end;
  gap: 8px !important;
  width: 100%;
  overflow: visible !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar .practice-field,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar .practice-field:nth-child(-n+2) {
  display: grid !important;
  grid-column: auto;
  align-items: center !important;
  gap: 3px !important;
  min-width: 0;
  color: var(--muted);
  font-size: 9px !important;
  white-space: normal !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar select {
  width: 100%;
  min-width: 0;
  min-height: 34px !important;
  padding: 5px 8px !important;
  font-size: 11px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar input[type="range"] {
  width: 100%;
  height: 16px !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch {
  display: grid !important;
  grid-column: 2 !important;
  grid-row: 1 !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  align-content: end;
  align-self: stretch;
  gap: 3px;
  width: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  padding-right: 0 !important;
  padding-bottom: 0 !important;
  padding-left: 16px !important;
  background: transparent;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch::before {
  left: 16px;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch button {
  min-width: 0;
  min-height: 34px !important;
  padding: 5px 6px !important;
  font-size: 10px !important;
}

/* The lesson keeps priority, but measure cards no longer stretch to fill the viewport. */
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-workspace {
  display: grid !important;
  grid-column: 1 !important;
  grid-row: 2 !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: minmax(0, 1fr) auto !important;
  gap: 8px !important;
  min-height: 0;
  overflow: hidden;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-learning-panel {
  display: grid !important;
  grid-column: 1 !important;
  grid-row: 1 !important;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: auto;
  min-height: 0;
  overflow: hidden !important;
  border-top: 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-status {
  display: flex !important;
  padding: 7px 0 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-stage {
  display: block;
  min-height: 0;
  overflow: auto;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-learning {
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-content: start;
  gap: 7px;
  width: 100%;
  min-height: 0;
  height: auto;
  padding: 8px 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-focus,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-head {
  margin: 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-note-grid {
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  grid-auto-rows: clamp(56px, 9dvh, 82px);
  align-content: start;
  min-height: 0;
  gap: 6px;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-note {
  display: grid;
  min-height: 0;
  place-items: center;
  align-content: center;
  padding: 5px 8px;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-actions {
  flex-wrap: nowrap;
  gap: 6px;
  padding: 7px 0 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-actions .button,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-actions input[type="number"] {
  min-height: 32px;
}

/* Device status and physical-piano commands form their own bottom section. */
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-instrument-panel {
  display: block !important;
  grid-column: 1 !important;
  grid-row: 2 !important;
  height: auto !important;
  min-height: 0 !important;
  padding: 8px 0 0;
  overflow: hidden !important;
  border-top: 2px solid var(--accent);
  border-left: 0;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device {
  display: grid !important;
  grid-template-columns: minmax(260px, .8fr) minmax(300px, .9fr) minmax(300px, 1.2fr);
  align-items: center;
  align-content: center;
  gap: 12px 18px;
  width: 100%;
  height: auto;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head {
  display: grid !important;
  position: relative;
  padding-top: 18px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 5px 8px;
  margin: 0 !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head > div {
  grid-column: 1 / -1;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head::before,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions::before,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction::before {
  content: attr(data-section-label);
  position: absolute;
  top: 0;
  left: 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head h2 {
  margin: 0 0 2px;
  font-size: 14px;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head p {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.4;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-transport,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device [data-hardware-battery] {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: var(--surface);
  font-size: 9px;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions {
  position: relative;
  padding-top: 18px;
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions button {
  min-width: 0;
  min-height: 34px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
  font-size: 10px;
  font-weight: 700;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions button.is-active,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions button[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-mode,
body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-help {
  display: none !important;
}

body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction {
  position: relative;
  padding-top: 26px;
  min-height: 34px;
  margin: 0 !important;
  padding: 8px 10px;
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  color: var(--text);
  background: var(--accent-soft);
  font-size: 10px;
  line-height: 1.5;
}

@media (max-width: 1000px) and (orientation: landscape),
       (max-width: 700px) and (orientation: portrait) {
  body[data-route="practice"][data-page-kind="workspace"] .practice-shell {
    grid-template-rows: minmax(0, 1fr) auto !important;
    gap: 4px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="software"] .practice-shell {
    grid-template-columns: minmax(0, 1fr) minmax(270px, .6fr) !important;
    grid-template-rows: minmax(0, 1fr) auto !important;
    gap: 5px 10px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="software"] .practice-controlbar {
    grid-column: 2 !important;
    grid-row: 1 !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="software"] .practice-workspace {
    display: contents !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="software"] .practice-learning-panel {
    grid-column: 1 !important;
    grid-row: 1 !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="software"] .practice-instrument-panel {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-shell {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar {
    grid-template-columns: minmax(0, 1.2fr) minmax(270px, .8fr) !important;
    gap: 8px !important;
    padding: 5px 0 6px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch {
    padding-top: 14px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar::before,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch::before {
    font-size: 7px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar {
    grid-template-columns: minmax(130px, 1.2fr) minmax(100px, .8fr) !important;
    gap: 5px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar .practice-field:nth-child(n+3) {
    display: none !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-toolbar select {
    min-height: 27px !important;
    padding: 3px 6px !important;
    font-size: 9px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch {
    padding-left: 8px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch::before {
    left: 8px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-controlbar .mode-switch button {
    min-height: 27px !important;
    padding: 3px 4px !important;
    font-size: 8px !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-status {
    min-height: 28px;
    padding: 3px 0 !important;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-status h2 {
    font-size: 13px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-learning {
    gap: 3px;
    padding: 3px 0;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .phrase-note-grid {
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
    grid-auto-rows: 54px;
    gap: 4px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-instrument-panel {
    padding: 4px 0 0;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device {
    grid-template-columns: minmax(180px, .72fr) minmax(240px, .9fr) minmax(250px, 1.1fr);
    gap: 6px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head > div {
    grid-column: 1;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head h2 {
    font-size: 11px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head p {
    display: none;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions {
    padding-top: 14px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-head::before,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions::before,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction::before {
    font-size: 7px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-transport,
  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device [data-hardware-battery] {
    min-height: 22px;
    padding: 2px 4px;
    font-size: 7px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-config-actions button {
    min-height: 27px;
    padding: 3px;
    font-size: 8px;
  }

  body[data-route="practice"][data-page-kind="workspace"][data-display-mode="hardware"] .practice-hardware-device .hardware-instruction {
    min-height: 27px;
    padding: 20px 7px 5px;
    font-size: 8px;
  }
}
