/* ============================================================
   Piano · 五形樂器 — main.css
   Shell + 主題 + topbar + transitions + loading + settings
   ============================================================ */

:root {
    --bg: #0a0a0a;
    --bg-1: #0d0d0d;
    --bg-2: #141414;
    --bg-3: #1c1c1c;
    --line: #1f1f1f;
    --line-2: #2a2a2a;
    --text: #e8e8e8;
    --text-dim: #888;
    --text-faint: #555;

    /* 模式色 — 每個模式有自己的 accent */
    --c-piano: #d4a960;
    --c-dots: #ff7a3d;
    --c-hex: #4dd0c8;
    --c-strip: #b56dff;
    --c-chords: #ffc04d;

    --accent: var(--c-piano);
    --accent-glow: rgba(212, 169, 96, 0.4);

    --shadow-deep: 0 30px 70px rgba(0, 0, 0, 0.85);
    --shadow-key: 0 8px 14px rgba(0, 0, 0, 0.5);

    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;

    --topbar-h: 64px;
}

body[data-mode="piano"]   { --accent: var(--c-piano);  --accent-glow: rgba(212, 169, 96, 0.4); }
body[data-mode="dots"]    { --accent: var(--c-dots);   --accent-glow: rgba(255, 122, 61, 0.45); }
body[data-mode="hex"]     { --accent: var(--c-hex);    --accent-glow: rgba(77, 208, 200, 0.4); }
body[data-mode="strip"]   { --accent: var(--c-strip);  --accent-glow: rgba(181, 109, 255, 0.45); }
body[data-mode="chords"]  { --accent: var(--c-chords); --accent-glow: rgba(255, 192, 77, 0.4); }

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    transition: background 0.4s ease;
}

/* 微微的環境光跟著當前模式變色 */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at top, var(--accent-glow) 0%, transparent 55%);
    opacity: 0.05;
    pointer-events: none;
    transition: background 0.6s ease;
    z-index: 0;
}

/* ============================================================
   TOPBAR
   ============================================================ */
#topbar {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 22px;
    background: linear-gradient(to bottom, #161616 0%, #0c0c0c 100%);
    border-bottom: 1px solid #000;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
    flex-shrink: 0;
    min-height: var(--topbar-h);
    height: auto;
}

#brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    min-width: 110px;
}
#brand .logo {
    color: var(--accent);
    font-size: 24px;
    line-height: 1;
    text-shadow: 0 0 12px var(--accent-glow);
    transition: color 0.4s, text-shadow 0.4s;
}
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-text .title {
    font-size: 12px;
    letter-spacing: 5px;
    color: var(--text-dim);
    font-weight: 400;
}
.brand-text .subtitle {
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--accent);
    transition: color 0.4s;
}

/* ============================================================
   MODE SWITCHER (中央 tab bar)
   ============================================================ */
