/* Desktop and iPad landscape fit rules */
@media (min-width: 761px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    width: 100vw;
    max-width: 3840px;
    padding: clamp(10px, 0.75vw, 24px);
    grid-template-columns: minmax(236px, 0.66fr) minmax(440px, 1.52fr) minmax(284px, 0.9fr);
    grid-template-rows: minmax(0, 0.46fr) minmax(0, 0.54fr);
    gap: clamp(10px, 0.75vw, 24px);
    overflow: hidden;
  }

  .panel {
    min-width: 0;
    min-height: 0;
    border-radius: clamp(18px, 1.35vw, 34px);
  }

  .tempo-card {
    min-height: 0;
    grid-template-rows: auto minmax(82px, 0.36fr) auto minmax(150px, 1fr) auto auto;
    gap: clamp(5px, 0.65vh, 14px);
    padding: clamp(14px, 1.05vw, 34px);
  }

  .settings-card,
  .practice-card,
  .rhythm-card-wrap {
    overflow: hidden;
    padding: clamp(8px, 0.7vw, 18px);
  }

  .brand-row {
    min-width: 0;
    gap: clamp(8px, 0.7vw, 14px);
  }

  h1,
  h2,
  .eyebrow,
  .signature-field span,
  .signature-field small,
  .field span,
  .switch span,
  .status-grid span,
  .status-grid strong,
  .primary-actions button,
  .practice-modes button,
  .tempo-presets button,
  .custom-select-button,
  .custom-select-menu button,
  .rhythm-legend span,
  .rhythm-reset,
  .theme-toggle-desktop {
    white-space: nowrap;
  }

  h1,
  h2,
  .field span,
  .switch span,
  .custom-select-button,
  .status-grid strong {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  h1 {
    font-size: clamp(2.15rem, 3.45vw, 7rem);
    line-height: 1;
  }

  h2 {
    font-size: clamp(1.25rem, 1.7vw, 3rem);
    line-height: 0.95;
    letter-spacing: -0.04em;
  }

  .eyebrow {
    margin-bottom: 3px;
    font-size: clamp(0.72rem, 0.62vw, 1.18rem);
    letter-spacing: 0.1em;
  }

  .signature-field {
    min-width: clamp(126px, 12vw, 290px);
    max-width: clamp(126px, 18vw, 360px);
    padding: clamp(6px, 0.7vw, 16px);
  }

  .signature-field strong {
    font-size: clamp(1.55rem, 1.55vw, 3.1rem);
    line-height: 0.9;
  }

  .signature-field small {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  .tempo-panel {
    min-height: 0;
    grid-template-columns: clamp(54px, 4.2vw, 128px) minmax(0, 1fr) clamp(54px, 4.2vw, 128px);
  }

  .tempo-readout {
    min-width: 0;
    min-height: 0;
  }

  #bpmInput {
    font-size: clamp(5rem, 8.4vw, 15rem);
    line-height: 0.76;
  }

  .slider {
    height: clamp(28px, 3.6vh, 34px);
    margin-top: clamp(7px, 0.9vh, 12px);
    margin-bottom: 0;
  }

  .beat-stage {
    min-height: 0;
    height: 100%;
  }

  .beat-count {
    font-size: clamp(5.2rem, 8vw, 15rem);
  }

  .status-grid,
  .primary-actions,
  .tempo-presets,
  .practice-modes,
  .practice-grid,
  .controls {
    gap: clamp(4px, 0.55vw, 12px);
  }

  .status-grid div,
  .field,
  .switch {
    min-width: 0;
    min-height: 0;
    padding: clamp(5px, 0.6vw, 14px);
    border-radius: clamp(12px, 1vw, 24px);
  }

  .status-grid div {
    min-height: clamp(42px, 5.1vh, 84px);
  }

  .status-grid strong {
    font-size: clamp(1.35rem, 2vw, 3.8rem);
    line-height: 1;
  }

  .tap-button,
  .timer-reset,
  .start-button {
    min-width: 0;
    min-height: clamp(42px, 5.2vh, 80px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .controls {
    grid-auto-rows: minmax(0, 1fr);
  }

  .practice-grid {
    grid-auto-rows: minmax(0, 1fr);
  }

  .settings-card .controls,
  .practice-card .practice-grid {
    overflow: hidden;
  }

  .settings-card .field,
  .settings-card .switch,
  .practice-grid .field {
    min-height: 0;
  }

  .field span,
  .switch span,
  .status-grid span {
    font-size: clamp(0.68rem, 0.65vw, 1rem);
    line-height: 1.05;
  }

  .field:not(.inactive) span strong {
    font-size: clamp(0.65rem, 0.58vw, 0.92rem);
  }

  .custom-select-button,
  .field select,
  .field input[type="number"] {
    min-height: clamp(30px, 3.7vh, 52px);
    padding-top: 4px;
    padding-bottom: 4px;
    font-size: clamp(0.72rem, 0.72vw, 1.05rem);
  }

  .tempo-presets button,
  .practice-modes button {
    min-width: 0;
    min-height: clamp(30px, 4vh, 56px);
    padding: 0 clamp(6px, 0.65vw, 14px);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: clamp(0.78rem, 0.78vw, 1.25rem);
  }

  .practice-reset {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .rhythm-heading {
    align-items: flex-start;
  }

  .rhythm-tools {
    min-width: 0;
    flex-wrap: nowrap;
  }

  .rhythm-legend {
    min-width: 0;
    gap: clamp(2px, 0.3vw, 6px);
  }

  .rhythm-legend span {
    min-width: 0;
    padding: 2px clamp(4px, 0.42vw, 9px);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: clamp(0.58rem, 0.52vw, 0.9rem);
  }

  .rhythm-grid {
    display: grid;
    grid-template-columns: repeat(var(--beat-count, 4), minmax(0, 1fr));
    gap: clamp(4px, 0.5vw, 10px);
    overflow: hidden;
  }

  .rhythm-beat-bar {
    min-width: 0;
    grid-template-rows: clamp(22px, 2.7vh, 38px) minmax(0, 1fr) clamp(22px, 2.7vh, 38px);
    gap: clamp(3px, 0.45vh, 6px);
  }

  .rhythm-split-button {
    height: auto;
    min-height: 0;
    font-size: clamp(0.72rem, 0.8vw, 1.2rem);
  }

  .rhythm-cells {
    gap: clamp(3px, 0.45vh, 6px);
  }
}

@media (min-width: 761px) and (max-height: 820px) {
  .app {
    padding: 10px;
    gap: 10px;
  }

  .tempo-card {
    grid-template-rows: auto minmax(72px, 0.3fr) 14px minmax(126px, 1fr) auto auto;
    gap: 5px;
  }

  #bpmInput {
    font-size: clamp(4.35rem, 6.4vw, 7.8rem);
    line-height: 0.72;
  }

  .tempo-readout span {
    margin-top: 2px;
    margin-bottom: 7px;
    font-size: clamp(0.75rem, 0.85vw, 1rem);
  }

  .beat-flash {
    inset: 12px;
  }

  .practice-grid {
    gap: 5px;
  }

  .section-heading.compact {
    margin-bottom: 3px;
  }
}

@media (min-width: 761px) and (max-width: 1400px) {
  .rhythm-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px 6px;
  }

  .rhythm-heading .rhythm-tools {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 54px);
    align-items: center;
    gap: 4px;
    overflow: hidden;
  }

  .rhythm-legend {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-width: 0;
    gap: 3px;
  }

  .rhythm-legend span {
    min-width: 0;
    padding-inline: 3px;
    text-align: center;
  }

  .rhythm-help-icon {
    display: none;
  }

  .rhythm-reset {
    width: 54px;
    min-width: 0;
    padding-inline: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Mobile-only elements hidden on desktop */
.theme-dock,
.advanced-rhythm-toggle,
.collapsible-trigger,
.panel-close,
.theme-toggle-mobile,
.theme-panel-mobile,
.trigger-switch {
  display: none;
}

@media (max-width: 760px) and (max-height: 800px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
  }
}


/* ── 移动端：手机 + iPad 竖屏 ── */
@media (max-width: 760px) {
  /* 2.1 body + app */
  body {
    height: auto;
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .panel {
    border-radius: 22px;
  }

  /* 2.2 主题 — 桌面端 dock 及 desktop 面板隐藏，改用 mobile 面板 */
  .theme-dropdown-wrap,
  .theme-toggle-desktop,
  .theme-panel-desktop {
    display: none !important;
  }

  .theme-toggle-mobile {
    display: inline-flex;
    align-items: center;
    padding: 9px 16px;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
  }

  .theme-toggle-mobile:active {
    transform: scale(0.96);
  }

  .theme-toggle-mobile.active {
    background: var(--accent-soft);
    border-color: var(--accent);
  }

  .theme-panel-mobile {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    width: auto;
    z-index: 10;
    padding: 14px;
    border: 1.5px solid var(--border);
    border-radius: 22px;
    background: var(--panel);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    gap: 10px;
  }

  .theme-panel-mobile:not([hidden]) {
    display: grid;
  }

  .theme-panel-mobile .theme-group {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }

  .theme-panel-mobile .theme-group:last-of-type {
    padding-bottom: 0;
    border-bottom: 0;
  }

  .theme-panel-mobile .theme-swatches {
    display: grid;
    grid-template-columns: repeat(3, 30px);
    gap: 7px;
    justify-content: center;
  }

  .theme-panel-mobile .theme-swatches button {
    width: 30px;
    height: 30px;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--swatch);
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s;
  }

  .theme-panel-mobile .theme-swatches button:active {
    transform: scale(0.88);
  }

  .theme-panel-mobile .theme-swatches button.active {
    border-color: var(--text);
    outline: 2.5px solid var(--accent);
    outline-offset: 3px;
  }

  .theme-panel-mobile .theme-reset {
    min-height: 36px;
    border-radius: 14px;
    background: var(--accent);
    color: #120f0d;
    font-size: 0.82rem;
    font-weight: 900;
    letter-spacing: 0.02em;
    border: 0;
    cursor: pointer;
    transition: filter 0.12s;
  }

  .theme-panel-mobile .theme-reset:active {
    filter: brightness(0.85);
  }

  /* 2.3 品牌区 */
  .brand-row {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .brand-row > div:first-child {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: clamp(1.35rem, 3vw, 2.2rem);
    letter-spacing: -0.03em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .signature-field {
    display: none !important;
  }

  /* 2.4 高级节奏型按钮 */
  .advanced-rhythm-toggle {
    display: inline-flex;
    align-items: center;
    padding: 9px 16px;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
  }

  .advanced-rhythm-toggle:active {
    transform: scale(0.96);
  }

  body[data-advanced-rhythm="true"] .advanced-rhythm-toggle {
    background: var(--accent-soft);
    border-color: var(--accent);
  }

  /* 2.5 tempo-card — flex 列布局，让 rhythm-card-wrap 可插入 */
  .tempo-card {
    display: flex;
    flex-direction: column;
    padding: 14px;
    gap: 10px;
    overflow: visible;
  }

  /* 2.6 tempo-panel */
  .tempo-panel {
    grid-template-columns: clamp(50px, 8vw, 72px) 1fr clamp(50px, 8vw, 72px);
    min-height: auto;
    gap: clamp(6px, 1.5vw, 10px);
  }

  .icon-button {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    font-size: clamp(1.8rem, 3.5vw, 2.6rem);
    border-radius: clamp(16px, 2vw, 20px);
    transition: background 0.12s, border-color 0.12s, transform 0.1s;
  }

  .icon-button:active {
    transform: scale(0.93);
    background: var(--panel-3);
  }

  .tempo-readout {
    min-height: auto;
  }

  #bpmInput {
    font-size: clamp(3.8rem, 18vw, 5.5rem);
    font-weight: 900;
    transition: color 0.15s;
  }

  .tempo-presets {
    display: none !important;
  }

  /* 2.7 visualizer ↔ rhythm-card-wrap 互斥（JS 将 rhythm-card-wrap 移入 tempo-card） */
  .beat-stage {
    min-height: clamp(130px, 32vh, 380px);
    border-radius: 26px;
  }

  .beat-stage::before {
    font-size: clamp(2.5rem, 12vw, 5rem);
  }

  .beat-count {
    font-size: clamp(5rem, 22vw, 8rem);
  }

  body[data-advanced-rhythm="true"] .visualizer {
    display: none;
  }

  /* 普通模式：rhythm-card-wrap 隐藏在 app 底部 */
  body:not([data-advanced-rhythm="true"]) .rhythm-card-wrap {
    display: none;
  }

  /* 高级模式：rhythm-card-wrap 显示在 tempo-card 内 visualizer 原位 */
  body[data-advanced-rhythm="true"] .rhythm-card-wrap {
    display: grid;
    min-height: clamp(160px, 64vw, 480px);
    max-height: 65vh;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: hidden;
  }

  body[data-advanced-rhythm="true"] .rhythm-grid {
    gap: 6px;
    overflow-x: auto;
    min-height: 0;
  }

  body[data-advanced-rhythm="true"] .rhythm-beat-bar {
    min-width: 30px;
    grid-template-rows: 24px 1fr 24px;
    gap: 5px;
  }

  body[data-advanced-rhythm="true"] .rhythm-split-button {
    height: 24px;
    border-radius: 12px;
    font-size: 0.9rem;
  }

  body[data-advanced-rhythm="true"] .rhythm-cells {
    gap: 5px;
  }

  body[data-advanced-rhythm="true"] .rhythm-cell {
    min-height: 0;
    border-radius: 10px;
  }

  body[data-advanced-rhythm="true"] .rhythm-heading .eyebrow,
  body[data-advanced-rhythm="true"] .rhythm-heading h2,
  body[data-advanced-rhythm="true"] .rhythm-enable {
    display: none;
  }

  body[data-advanced-rhythm="true"] .rhythm-heading .rhythm-tools {
    flex-wrap: wrap;
    gap: 5px;
  }

  body[data-advanced-rhythm="true"] .rhythm-reset {
    min-height: 26px;
    padding: 0 10px;
    font-size: 0.7rem;
  }

  body[data-advanced-rhythm="true"] .rhythm-help-icon {
    width: 18px;
    height: 18px;
    font-size: 0.62rem;
  }

  body[data-advanced-rhythm="true"] .rhythm-help-icon::after {
    bottom: auto;
    top: calc(100% + 8px);
  }

  /* 2.8 状态栏 */
  .status-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .status-grid > div:nth-child(3) {
    display: none;
  }

  .status-grid div {
    padding: 10px 14px;
    border-radius: 18px;
  }

  .status-grid strong {
    font-size: clamp(1.5rem, 7vw, 2.2rem);
  }

  /* 2.9 主操作 */
  .primary-actions {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
  }

  .tap-button,
  .timer-reset {
    min-height: 52px;
    font-weight: 700;
    border-radius: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.12s, transform 0.1s;
  }

  .tap-button:active,
  .timer-reset:active {
    transform: scale(0.96);
  }

  .start-button {
    min-height: 52px;
    font-size: 1.25rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    border-radius: 18px;
    transition: background 0.12s, transform 0.1s;
  }

  .start-button:active {
    transform: scale(0.96);
  }

  /* 2.10 折叠入口与面板 */
  .collapsible-trigger {
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.5vw, 12px);
    width: 100%;
    padding: clamp(14px, 2vw, 20px) clamp(16px, 2.5vw, 24px);
    border: 1.5px solid var(--border);
    border-radius: clamp(18px, 2vw, 22px);
    background: var(--panel-2);
    color: var(--text);
    font-size: clamp(0.9rem, 1.3vw, 1.05rem);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
  }

  .collapsible-trigger:active {
    transform: scale(0.985);
  }

  .collapsible-trigger:hover {
    background: var(--panel-3);
    border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  }

  .collapsible-trigger.expanded {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 6%, var(--panel-2));
  }

  .collapsible-trigger[hidden] {
    display: none !important;
  }

  .collapsible-arrow {
    margin-left: auto;
    font-size: 0.7rem;
    opacity: 0.5;
    transition: transform 0.25s ease, opacity 0.2s;
  }

  .collapsible-trigger.expanded .collapsible-arrow {
    transform: rotate(90deg);
    opacity: 0.8;
  }

  /* 面板折叠/展开 */
  .settings-card,
  .practice-card {
    display: none;
  }

  .settings-card.expanded,
  .practice-card.expanded {
    display: grid;
    padding: 18px;
  }

  /* 展开面板中隐藏标题和关闭按钮，练习模式开启开关保留 */
  .settings-card.expanded .eyebrow,
  .settings-card.expanded h2,
  .settings-card.expanded .panel-close,
  .practice-card.expanded .eyebrow,
  .practice-card.expanded h2,
  .practice-card.expanded .panel-close {
    display: none;
  }

  .practice-card.expanded .practice-heading {
    display: none;
  }

  /* 练习模式开关集成到折叠栏上 */
  .trigger-switch {
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  .collapsible-trigger .trigger-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .collapsible-trigger .trigger-switch i {
    display: block;
    width: 44px;
    height: 26px;
    border: 2px solid var(--border);
    border-radius: 999px;
    background: var(--control);
    transition: background 0.16s, border-color 0.16s;
  }

  .collapsible-trigger .trigger-switch i::before {
    content: "";
    display: block;
    width: 18px;
    height: 18px;
    margin: 2px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform 0.16s, background 0.16s;
  }

  .collapsible-trigger .trigger-switch input:checked + i {
    background: var(--accent-soft);
    border-color: var(--accent);
  }

  .collapsible-trigger .trigger-switch input:checked + i::before {
    transform: translateX(18px);
    background: var(--accent);
  }

  /* 2.11 节拍器设置卡片移动端微调 */
  .settings-card .controls {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .settings-card .field,
  .settings-card .switch {
    border-radius: 16px;
    padding: 10px 12px;
  }

  /* 2.12 练习模式卡片移动端微调 */
  .practice-modes {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .practice-modes button {
    font-size: 0.8rem;
    min-height: 42px;
    border-radius: 16px;
    font-weight: 700;
    transition: background 0.12s, border-color 0.12s, transform 0.1s;
  }

  .practice-modes button:active {
    transform: scale(0.95);
  }

  .practice-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .practice-grid .field {
    border-radius: 16px;
    padding: 10px 12px;
  }

  /* 2.13 手机端隐藏节奏型启用开关 */
  .rhythm-enable {
    display: none !important;
  }

  .rhythm-legend {
    flex-wrap: wrap;
    font-size: 0.7rem;
  }

  .rhythm-legend span {
    font-size: 0.68rem;
    padding: 4px 8px;
    border-radius: 999px;
  }

  /* 2.14 滑块微调 */
  .slider {
    margin-top: 2px;
    height: 32px;
  }
}

@media (max-width: 760px) and (max-height: 760px) {
  .app {
    padding: 8px 10px;
    gap: 8px;
  }

  .tempo-card {
    padding: 12px 14px;
    gap: 7px;
  }

  .brand-row {
    gap: 8px;
  }

  h1 {
    font-size: clamp(1.25rem, 5.5vw, 1.55rem);
    line-height: 1;
  }

  .advanced-rhythm-toggle,
  .theme-toggle-mobile {
    padding: 8px 13px;
    font-size: 0.78rem;
  }

  .tempo-panel {
    grid-template-columns: 50px 1fr 50px;
    gap: 8px;
  }

  #bpmInput {
    font-size: clamp(3.5rem, 16vw, 4.8rem);
    line-height: 0.78;
  }

  .tempo-readout span {
    font-size: 0.78rem;
    margin-bottom: 5px;
  }

  .beat-stage {
    min-height: clamp(118px, 23vh, 176px);
    border-radius: 22px;
  }

  .beat-flash {
    inset: 14px;
  }

  .beat-stage::before {
    font-size: clamp(2.2rem, 10vw, 4rem);
  }

  .beat-count {
    font-size: clamp(4.5rem, 20vw, 6.6rem);
  }

  .bar-timeline {
    min-height: 14px;
  }

  .beat-dot-cell {
    min-height: 10px;
  }

  .status-grid {
    gap: 6px;
  }

  .status-grid div {
    min-height: 54px;
    padding: 7px 12px;
    border-radius: 16px;
  }

  .status-grid strong {
    font-size: clamp(1.35rem, 6.3vw, 1.9rem);
    line-height: 1;
  }

  .primary-actions {
    gap: 7px;
  }

  .tap-button,
  .timer-reset,
  .start-button {
    min-height: 48px;
    border-radius: 16px;
    font-size: 0.92rem;
    white-space: nowrap;
  }

  .start-button {
    font-size: 1.18rem;
  }

  .collapsible-trigger {
    min-height: 46px;
    padding: 11px 16px;
    border-radius: 18px;
    white-space: nowrap;
  }

  .collapsible-label,
  .collapsible-arrow {
    white-space: nowrap;
  }

  body[data-advanced-rhythm="true"] .rhythm-card-wrap {
    min-height: clamp(136px, 54vw, 210px);
    max-height: 38vh;
  }

  body[data-advanced-rhythm="true"] .rhythm-grid {
    gap: 5px;
  }

  body[data-advanced-rhythm="true"] .rhythm-beat-bar {
    grid-template-rows: 22px 1fr 22px;
    gap: 4px;
  }

  body[data-advanced-rhythm="true"] .rhythm-split-button {
    height: 22px;
  }
}

/* Flat brutalism redesign overrides */
:root {
  color-scheme: light;
  --bg: #d9d9d9;
  --panel: #eeeeee;
  --panel-2: #ffffff;
  --panel-3: #d9d9d9;
  --text: #2b2b2b;
  --muted: #777777;
  --accent: #ccff00;
  --accent-2: #ff006e;
  --ok: #00d9ff;
  --border: #2b2b2b;
  --control: #ffffff;
  --rhythm-accent: var(--accent);
  --rhythm-secondary: color-mix(in srgb, var(--accent) 58%, var(--panel-2));
  --rhythm-light: color-mix(in srgb, var(--accent) 24%, var(--panel-2));
  --rhythm-rest: #ffffff;
  --beat-idle: #ffffff;
  --accent-soft: var(--accent);
  --accent-progress: var(--accent);
  --accent-2-progress: var(--accent-2);
  font-family: "Courier New", "Microsoft YaHei", "PingFang SC", "Segoe UI", monospace;
}

*,
*::before,
*::after {
  box-shadow: none !important;
  text-shadow: none !important;
}

body {
  background: var(--bg) !important;
  color: var(--text);
}

button,
input,
select,
.custom-select-button,
.custom-select-menu button {
  border-radius: 0 !important;
  box-shadow: none !important;
  filter: none !important;
  transition: none !important;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.custom-select-button:focus-visible,
.rhythm-help-icon:focus-visible {
  outline: 4px solid var(--text) !important;
  outline-offset: 2px;
}

button:active:not(:disabled) {
  transform: none !important;
  background: var(--text) !important;
  color: var(--panel-2) !important;
  outline: 3px solid var(--text);
  outline-offset: -6px;
}

.app {
  background: var(--bg);
}

.panel,
.theme-panel,
.theme-panel-desktop,
.theme-panel-mobile,
.tempo-card,
.settings-card,
.practice-card,
.rhythm-card-wrap,
.beat-stage,
.beat-flash,
.signature-field,
.status-grid div,
.field,
.switch,
.practice-enable,
.rhythm-enable,
.collapsible-trigger,
.custom-select-menu,
.rhythm-help-icon::after {
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--panel) !important;
  color: var(--text);
}

.tempo-card {
  background: var(--panel-2) !important;
}

.settings-card,
.practice-card,
.rhythm-card-wrap {
  background: var(--panel) !important;
}

.theme-panel-desktop,
.theme-panel-mobile {
  border-width: 3px !important;
}

.eyebrow,
.tempo-readout span,
.signature-field span,
.signature-field small,
.field span,
.switch span,
.status-grid span,
.rhythm-note,
.rhythm-help-icon {
  color: var(--muted) !important;
}

h1,
h2,
.signature-field strong,
.status-grid strong,
.beat-count,
#bpmInput {
  color: var(--text) !important;
  letter-spacing: 0 !important;
}

.tempo-readout span,
.eyebrow {
  color: var(--accent-2) !important;
}

.settings-card .field:not(.inactive) > span,
.settings-card .switch:not(.inactive) > span,
.practice-card:not(.disabled) .field:not(.inactive) > span,
.practice-card:not(.disabled) .switch:not(.inactive) > span {
  color: var(--text) !important;
  opacity: 1 !important;
}

.advanced-rhythm-toggle,
.theme-toggle,
.theme-toggle-desktop,
.theme-toggle-mobile,
.icon-button,
.tap-button,
.timer-reset,
.start-button,
.practice-modes button,
.tempo-presets button,
.practice-reset,
.rhythm-reset,
.rhythm-split-button,
.custom-select-button {
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--panel-2) !important;
  color: var(--text) !important;
  font-weight: 900;
  text-transform: uppercase;
}

