:root {
    color-scheme: light dark;
    /* גודל מעגל התיבה - שינוי כאן מעדכן גם את המחוג וגם את הנקודות */
    --circle-size: 150px;
    /* only the outer page background follows the theme toggle; the metronome
       body and side-controls panel keep their fixed wood/hardware look */
    --bg-page: #f1f5f9;
    --text-page: #0f172a;
    --toggle-bg: #ffffff;
    --toggle-border: #cbd5e1;
    --toggle-hover: #e2e8f0;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-page: #1a1a1a;
        --text-page: #e0e0e0;
        --toggle-bg: #262626;
        --toggle-border: #444;
        --toggle-hover: #333;
    }
}

:root[data-theme="dark"] {
    --bg-page: #1a1a1a;
    --text-page: #e0e0e0;
    --toggle-bg: #262626;
    --toggle-border: #444;
    --toggle-hover: #333;
}

body {
    background-color: var(--bg-page);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-page);
}

.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    padding: 20px;
    zoom: 0.8; /* מקטין את הכל ל-75% כדי שייכנס במסך */
}

h1 {
    margin: 0;
    font-weight: 300;
    letter-spacing: 2px;
    color: var(--text-page);
    text-shadow: 0 5px 10px rgba(0,0,0,0.5);
}

.spec-btn {
    position: fixed; top: 14px; left: 14px; z-index: 20; width: 38px; height: 38px;
    border-radius: 10px; border: 1px solid var(--toggle-border); background: var(--toggle-bg);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.spec-btn:hover { border-color: var(--toggle-hover); }
.spec-btn-core {
    width: 16px; height: 16px; border-radius: 50%;
    background: conic-gradient(from 180deg,#0f172a,#f0554c,#f5a623,#e9e04a,#67d07a,#4fb0e0,#8b7bd8,#0f172a);
    box-shadow: 0 0 0 1px rgba(255,255,255,.15) inset;
}
.spec-pop {
    position: fixed; top: 58px; left: 14px; z-index: 21; width: min(360px, calc(100vw - 28px));
    background: var(--toggle-bg); border: 1px solid var(--toggle-border); border-radius: 12px;
    padding: 14px 14px 12px; display: none; box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.spec-pop.open { display: block; }
.spec-track {
    position: relative; height: 30px; border-radius: 9px; cursor: pointer;
    box-shadow: 0 0 0 1px rgba(255,255,255,.06) inset;
}
.spec-ticks { position: relative; height: 18px; margin-top: 5px; }
.spec-tick {
    position: absolute; top: 0; transform: translateX(50%);
    font-size: 9px; color: var(--text-page);
    display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
    background: none; border: none; padding: 0; font-family: inherit; opacity: .7;
}
.spec-tick::before { content: ""; width: 1px; height: 4px; background: var(--toggle-border); }
.spec-tick:hover, .spec-tick:focus-visible { opacity: 1; }
.spec-handle {
    position: absolute; top: 50%; width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid #0b1220; box-shadow: 0 2px 6px rgba(0,0,0,.4);
    transform: translate(-50%,-50%); cursor: grab; touch-action: none;
}
.spec-handle:active { cursor: grabbing; }
.spec-readout { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 10px; }
.spec-readout-name { font-size: 14px; font-weight: 700; color: var(--text-page); }
.spec-readout-hex { font-size: 11px; color: var(--text-page); opacity: .7; font-family: ui-monospace, monospace; }
.spec-tick.active { opacity: 1; }

.main-content {
    display: flex;
    flex-direction: row;
    align-items: flex-start; /* מונע קפיצה אנכית כשהפאנל הצדדי גדל */
    justify-content: center;
    gap: 80px;
    flex-wrap: wrap;
}

.metronome {
    position: relative;
    width: 380px; 
    height: 580px; 
    filter: drop-shadow(0 35px 45px rgba(0,0,0,0.9)) drop-shadow(0 10px 15px rgba(0,0,0,0.5));
}

.body {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100%;
    /* עץ חזק ומחוספס יותר! */
    background: 
        repeating-linear-gradient(88deg, rgba(0,0,0,0.15) 0px, transparent 1px, rgba(0,0,0,0.15) 2px, transparent 5px),
        repeating-linear-gradient(92deg, rgba(0,0,0,0.1) 0px, transparent 2px, rgba(0,0,0,0.1) 3px, transparent 12px),
        repeating-linear-gradient(to right, rgba(0,0,0,0.5) 0%, transparent 12%, transparent 88%, rgba(0,0,0,0.5) 100%),
        linear-gradient(to right, #1a0500 0%, #4a1503 20%, #752504 50%, #4a1503 80%, #1a0500 100%);
    clip-path: polygon(25% 0, 75% 0, 100% 100%, 0 100%);
    border-radius: 8px 8px 15px 15px;
    display: flex;
    justify-content: center;
    box-shadow: inset 5px 0 20px rgba(255,255,255,0.05), inset -5px 0 20px rgba(0,0,0,0.9);
}

.face {
    position: absolute;
    top: 5%;
    width: 58%; 
    height: 72%;
    background: #050505;
    clip-path: polygon(8% 0, 92% 0, 100% 100%, 0 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: inset 0 15px 30px #000, inset 0 0 10px #000;
}

.face::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 40%, rgba(0,0,0,0.5) 100%);
    pointer-events: none;
    z-index: 1; 
}

.scale {
    position: relative;
    margin-top: 10%;
    width: 45%;
    height: 75%;
    border-left: 1.5px solid rgba(212, 175, 55, 0.7);
    border-right: 1.5px solid rgba(212, 175, 55, 0.7);
    z-index: 2;
}

.tick {
    position: absolute;
    color: #e5c158;
    font-size: 11px;
    font-weight: bold;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    text-shadow: 0 1px 2px #000;
}

.left-tick { right: 100%; margin-right: 6px; }
.left-tick::after {
    content: ''; position: absolute; right: -6px; width: 5px; height: 1.5px; background: #e5c158;
}

.right-tick { left: 100%; margin-left: 6px; }
.right-tick::before {
    content: ''; position: absolute; left: -6px; width: 5px; height: 1.5px; background: #e5c158;
}

.term {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(212, 175, 55, 0.9);
    font-size: 9px;
    font-family: 'Times New Roman', Times, serif;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    width: max-content;
    text-shadow: 0 1px 2px #000;
}

.brand {
    margin-top: auto;
    margin-bottom: 12px;
    color: #e5c158;
    font-family: serif;
    font-size: 11px;
    letter-spacing: 2px;
    font-weight: bold;
    text-shadow: 0 3px 5px #000;
    background: linear-gradient(to bottom, #f3e5ab, #d4af37);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    z-index: 2;
}

.base-cover {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 16%;
    background: 
        repeating-linear-gradient(85deg, rgba(0,0,0,0.15) 0px, transparent 2px, transparent 8px),
        linear-gradient(to bottom, #4a1503 0%, #1a0500 100%);
    border-top: 3px solid rgba(255,255,255,0.05);
    box-shadow: inset 0 8px 10px rgba(0,0,0,0.8), 0 -5px 15px rgba(0,0,0,0.9);
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}

.pendulum-container {
    position: absolute;
    bottom: 14%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 5;
}

.pendulum-pivot {
    position: absolute;
    bottom: -12px;
    left: -12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff, #bbb 40%, #444 80%);
    box-shadow: 0 5px 10px rgba(0,0,0,0.8), inset 0 -2px 5px rgba(0,0,0,0.5);
    border: 1px solid #222;
}

.pendulum {
    position: absolute;
    bottom: 0;
    left: -3px;
    width: 6px;
    height: 450px;
    background: linear-gradient(to right, #444, #999 30%, #fff 50%, #999 70%, #444);
    transform-origin: bottom center;
    transform: rotate(0deg);
    border-radius: 3px 3px 0 0;
    box-shadow: 5px 0 10px rgba(0,0,0,0.5);
}

.weight {
    position: absolute;
    left: -22px; 
    width: 50px;
    height: 40px;
    background: linear-gradient(to bottom, #e5c158 0%, #ffe699 20%, #b38b1f 50%, #735300 80%, #4d3d00 100%);
    border: 1px solid #332900;
    border-radius: 4px;
    box-shadow: 
        0 15px 20px rgba(0,0,0,0.7), 
        inset 0 3px 5px rgba(255,255,255,0.8),
        inset 0 -2px 3px rgba(0,0,0,0.5);
    transform: translateY(-50%);
    cursor: grab;
    transition: top 0.2s ease-out;
    touch-action: none; /* מאפשר גרירה במסך מגע בלי שהדף יגלול */
    user-select: none;
    -webkit-user-select: none;
}

.weight:hover {
    filter: brightness(1.1);
}

.weight:active {
    cursor: grabbing;
}

.weight::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 5px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), rgba(0,0,0,0.2));
    transform: translateY(-50%);
    border-top: 1px solid rgba(0,0,0,0.8);
    border-bottom: 1px solid rgba(255,255,255,0.5);
}

/* פאנל שליטה ותצוגה צדדי */
.side-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #1a1a1a;
    padding: 30px;
    border-radius: 15px;
    box-shadow: -5px 0 20px rgba(0,0,0,0.5);
    width: 320px;
    min-width: 320px;
    max-width: 320px;
    box-sizing: border-box;
    align-items: stretch;
}

.bpm-display-large {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: radial-gradient(circle at center, #222, #111);
    padding: 20px 10px;
    border-radius: 20px;
    box-shadow: 
        0 10px 20px rgba(0,0,0,0.5), 
        inset 0 2px 5px rgba(255,255,255,0.05);
    border: 1px solid #333;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
}

/* שורת הצעדים: תמיד מינוס משמאל ופלוס מימין, גם בעברית */
.bpm-row {
    display: flex;
    direction: ltr;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.bpm-step {
    position: relative;
    flex: none;
    width: 38px;
    height: 38px;
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 1;
    color: #e5c158;
    background: linear-gradient(to bottom, #2c2c2c, #1a1a1a);
    border: 1px solid #444;
    border-radius: 50%;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    box-shadow: 0 3px 6px rgba(0,0,0,0.6), inset 0 1px 1px rgba(255,255,255,0.12);
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

/* מרחיב את אזור המגע מעבר לעיגול הנראה (בגלל ה-zoom של 0.75) */
.bpm-step::before {
    content: '';
    position: absolute;
    inset: -9px;
    border-radius: 50%;
}

.bpm-step:hover:not(:disabled) {
    background: linear-gradient(to bottom, #3a3a3a, #222);
    color: #ffe699;
}

.bpm-step:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.6), inset 0 2px 4px rgba(0,0,0,0.6);
}

.bpm-step:disabled {
    opacity: 0.3;
    cursor: default;
}

/* שדה קלט שנראה כמו התצוגה הגדולה - אפשר להקליד בו טמפו ישירות */
#bpm-value {
    font-size: 5rem;
    font-weight: bold;
    color: #e5c158;
    text-shadow: 0 5px 10px rgba(0,0,0,0.8);
    line-height: 1;
    /* רוחב קבוע כדי שהכפתורים לא יזוזו במעבר בין 2 ל-3 ספרות */
    width: 3.2ch;
    text-align: center;
    font-family: inherit;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 0;
    margin: 0;
    caret-color: #e5c158;
    cursor: text;
    appearance: textfield;
    -moz-appearance: textfield;
}

#bpm-value::-webkit-outer-spin-button,
#bpm-value::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#bpm-value:focus {
    outline: none;
    border-bottom-color: rgba(229, 193, 88, 0.6);
}

/* שדה משקל חופשי (נפתח דרך "אחר...") */
.meter-custom {
    margin-top: 8px;
    padding: 8px 12px;
    width: 100%;
    box-sizing: border-box;
    font-size: 1rem;
    text-align: center;
    color: white;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
}

.meter-custom[hidden] {
    display: none;
}

.bpm-label {
    font-size: 1.2rem;
    letter-spacing: 4px;
    color: #999;
    margin-top: 5px;
}

.tempo-term-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
    padding: 8px 6px;
    background: rgba(0,0,0,0.5);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.8), 0 5px 10px rgba(0,0,0,0.5);
    width: 100%;
    box-sizing: border-box;
    min-height: 52px;
}

.term-en {
    font-size: 1.05rem;
    font-weight: bold;
    color: #e5c158;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-family: 'Times New Roman', Times, serif;
    text-shadow: 0 2px 4px rgba(0,0,0,0.9);
    text-align: center;
    white-space: nowrap;
}

.term-he {
    font-size: 0.9rem;
    color: #bbb;
    margin-top: 4px;
    text-align: center;
    letter-spacing: 1px;
}

/* מעגל התצוגה (Radar Circle) */
.measure-circle-container {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 10px 0;
    transition: opacity 0.3s ease;
}

.measure-circle-container.hidden {
    opacity: 0.2;
    pointer-events: none;
}

.measure-circle {
    position: relative;
    width: var(--circle-size);
    height: var(--circle-size);
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.1);
    background: radial-gradient(circle at center, rgba(0,0,0,0.8), rgba(0,0,0,0.3));
    box-shadow: inset 0 5px 15px rgba(0,0,0,0.9), 0 2px 5px rgba(255,255,255,0.05);
}

.circle-marker {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    background-color: #aaa;
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(255,255,255,0.3);
    margin-top: -5px;
    margin-left: -5px;
    z-index: 4;
}

.circle-marker.downbeat {
    width: 20px;
    height: 20px;
    background-color: #e74c3c;
    box-shadow: 0 0 10px #e74c3c;
    margin-top: -10px;
    margin-left: -10px;
    z-index: 5;
}

.circle-marker.flash {
    background-color: #fff !important;
    box-shadow: 0 0 15px #fff, 0 0 5px #fff inset !important;
}

.circle-marker.downbeat.flash {
    background-color: #ff9999 !important;
    box-shadow: 0 0 20px #ff9999, 0 0 10px #fff inset !important;
}

.circle-hand {
    position: absolute;
    bottom: 50%;
    left: 50%;
    width: 4px;
    height: calc(var(--circle-size) / 2 - 8px);
    background: linear-gradient(to top, rgba(229,193,88,0.2) 0%, #e5c158 100%);
    transform-origin: bottom center;
    transform: translateX(-50%) rotate(0deg);
    border-radius: 2px;
    box-shadow: 0 0 5px rgba(229,193,88,0.5);
    z-index: 2;
    /* We use JS to update the transition directly */
}


.sound-select-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    width: 100%;
}

.sound-select-wrapper label {
    font-size: 1rem;
    color: #ccc;
}

select {
    padding: 8px 12px;
    font-size: 1rem;
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    text-align: center;
}
select option {
    background: #222;
    color: white;
}

/* בורר השפה ממוקם absolute - בלי זה הוא נמתח על כל הכותרת ומסתיר אותה */
#lang-select {
    width: auto;
}