#mode-switcher {
    display: flex;
    gap: 4px;
    background: #060606;
    border: 1px solid var(--line);
    padding: 4px;
    border-radius: 12px;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    touch-action: pan-x;
}
#mode-switcher::-webkit-scrollbar { display: none; }
.mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 12px;
    letter-spacing: 2px;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    position: relative;
    flex: 0 0 auto;
}
.mode-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.mode-btn.active {
    color: #000;
    background: var(--accent);
    box-shadow: 0 0 18px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.mode-btn.active .m-icon * {
    background: #000 !important;
    border-color: #000 !important;
}
.m-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.m-text { font-weight: 500; }

/* 模式按鈕 icon */
.piano-icon { gap: 1px; align-items: flex-end; }
.piano-icon span { width: 2px; background: currentColor; }
.piano-icon span:nth-child(1) { height: 14px; }
.piano-icon span:nth-child(2) { height: 9px; }
.piano-icon span:nth-child(3) { height: 14px; }
.piano-icon span:nth-child(4) { height: 9px; }
.piano-icon span:nth-child(5) { height: 14px; }

.dots-icon { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.dots-icon span { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.hex-icon {
    width: 14px; height: 16px;
    background: currentColor;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.strip-icon {
    width: 18px; height: 3px; border-radius: 2px;
    background: linear-gradient(to right, currentColor, transparent, currentColor);
}

.chords-icon { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.chords-icon span {
    width: 6px; height: 6px; border-radius: 1px;
    background: currentColor;
    opacity: 0.5;
}
.chords-icon span:first-child { opacity: 1; }

/* ============================================================
   ACTIONS (右側按鈕)
   ============================================================ */
#actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    align-items: center;
    min-width: 0;
}
.btn {
    padding: 8px 14px;
    background: #1a1a1a;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    color: var(--text);
    font-size: 12px;
    letter-spacing: 2px;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
    -webkit-appearance: none;
    min-width: 44px;
}
.btn:active { transform: scale(0.96); }
.btn:hover { background: #222; border-color: #353535; }
.btn.ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--text-dim);
}
.btn.ghost:hover { color: var(--text); border-color: var(--line-2); background: rgba(255, 255, 255, 0.02); }
.btn.icon { padding: 8px; min-width: 36px; display: inline-flex; align-items: center; justify-content: center; }
.btn.icon-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
}
.btn.icon-text .vol-num {
    font-size: 11px;
    letter-spacing: 1px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    min-width: 22px;
    text-align: right;
}
.btn.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
}
.btn.active .vol-num { color: #000; }
.btn.muted {
    color: #ff6464;
    border-color: rgba(255, 100, 100, 0.4);
}
.btn.muted .vol-wave1, .btn.muted .vol-wave2 { display: none; }

/* 延音 ON 時加脈動，使用者一眼看出狀態 */
#btn-sustain.active {
    animation: sustainPulse 1.6s ease-in-out infinite;
}
@keyframes sustainPulse {
    0%, 100% { box-shadow: 0 0 16px var(--accent-glow); }
    50%      { box-shadow: 0 0 28px var(--accent), 0 0 12px var(--accent-glow); }
}

/* ============================================================
   VOLUME POPOVER
   ============================================================ */
#volume-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 18px;
    width: 280px;
    background: linear-gradient(to bottom, #1c1c1c 0%, #0e0e0e 100%);
    border: 1px solid var(--line-2);
    border-radius: 12px;
    padding: 16px 18px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px) scale(0.96);
    transform-origin: top right;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 60;
}
#volume-popover.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}
#volume-popover .vp-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
}
#volume-popover .vp-title {
    font-size: 11px;
    letter-spacing: 4px;
    color: var(--text-dim);
}
#volume-popover .vp-num {
    font-size: 22px;
    font-weight: 300;
    color: var(--accent);
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
}
#volume-popover .vp-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
#volume-popover .vp-quick {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    background: #181818;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 10px;
    letter-spacing: 1px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    -webkit-appearance: none;
    font-family: inherit;
}
#volume-popover .vp-quick:hover {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}
#volume-popover input[type=range] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--vol-pct, 80%), #2a2a2a var(--vol-pct, 80%), #2a2a2a 100%);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}
#volume-popover input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 2px solid var(--accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 12px var(--accent-glow);
}
#volume-popover input[type=range]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #fff;
    border: 2px solid var(--accent);
    border-radius: 50%;
    cursor: pointer;
}
#volume-popover .vp-presets {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    justify-content: space-between;
}
#volume-popover .vp-preset {
    flex: 1;
    padding: 6px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 11px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    -webkit-appearance: none;
    font-family: inherit;
}
#volume-popover .vp-preset:hover {
    background: rgba(212, 169, 96, 0.12);
    color: var(--accent);
    border-color: var(--accent);
}

/* ============================================================
   STAGE (voice bar + mode container)
   ============================================================ */
#stage {
    flex: 1;
    position: relative;
    overflow: hidden;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#mode-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
    contain: layout paint;
    will-change: opacity, transform;
    transition: opacity 0.22s ease, transform 0.22s ease, filter 0.22s ease;
}
#mode-container.fading {
    opacity: 0;
    filter: blur(6px);
    transform: scale(0.985);
}

/* ============================================================
   VOICE BAR
   ============================================================ */
#voice-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.55), rgba(0,0,0,0.25));
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #2a2a2a transparent;
    box-shadow: inset 0 -2px 8px rgba(0,0,0,0.3);
    overscroll-behavior-x: contain;
    touch-action: pan-x;
}
#voice-bar::-webkit-scrollbar { height: 4px; }
#voice-bar::-webkit-scrollbar-track { background: transparent; }
#voice-bar::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 2px; }