.icon-button {
  position: relative !important;
  display: inline-grid !important;
  place-items: center !important;
  overflow: hidden !important;
  font-size: 0 !important;
  line-height: 0 !important;
}

#tempoDown::before,
#tempoUp::before,
#tempoUp::after {
  content: "" !important;
  position: absolute !important;
  left: 50% !important;
  top: 50% !important;
  display: block !important;
  background: currentColor !important;
  transform: translate(-50%, -50%) !important;
}

#tempoDown::before,
#tempoUp::before {
  width: 38% !important;
  height: clamp(4px, 0.42vw, 8px) !important;
}

#tempoUp::after {
  width: clamp(4px, 0.42vw, 8px) !important;
  height: 38% !important;
}

.start-button,
.theme-reset,
.practice-modes button.active,
.tempo-presets button:hover,
.advanced-rhythm-toggle:hover,
.theme-toggle:hover,
.theme-toggle-desktop:hover,
.theme-toggle-mobile:hover,
.tap-button:hover,
.timer-reset:hover,
.practice-reset:hover,
.rhythm-reset:hover,
.rhythm-split-button:hover,
.icon-button:hover,
.custom-select-button:hover,
.custom-select-button:focus {
  background: var(--accent) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

.start-button.playing,
.practice-enable input:checked + i,
.toggle-field input:checked + i,
.collapsible-trigger .trigger-switch input:checked + i {
  background: var(--accent-2) !important;
  border-color: var(--border) !important;
}

.theme-toggle-desktop::before {
  border-radius: 0 !important;
  background: var(--accent) !important;
}

.theme-swatches button,
.theme-panel-desktop .theme-swatches button,
.theme-panel-mobile .theme-swatches button {
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--swatch) !important;
  transform: none !important;
}