#play-btn {
    padding: 10px 40px;
    font-size: 1.4rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    background: #27ae60;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6), inset 0 2px 2px rgba(255,255,255,0.3);
    z-index: 20;
}

#play-btn:hover {
    background: #2ecc71;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.7), inset 0 2px 2px rgba(255,255,255,0.3);
}

#play-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.4);
}

#play-btn.playing {
    background: #c0392b;
}

#play-btn.playing:hover {
    background: #e74c3c;
}


/* Large Circle Mode */
body.circle-large-mode .measure-circle {
    --circle-size: min(400px, 85vw) !important;
}
body.circle-large-mode .metronome {
    transform: scale(0.3);
    transform-origin: top center;
    margin-top: 10px;
    margin-bottom: -406px;
    margin-left: -133px;
    margin-right: -133px; /* Fix layout width (380 - 380*0.3)/2 = 133 */
    /* for webkit zoom works better but scale is standard */
}
body.circle-large-mode .measure-circle-container {
    margin: 0 !important;
}
.beat-number {
    position: absolute;
    top: 50%;
    left: 50%;
    color: #111;
    font-size: 0;
    font-weight: bold;
    opacity: 0;
    transition: all 0.3s;
}
body.circle-large-mode .beat-number {
    font-size: 20px;
    opacity: 1;
}
body.circle-large-mode .circle-marker {
    width: 34px !important;
    height: 34px !important;
    margin-top: -17px !important;
    margin-left: -17px !important;
    box-shadow: 0 0 10px rgba(255,255,255,0.4);
}
body.circle-large-mode .circle-marker.downbeat {
    width: 44px !important;
    height: 44px !important;
    margin-top: -22px !important;
    margin-left: -22px !important;
    background-color: #e74c3c;
    box-shadow: 0 0 15px #e74c3c;
}
body.circle-large-mode .measure-circle-container {
    margin: 30px 0;
}

/* Make downbeat number white since it's on red background */
body.circle-large-mode .circle-marker.downbeat .beat-number {
    color: white !important;
}

/* Enlarge BPM display in large mode */