#voice-bar .vb-prefix {
    font-size: 10px;
    letter-spacing: 4px;
    color: var(--text-faint);
    flex-shrink: 0;
    padding-right: 4px;
    white-space: nowrap;
}

.voice-chip {
    flex-shrink: 0;
    padding: 8px 14px 7px;
    background: #161616;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text-dim);
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 96px;
    -webkit-appearance: none;
    position: relative;
    overflow: hidden;
}
.voice-chip:hover {
    background: #1f1f1f;
    border-color: var(--line-2);
    color: var(--text);
}
.voice-chip:active { transform: scale(0.97); }

.voice-chip .vc-tag {
    font-size: 8px;
    letter-spacing: 2px;
    color: var(--accent);
    opacity: 0.6;
    line-height: 1;
}
.voice-chip .vc-label {
    font-size: 13px;
    letter-spacing: 1px;
    color: var(--text);
    font-weight: 400;
    line-height: 1.1;
}
.voice-chip .vc-sub {
    font-size: 9px;
    letter-spacing: 1px;
    color: var(--text-faint);
    line-height: 1;
}

.voice-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 18px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,0.25);
}
.voice-chip.active .vc-tag,
.voice-chip.active .vc-label,
.voice-chip.active .vc-sub {
    color: #000;
    opacity: 1;
}

@media (max-width: 700px) {
    #voice-bar { padding: 8px 12px; gap: 6px; }
    #voice-bar .vb-prefix { display: none; }
    .voice-chip { min-width: 84px; padding: 6px 10px 5px; }
    .voice-chip .vc-label { font-size: 12px; }
}

/* ============================================================
   SUSTAIN OVERLAY
   ============================================================ */
#sustain-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 44px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: var(--accent);
    letter-spacing: 8px;
    font-size: 10px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-weight: 500;
    z-index: 5;
}
#sustain-overlay .dot {
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
    animation: pulse-dot 1.6s infinite;
}
#sustain-overlay .dot:last-child { animation-delay: 0.8s; }
body.sustaining #sustain-overlay { opacity: 1; }

@keyframes pulse-dot {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* ============================================================
   LOADING
   ============================================================ */
#loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(8, 8, 8, 0.96);
    color: #fff;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: opacity 0.5s ease;
}
#loading.hidden {
    opacity: 0;
    pointer-events: none;
}
#loading .brand-logo {
    font-size: 56px;
    color: var(--accent);
    text-shadow: 0 0 30px var(--accent-glow);
    margin-bottom: 8px;
    animation: rotate-slow 6s linear infinite;
}
@keyframes rotate-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
#loading .ll-label {
    font-size: 14px;
    letter-spacing: 10px;
    color: var(--accent);
    font-weight: 500;
}
#loading .ll-sublabel {
    font-size: 11px;
    letter-spacing: 4px;
    color: var(--text-dim);
}
#loading .ll-progress {
    width: 240px;
    height: 2px;
    background: var(--line);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}
#loading .ll-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(to right, var(--accent), #fff);
    box-shadow: 0 0 10px var(--accent-glow);
    transition: width 0.4s ease;
}
#loading .ll-hint {
    font-size: 10px;
    color: var(--text-faint);
    letter-spacing: 1px;
    margin-top: 14px;
}

/* ============================================================
   SETTINGS PANEL
   ============================================================ */
#settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    width: min(320px, 100vw);
    background: linear-gradient(to bottom, #141414, #080808);
    border-left: 1px solid var(--line);
    box-shadow: -20px 0 40px rgba(0, 0, 0, 0.6);
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    padding: 24px 22px;
    overflow-y: auto;
}
#settings-panel.open { transform: translateX(0); }
.sp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.sp-header h3 {
    margin: 0;
    font-size: 13px;
    letter-spacing: 6px;
    color: var(--accent);
    font-weight: 500;
}
#settings-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
    transition: color 0.15s;
}
#settings-close:hover { color: var(--text); }