.theme-swatches button.active,
.theme-panel-desktop .theme-swatches button.active,
.theme-panel-mobile .theme-swatches button.active {
  outline: 4px solid var(--text) !important;
  outline-offset: 2px;
}

.theme-reset,
.theme-panel-desktop .theme-reset,
.theme-panel-mobile .theme-reset {
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--accent-2) !important;
  color: #ffffff !important;
}

.slider,
.range-field input {
  --slider-track-height: 24px;
  --slider-thumb-width: 24px;
  --slider-thumb-height: 34px;
  -webkit-appearance: none !important;
  appearance: none !important;
  height: var(--slider-track-height);
  min-height: var(--slider-track-height);
  width: calc(100% - var(--slider-thumb-width));
  margin-inline: calc(var(--slider-thumb-width) / 2);
  padding: 0;
  border: 3px solid var(--border);
  background:
    linear-gradient(
      90deg,
      var(--accent) 0 var(--range-fill, 50%),
      var(--control) var(--range-fill, 50%) 100%
    ) !important;
  accent-color: var(--accent);
}

.slider::-webkit-slider-runnable-track,
.range-field input[type="range"]::-webkit-slider-runnable-track,
.slider::-moz-range-track,
.range-field input[type="range"]::-moz-range-track {
  -webkit-appearance: none !important;
  appearance: none !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  opacity: 0 !important;
}

