/* ==========================================================================
   Calm Meter — sleeping bear reacts to classroom noise
   ========================================================================== */

/* Fill the viewport like the bouncy-balls tool (kill the base 70vh gap) */
.tool-page-wrapper:has(.nm) { min-height: 0 !important; }
.tool-content-area:has(.nm) { min-height: 0 !important; }

.nm {
    --nm-radius: 18px;
    --nm-ink: #2b2118;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 95vh;
    flex: 1;
    background: #1c160f;
    color: #fff;
    overflow: hidden;
}

/* ----- Scene (cave + bear) ----- */
.nm__scene {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #14100b;
    overflow: hidden;
}

/* The cave fills the whole scene edge-to-edge (no letterboxing) */
.nm__cave {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-image: var(--nm-cave);
    background-size: cover;       /* fill the area, crop the overflow */
    background-position: center;
    z-index: 1;
}

/* gentle vignette so the bear pops */
.nm__cave::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 58%, transparent 42%, rgba(0,0,0,0.30) 100%);
    pointer-events: none;
}

.nm__stage {
    position: absolute;
    bottom: 11%;
    left: 50%;
    transform: translateX(-50%);
    height: 50%;                  /* smaller bear, sits in the cave mouth */
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 2;
}

.nm__bear {
    height: 100%;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 14px 18px rgba(0,0,0,0.40));
    will-change: transform;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* the bear "breathes" while calm, gives a subtle wobble when furious */
.nm.is-calm .nm__bear { animation: nm-breathe 4.6s ease-in-out infinite; }
.nm.is-furious .nm__bear { animation: nm-shake 0.9s ease-in-out infinite; }

@keyframes nm-breathe {
    0%, 100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-0.5%) scale(1.006); }
}
@keyframes nm-shake {
    0%, 100% { transform: rotate(-0.8deg); }
    50%      { transform: rotate(0.8deg); }
}

/* ----- Floating Z's (calm) ----- */
.nm__zzz {
    position: absolute;
    top: 4%;
    inset-inline-end: 14%;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}
.nm.is-calm .nm__zzz { opacity: 1; }
.nm__zzz span {
    position: absolute;
    font-family: inherit;
    font-weight: 700;
    color: #bfe9ef;
    text-shadow: 0 2px 6px rgba(0,0,0,0.4);
    opacity: 0;
    animation: nm-float 3.6s ease-in infinite;
}
.nm__zzz span:nth-child(1){ font-size: 1.2rem;  animation-delay: 0s;   }
.nm__zzz span:nth-child(2){ font-size: 1.7rem;  animation-delay: 1.2s; }
.nm__zzz span:nth-child(3){ font-size: 2.3rem;  animation-delay: 2.4s; }
@keyframes nm-float {
    0%   { transform: translate(0, 10px) rotate(-8deg); opacity: 0; }
    30%  { opacity: 1; }
    100% { transform: translate(38px, -90px) rotate(8deg); opacity: 0; }
}