.sp-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}
.sp-row label {
    font-size: 12px;
    letter-spacing: 2px;
    color: var(--text-dim);
    width: 60px;
    flex-shrink: 0;
}
.sp-row input[type=range] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--line-2);
    border-radius: 2px;
    outline: none;
}
.sp-row input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
}
.sp-row input[type=range]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}
.sp-value {
    width: 32px;
    text-align: right;
    font-size: 11px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.sp-section {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}
.sp-section-title {
    font-size: 10px;
    letter-spacing: 4px;
    color: var(--text-faint);
    margin-bottom: 10px;
}
.sp-text {
    font-size: 12px;
    color: var(--text-dim);
    margin: 4px 0;
    line-height: 1.5;
}
.sp-text-dim {
    font-size: 10px;
    color: var(--text-faint);
    margin: 2px 0;
}

#settings-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 49;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
#settings-backdrop.open { opacity: 1; pointer-events: auto; }

/* ============================================================
   響應式
   ============================================================ */
@media (max-width: 900px) {
    #topbar { padding: 10px 14px; gap: 10px; }
    #brand { min-width: 0; }
    .brand-text { display: none; }
    #brand .logo { font-size: 22px; }
    .mode-btn { padding: 7px 10px; }
    .m-text { display: none; }
    .btn { padding: 7px 10px; min-width: 36px; }
    #actions .btn[id="btn-labels"],
    #actions .btn[id="btn-sustain"] { font-size: 11px; letter-spacing: 1px; padding: 7px 10px; }
}
@media (max-width: 600px) {
    #mode-switcher { padding: 3px; gap: 2px; }
    .mode-btn { padding: 6px 8px; }
    .m-icon { width: 16px; height: 16px; }
    #actions { gap: 5px; }
    .btn { padding: 7px 8px; min-width: 34px; }
    .btn.icon-text { padding: 7px 8px; }
    .btn.icon-text .vol-num { display: none; }
    #volume-popover {
        right: 10px;
        width: min(280px, calc(100vw - 20px));
    }
}

@media (max-height: 520px) {
    :root { --topbar-h: 54px; }
    #topbar { padding: 7px 12px; gap: 8px; }
    #voice-bar { padding: 6px 12px; }
    .voice-chip { padding: 6px 10px 5px; min-width: 82px; }
    .voice-chip .vc-label { font-size: 12px; }
}

/* iOS PWA safe area */
@supports (padding: env(safe-area-inset-top)) {
    #topbar {
        min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
        padding-top: calc(12px + env(safe-area-inset-top, 0));
        padding-left: max(22px, env(safe-area-inset-left, 0));
        padding-right: max(22px, env(safe-area-inset-right, 0));
    }
    #stage { padding-bottom: env(safe-area-inset-bottom, 0); }

    @media (max-width: 900px) {
        #topbar {
            padding-top: calc(10px + env(safe-area-inset-top, 0));
            padding-left: max(14px, env(safe-area-inset-left, 0));
            padding-right: max(14px, env(safe-area-inset-right, 0));
        }
    }

    @media (max-width: 600px) {
        #topbar {
            padding-left: max(10px, env(safe-area-inset-left, 0));
            padding-right: max(10px, env(safe-area-inset-right, 0));
        }
    }

    @media (max-height: 520px) {
        #topbar { padding-top: calc(7px + env(safe-area-inset-top, 0)); }
    }
}

@media (hover: none) {
    .mode-btn:not(.active):hover { color: var(--text-dim); background: transparent; }
    .btn.ghost:not(.active):hover { color: var(--text-dim); border-color: var(--line); background: transparent; }
    .voice-chip:not(.active):hover { color: var(--text-dim); background: #161616; border-color: var(--line); }
}

/* ============================================================
   FULLSCREEN BUTTON
   ============================================================ */
#btn-fullscreen .fs-exit { display: none; }
body.is-fullscreen #btn-fullscreen .fs-enter { display: none; }
body.is-fullscreen #btn-fullscreen .fs-exit { display: block; }

/* ============================================================
   TOPBAR HANDLE (fullscreen: reveal topbar)
   ============================================================ */
#topbar-handle {
    display: none;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    width: 80px;
    height: 24px;
    align-items: flex-end;
    justify-content: center;
    cursor: pointer;
    padding-bottom: 6px;
    -webkit-tap-highlight-color: transparent;
}
#topbar-handle .handle-line {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 2px;
    transition: background 0.15s, width 0.15s;
}
#topbar-handle:hover .handle-line,
#topbar-handle:active .handle-line {
    background: rgba(255, 255, 255, 0.5);
    width: 48px;
}