.slider::-moz-range-progress,
.range-field input[type="range"]::-moz-range-progress {
  appearance: none !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}

.slider::-webkit-slider-thumb,
.range-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none !important;
  appearance: none !important;
  width: var(--slider-thumb-width) !important;
  height: var(--slider-thumb-height) !important;
  margin-top: calc((var(--slider-track-height) - var(--slider-thumb-height)) / 2) !important;
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--panel-2) !important;
}

.slider::-moz-range-thumb,
.range-field input[type="range"]::-moz-range-thumb {
  appearance: none !important;
  width: var(--slider-thumb-width) !important;
  height: var(--slider-thumb-height) !important;
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--panel-2) !important;
}

.slider::-webkit-slider-runnable-track,
.range-field input[type="range"]::-webkit-slider-runnable-track {
  -webkit-appearance: none !important;
  appearance: none !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
  background:
    linear-gradient(
      90deg,
      var(--accent) 0 var(--range-fill, 50%),
      var(--control) var(--range-fill, 50%) 100%
    ) !important;
  opacity: 1 !important;
}

.slider::-moz-range-track,
.range-field input[type="range"]::-moz-range-track {
  appearance: none !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}

.slider::-moz-range-progress,
.range-field input[type="range"]::-moz-range-progress {
  appearance: none !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}