/* ----- Anger sparks (loud) ----- */
.nm__spark {
    position: absolute;
    top: 6%;
    inset-inline-start: 16%;
    z-index: 3;
    display: flex;
    gap: 0.5rem;
    color: #ffd23f;
    font-size: 1.6rem;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
    text-shadow: 0 0 10px rgba(255, 120, 0, 0.7);
}
.nm.is-furious .nm__spark { opacity: 1; animation: nm-spark 0.4s steps(2) infinite; }
.nm__spark .bi-exclamation-lg { color: #ff5252; font-size: 2.1rem; }
@keyframes nm-spark {
    0%, 100% { transform: scale(1) rotate(-4deg); }
    50%      { transform: scale(1.18) rotate(4deg); }
}

/* ----- Mood badge ----- */
.nm__mood {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    padding: 0.4rem 1.1rem;
    border-radius: 999px;
    font-family: inherit;
    font-weight: 700;
    font-size: clamp(0.9rem, 2.2vw, 1.25rem);
    letter-spacing: 0.01em;
    color: #2b2118;
    background: rgba(255,255,255,0.92);
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    white-space: nowrap;
    transition: background 0.4s ease, color 0.4s ease;
}

/* ----- Vertical meter ----- */
.nm__meter {
    position: absolute;
    inset-inline-end: clamp(12px, 3vw, 34px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    height: 62%;
}
.nm__meter-track {
    position: relative;
    flex: 1;
    width: clamp(16px, 3.2vw, 26px);
    border-radius: 999px;
    background: rgba(0,0,0,0.45);
    border: 2px solid rgba(255,255,255,0.25);
    overflow: hidden;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}
.nm__meter-fill {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 0%;
    border-radius: 999px;
    background: linear-gradient(to top, #38d39f 0%, #b6e34a 45%, #ffd23f 70%, #ff8a3d 86%, #ff4b4b 100%);
    transition: height 0.09s linear;
}
.nm__meter-thresh {
    position: absolute;
    left: -4px;
    right: -4px;
    bottom: 75%;
    height: 3px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
    border-radius: 2px;
}
.nm__meter-thresh::after {
    content: '';
    position: absolute;
    inset-inline-end: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-inline-end: 3px;
    border: 5px solid transparent;
    border-inline-start-color: #fff;
}
.nm__meter-val {
    font-family: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.7);
    min-width: 3ch;
    text-align: center;
}

/* ----- Too-loud alarm banner ----- */
.nm__alarm {
    position: absolute;
    top: 64px;
    left: 50%;
    transform: translate(-50%, -12px);
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 999px;
    background: #ff4b4b;
    color: #fff;
    font-family: inherit;
    font-weight: 700;
    font-size: clamp(0.85rem, 2vw, 1.05rem);
    box-shadow: 0 8px 24px rgba(255, 50, 50, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.nm.is-alarm .nm__alarm {
    opacity: 1;
    transform: translate(-50%, 0);
}
.nm.is-alarm .nm__cave::after {
    background: radial-gradient(ellipse at 50% 55%, transparent 30%, rgba(255,0,0,0.30) 100%);
    animation: nm-redflash 0.6s ease-in-out infinite;
}
@keyframes nm-redflash {
    0%, 100% { opacity: 0.55; }
    50%      { opacity: 1; }
}

/* ----- Start overlay ----- */
.nm__overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(15, 11, 7, 0.66);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transition: opacity 0.3s ease;
}
.nm__overlay.is-hidden {
    opacity: 0;
    pointer-events: none;
}
.nm__overlay-card {
    max-width: 420px;
    width: 100%;
    text-align: center;
    background: #fff;
    color: var(--nm-ink);
    border-radius: var(--nm-radius);
    padding: 2rem 1.75rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.nm__overlay-icon {
    width: 70px; height: 70px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; color: #fff;
    background: linear-gradient(135deg, #15aebf 0%, #4ecdc4 100%);
    box-shadow: 0 8px 20px rgba(21,174,191,0.4);
}
.nm__overlay-title {
    font-family: inherit;
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
}
.nm__overlay-text {
    font-size: 0.98rem;
    line-height: 1.6;
    color: #5b5147;
    margin: 0 0 1.5rem;
}
.nm__big-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.85rem 2rem;
    border: none;
    border-radius: 999px;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, #15aebf 0%, #4ecdc4 100%);
    box-shadow: 0 6px 18px rgba(21,174,191,0.4);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.nm__big-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(21,174,191,0.5);
}
.nm__big-btn:active { transform: translateY(0); }
.nm__overlay-note {
    margin: 1rem 0 0;
    font-size: 0.85rem;
    color: #d23b3b;
    min-height: 1em;
}

/* ----- Top-left timer stack ----- */
.nm__timers {
    position: absolute;
    top: 16px;
    inset-inline-start: 16px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

/* Elapsed stopwatch (counts up) */
.nm__elapsed {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.9rem;
    border-radius: 14px;
    background: rgba(43, 33, 24, 0.78);
    color: #ffe9b8;
    font-family: inherit;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.nm__elapsed .bi { font-size: 1.05rem; color: #ffd23f; }
.nm__elapsed-time {
    font-weight: 800;
    font-size: clamp(1rem, 2.4vw, 1.35rem);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

/* ----- Goal countdown badge ----- */
.nm__goal {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.9rem;
    border-radius: 14px;
    background: rgba(21, 174, 191, 0.92);
    color: #fff;
    font-family: inherit;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: background 0.3s ease;
}
.nm__goal .bi { font-size: 1.05rem; }
.nm__goal-time {
    font-weight: 800;
    font-size: clamp(1rem, 2.4vw, 1.35rem);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}
.nm__goal-hint {
    font-weight: 600;
    font-size: 0.72rem;
    opacity: 0.92;
    border-inline-start: 1px solid rgba(255,255,255,0.4);
    padding-inline-start: 0.45rem;
}
.nm__goal.is-paused { background: rgba(214, 59, 59, 0.94); }

/* ----- Goal achieved celebration modal ----- */
.nm__overlay--goal { background: rgba(15, 11, 7, 0.72); }
.nm__goal-card {
    position: relative;
    max-width: 440px;
    width: 100%;
    text-align: center;
    background: #f1f0ee;
    color: var(--nm-ink);
    border-radius: 22px;
    padding: 2.5rem 2rem 2rem;
    box-shadow: 0 24px 70px rgba(0,0,0,0.55);
    animation: nm-pop 0.4s cubic-bezier(0.2, 1.3, 0.5, 1) both;
}
@keyframes nm-pop {
    0%   { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.nm__goal-close {
    position: absolute;
    top: 14px;
    inset-inline-end: 14px;
    width: 34px; height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #8a8178;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.nm__goal-close:hover { background: rgba(0,0,0,0.07); color: #4a443d; }
.nm__goal-img {
    width: 230px;
    max-width: 70%;
    margin: 0 auto 1.25rem;
    background: #fff;
    border-radius: 16px;
    padding: 0.75rem;
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
}
.nm__goal-img img { width: 100%; height: auto; display: block; }
.nm__goal-title {
    font-family: inherit;
    font-size: clamp(1.6rem, 5vw, 2.2rem);
    font-weight: 800;
    color: #f5b829;
    margin: 0 0 0.6rem;
}
.nm__goal-text {
    font-size: 1.05rem;
    line-height: 1.55;
    color: #6a6258;
    margin: 0 0 1.5rem;
}

/* "Goal missed" variant — gentle, not celebratory */
.nm__overlay--goal.is-failed .nm__goal-title { color: #e07a6b; }
.nm__overlay--goal.is-failed .nm__big-btn {
    background: #e07a6b;
    box-shadow: 0 8px 20px rgba(224, 122, 107, 0.4);
}

/* ----- Goal setup control ----- */
.nm__control-group--goal { max-width: 320px; flex-basis: 220px; }
.nm__goal-set {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}
.nm__select {
    flex: 0 0 auto;
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.08);
    color: #f0e8db;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.nm__select option { color: #2b2118; }
.nm__select:disabled { opacity: 0.5; cursor: not-allowed; }
.nm__goal-set .nm__btn { flex: 1 1 auto; justify-content: center; }

/* ----- Controls bar ----- */
.nm__controls {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    padding: 0.75rem 1rem;
    background: #2a2118;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.nm__controls-spacer { flex: 1 1 0; min-width: 0; }
.nm__control-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 150px;
    flex: 1 1 160px;
    max-width: 280px;
}
.nm__control-group label {
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    color: #d8cdbf;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.nm__control-group label .bi { color: #4ecdc4; }
.nm__control-group input[type="range"] {
    width: 100%;
    accent-color: #15aebf;
    cursor: pointer;
}
.nm__btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.nm__btn:active { transform: translateY(1px); }
.nm__btn:disabled { opacity: 0.5; cursor: not-allowed; }
.nm__btn--primary {
    background: linear-gradient(135deg, #15aebf 0%, #4ecdc4 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(21,174,191,0.35);
}
.nm__btn--primary:hover:not(:disabled) { transform: translateY(-1px); }
.nm__btn--ghost {
    background: rgba(255,255,255,0.08);
    color: #e7ddcf;
    border: 1px solid rgba(255,255,255,0.15);
}
.nm__btn--ghost:hover { background: rgba(255,255,255,0.16); }

/* round-ish icon-only reset button (sits next to the main button) */
.nm__btn--reset {
    background: rgba(255,255,255,0.08);
    color: #e7ddcf;
    border: 1px solid rgba(255,255,255,0.15);
    padding: 0.55rem;
    width: 42px;
    justify-content: center;
}
.nm__btn--reset:hover { background: rgba(255,255,255,0.16); }
.nm__btn--reset .bi { font-size: 1.15rem; }
.nm__btn--reset[hidden] { display: none; }
.nm__btn--ghost[aria-pressed="false"] { opacity: 0.55; }
.nm__btn--ghost[aria-pressed="false"] .bi::before { content: "\F2E1"; } /* volume-mute */

/* Keep centered text centered in RTL languages too.
   base.html applies `.rtl * { text-align: start }` to every element in
   Arabic/Kurdish; these higher-specificity rules (.nm .x) win it back. */
.nm .nm__overlay-card,
.nm .nm__overlay-title,
.nm .nm__overlay-text,
.nm .nm__overlay-note,
.nm .nm__goal-card,
.nm .nm__goal-title,
.nm .nm__goal-text,
.nm .nm__mood,
.nm .nm__alarm,
.nm .nm__meter-val,
.nm .nm__goal-time,
.nm .nm__goal-hint,
.nm .nm__elapsed-time {
    text-align: center;
}

/* ----- Responsive ----- */
@media (max-width: 600px) {
    .nm__stage { height: 44%; bottom: 12%; }
    .nm__meter { height: 56%; inset-inline-end: 8px; }
    .nm__controls { gap: 0.6rem 0.9rem; padding: 0.6rem 0.75rem; }
    .nm__control-group { min-width: 120px; flex-basis: 120px; }
    .nm__btn span { display: none; }
    .nm__overlay-card { padding: 1.5rem 1.25rem; }
    .nm__timers { top: 10px; inset-inline-start: 10px; gap: 0.35rem; }
    .nm__elapsed, .nm__goal { padding: 0.35rem 0.7rem; }
    .nm__goal-hint { display: none; }
    .nm__control-group--goal { flex-basis: 100%; max-width: none; }
    .nm__goal-set .nm__btn span { display: inline; }
    .nm__controls-spacer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .nm__bear, .nm__zzz span, .nm__spark,
    .nm.is-alarm .nm__cave::after { animation: none !important; }
    .nm__bear { transition: none; }
}