/* ============================================================
   FULLSCREEN MODE
   ============================================================ */
body.is-fullscreen #topbar {
    transition: transform 0.3s ease, opacity 0.3s ease;
}
body.is-fullscreen.topbar-hidden #topbar {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
body.is-fullscreen #topbar-handle {
    display: flex;
}
body.is-fullscreen:not(.topbar-hidden) #topbar-handle {
    display: none;
}
body.is-fullscreen #sustain-overlay {
    bottom: 80px;
}

/* ============================================================
   TABLET BAR (bottom mode switcher for touch tablets)
   ============================================================ */
#tablet-bar {
    display: none;
}

.tb-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 14px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text-dim);
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    min-width: 52px;
    min-height: 44px;
}
.tb-mode .m-icon { width: 20px; height: 20px; }
.tb-mode .m-icon * { transition: background 0.15s, border-color 0.15s; }
.tb-mode:active { transform: scale(0.93); }
.tb-mode.active {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.06);
}
.tb-mode.active .m-icon * {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
}
.tb-mode.active .hex-icon {
    background: var(--accent) !important;
}
.tb-mode.active .strip-icon {
    background: linear-gradient(to right, var(--accent), transparent, var(--accent)) !important;
}

.tb-label {
    font-size: 9px;
    letter-spacing: 1.5px;
    line-height: 1;
}

.tb-sep {
    width: 1px;
    height: 28px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 8px;
    flex-shrink: 0;
}

.tb-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 11px;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
}
.tb-action:active { transform: scale(0.93); }
.tb-action.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    box-shadow: 0 0 14px var(--accent-glow);
}
#tb-sustain.active {
    animation: sustainPulse 1.6s ease-in-out infinite;
}
.tb-action .fs-exit { display: none; }
body.is-fullscreen .tb-action .fs-enter { display: none; }
body.is-fullscreen .tb-action .fs-exit { display: block; }

/* ============================================================
   TABLET MODE (touch screens >= 768px)
   ============================================================ */
@media (min-width: 768px) and (pointer: coarse) {
    #tablet-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        height: 72px;
        padding: 0 20px;
        padding-bottom: env(safe-area-inset-bottom, 0);
        background: linear-gradient(to top, rgba(8, 8, 8, 0.97), rgba(12, 12, 12, 0.92));
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        border-top: 1px solid rgba(255, 255, 255, 0.06);
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.5);
    }

    #mode-switcher { display: none; }

    #topbar {
        min-height: 50px;
        padding: 8px 16px;
        gap: 12px;
    }
    .brand-text { display: none; }
    #brand .logo { font-size: 20px; }

    .btn { min-width: 44px; min-height: 44px; }
    .btn.icon { padding: 10px; }

    #voice-bar {
        padding: 8px 14px;
        gap: 6px;
    }
    .voice-chip {
        min-width: 80px;
        padding: 6px 10px 5px;
    }

    #stage {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0));
    }

    .mode-piano .piano-nav {
        padding-bottom: 20px;
    }
    .mode-chords .chord-bottom-hint,
    .mode-dots .dots-info,
    .mode-hex .hex-info,
    .mode-strip .strip-bottom-hint {
        bottom: 10px;
    }

    #sustain-overlay {
        bottom: 72px;
    }

    body.is-fullscreen #tablet-bar {
        background: linear-gradient(to top, rgba(8, 8, 8, 0.85), rgba(12, 12, 12, 0.6));
        border-radius: 16px 16px 0 0;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: auto;
        min-width: 420px;
        max-width: 90%;
        padding: 0 24px;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    body.is-fullscreen #stage {
        padding-bottom: 0;
    }
    body.is-fullscreen #sustain-overlay {
        bottom: 80px;
    }
}

@media (min-width: 1024px) and (pointer: coarse) {
    #tablet-bar { gap: 8px; height: 68px; }
    .tb-mode { padding: 8px 18px; min-width: 60px; }
    .tb-label { font-size: 10px; }

    .voice-chip { min-width: 96px; }
}

@supports (padding: env(safe-area-inset-bottom)) {
    @media (min-width: 768px) and (pointer: coarse) {
        #tablet-bar {
            padding-bottom: max(8px, env(safe-area-inset-bottom, 0));
        }
    }
}