.custom-select-button,
.field select {
  background-image: none !important;
}

.custom-select-menu {
  background: var(--panel-2) !important;
}

.custom-select-menu button:hover,
.custom-select-menu button.active,
.field select:hover,
.field select:focus {
  background: var(--accent) !important;
  color: var(--text) !important;
}

.practice-enable i,
.toggle-field i,
.collapsible-trigger .trigger-switch i {
  display: flex !important;
  align-items: center !important;
  width: 48px;
  height: 28px;
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--panel-2) !important;
}

.practice-enable i::before,
.toggle-field i::before,
.collapsible-trigger .trigger-switch i::before {
  flex: 0 0 auto !important;
  width: 18px;
  height: 18px;
  margin: 0 0 0 2px !important;
  border-radius: 0 !important;
  background: var(--text) !important;
}

.practice-enable input:checked + i::before,
.toggle-field input:checked + i::before {
  transform: translateX(20px);
  background: #ffffff !important;
}

.collapsible-trigger .trigger-switch input:checked + i::before {
  transform: translateX(20px);
  background: #ffffff !important;
}

.beat-stage {
  background: var(--panel) !important;
}

.beat-stage::before {
  color: #c2c2c2 !important;
}

.beat-flash {
  background: var(--panel-2) !important;
  opacity: 1 !important;
}

.beat-dot-cell,
.rhythm-cell,
.rhythm-split-button {
  border-radius: 0 !important;
}

.beat-dot-cell {
  border: 2px solid var(--border) !important;
  background: var(--panel-2) !important;
}

.beat-dot-cell.light,
.rhythm-cell.light {
  background: var(--rhythm-light) !important;
  border-color: var(--border) !important;
}

.beat-dot-cell.secondary,
.rhythm-cell.secondary {
  background: var(--rhythm-secondary) !important;
  border-color: var(--border) !important;
}

.beat-dot-cell.accent,
.rhythm-cell.accent {
  background: var(--rhythm-accent) !important;
  border-color: var(--border) !important;
}

.beat-dot-cell.rest,
.rhythm-cell.rest {
  background: var(--panel-2) !important;
  border: 2px dashed var(--border) !important;
  opacity: 1 !important;
}

.beat-dot-cell.active,
.rhythm-cell.playing {
  outline: 4px solid var(--text) !important;
  outline-offset: -7px;
  filter: none !important;
}

.rhythm-cell.merge-before,
.rhythm-cell.merge-after,
.rhythm-cell.merge-pressing {
  outline: 4px solid var(--accent-2) !important;
  outline-offset: -7px;
  filter: none !important;
}

.rhythm-grid {
  scrollbar-color: var(--text) var(--panel);
}

.rhythm-legend span {
  border: 2px solid var(--border) !important;
  border-radius: 0 !important;
  color: var(--text) !important;
}

.rhythm-legend .light {
  background: var(--rhythm-light) !important;
}

.rhythm-legend .secondary {
  background: var(--rhythm-secondary) !important;
}

.rhythm-legend .accent {
  background: var(--rhythm-accent) !important;
  color: var(--text) !important;
}

.rhythm-legend .rest {
  background: var(--panel-2) !important;
  border-style: dashed !important;
}

.rhythm-card-wrap.disabled .rhythm-tools,
.rhythm-card-wrap.disabled .rhythm-grid,
.rhythm-card-wrap.disabled .rhythm-reset,
.field.inactive,
.switch.inactive,
.practice-card.disabled .practice-options {
  opacity: 0.46;
  filter: none !important;
}

.panel-close {
  border: 3px solid var(--border) !important;
  border-radius: 0 !important;
  background: var(--panel-2) !important;
  color: var(--text) !important;
}

@media (min-width: 761px) {
  html,
  body {
    overflow: hidden;
  }

  .app {
    grid-template-columns: minmax(260px, 0.68fr) minmax(440px, 1.48fr) minmax(300px, 0.92fr);
    gap: clamp(10px, 0.8vw, 20px);
  }

  .panel {
    border-width: 4px !important;
  }

  .tempo-card {
    grid-template-rows: auto minmax(82px, 0.34fr) auto minmax(150px, 1fr) auto auto;
  }

  .rhythm-grid {
    overflow-x: auto;
    overflow-y: hidden;
  }
}

@media (max-width: 760px) {
  body {
    background: var(--bg) !important;
  }

  .panel,
  .collapsible-trigger,
  .theme-panel-mobile {
    border-width: 3px !important;
  }

  body[data-advanced-rhythm="true"] .rhythm-enable {
    display: none !important;
  }

  body[data-advanced-rhythm="true"] .rhythm-card-wrap {
    border: 3px solid var(--border) !important;
    background: var(--panel) !important;
  }

  body[data-advanced-rhythm="true"] .rhythm-heading .eyebrow,
  body[data-advanced-rhythm="true"] .rhythm-heading h2 {
    display: block;
  }

  .settings-card.expanded,
  .practice-card.expanded {
    border: 3px solid var(--border) !important;
  }
}

/* Final UI fixes */
.eyebrow {
  display: none !important;
}

.tempo-readout span {
  color: var(--text) !important;
  font-family: "Courier New", "Microsoft YaHei", "PingFang SC", monospace;
  font-size: clamp(0.9rem, 0.9vw, 1.2rem);
  font-weight: 900;
  letter-spacing: 0 !important;
  line-height: 1;
}

.settings-card .controls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

.beat-flash.pulse {
  background: var(--rhythm-light) !important;
  border-color: var(--text) !important;
}

.beat-flash.pulse.accent {
  background: var(--rhythm-accent) !important;
}

.beat-flash.pulse.secondary {
  background: var(--rhythm-secondary) !important;
}

.beat-flash.pulse.subdivision {
  background: var(--rhythm-light) !important;
}

.beat-flash.pulse.rest {
  background: var(--panel-2) !important;
  border-style: dashed !important;
}

.rhythm-cell.playing {
  background: var(--text) !important;
  border-color: var(--text) !important;
  outline: 4px solid var(--accent) !important;
  outline-offset: -7px;
}

@media (max-width: 760px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .app,
  .tempo-card,
  .visualizer,
  .status-grid,
  .primary-actions {
    width: auto !important;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .tempo-card,
  .collapsible-trigger,
  .settings-card,
  .practice-card {
    align-self: stretch;
  }

  body[data-advanced-rhythm="true"] .rhythm-card-wrap {
    border: 0 !important;
    width: 100%;
    max-width: 100%;
    overflow: hidden !important;
  }

  body[data-advanced-rhythm="true"] .rhythm-heading {
    display: block;
  }

  body[data-advanced-rhythm="true"] .rhythm-enable {
    display: none !important;
  }

  body[data-advanced-rhythm="true"] .rhythm-heading .rhythm-tools {
    display: flex;
    width: 100%;
    max-width: 100%;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
  }

  body[data-advanced-rhythm="true"] .rhythm-legend {
    flex: 1 1 180px;
    min-width: 0;
  }

  body[data-advanced-rhythm="true"] .rhythm-reset {
    flex: 1 0 100%;
    width: 100%;
    min-width: 0;
  }

  body[data-advanced-rhythm="true"] .rhythm-grid {
    display: grid !important;
    grid-template-columns: repeat(var(--beat-count, 4), minmax(0, 1fr));
    width: 100%;
    max-width: 100%;
    gap: 6px;
    overflow: hidden !important;
  }

  body[data-advanced-rhythm="true"] .rhythm-beat-bar {
    min-width: 0;
  }

  .primary-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .primary-actions button {
    min-width: 0;
    padding-inline: 6px;
    font-size: clamp(0.75rem, 3.2vw, 0.92rem);
  }

  .theme-toggle-mobile {
    display: none !important;
  }

  .advanced-rhythm-toggle {
    position: fixed;
    top: 28px !important;
    right: auto !important;
    left: 278px !important;
    z-index: 12;
    width: 88px !important;
    min-width: 0 !important;
    max-width: 88px !important;
    padding-inline: 8px !important;
    font-size: 0.72rem !important;
    line-height: 1.1;
    white-space: normal !important;
    text-align: center;
    transform: none !important;
  }

  .slider,
  .brand-row,
  .visualizer,
  .status-grid,
  .primary-actions,
  body[data-advanced-rhythm="true"] .rhythm-card-wrap,
  body[data-advanced-rhythm="true"] .rhythm-grid {
    width: calc(100vw - 88px) !important;
    max-width: calc(100vw - 88px) !important;
  }

  .slider {
    margin-inline: 12px;
  }
}

