:root {
    --base-font: clamp(16px, 4.5vw, 19px);
    --primary-btn: #6c5ce7;
    --remove-btn: #e17055;
    --bg-start: #cfcaf1;
    --bg-end: #cfcaf1;
    --container-bg: #ffffff;
    --text-color: #333333;
    --input-bg: #ffffff;
    --input-border: #cccccc;
    --input-text: #000000;
    --suggestion-bg: #dfe6e9;
    --average-bg: #ffffff;
    --average-border: #6c5ce7;
    --shadow: rgba(0, 0, 0, 0.15);
    color-scheme: light;
    /* Respectă tema sistemului pentru scrollbar/săgeți */
}

:root.dark-theme {
    --bg-start: #1f1b38;
    --bg-end: #1f1b38;
    --container-bg: #1e1e1e;
    --text-color: #f1f2f6;
    --input-bg: #2d2d2d;
    --input-border: #444444;
    --input-text: #ffffff;
    --suggestion-bg: #3d3d3d;
    --average-bg: #252525;
    --shadow: rgba(0, 0, 0, 0.5);
    color-scheme: dark;
    /* Aceasta face săgețile de la input să fie albe pe dark mode */
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;

    /* NEW: disable text selection */
    -webkit-user-select: none;
    user-select: none;

    /* NEW: disable long-press callout (copy menu) */
    -webkit-touch-callout: none;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-start), var(--bg-end)) fixed;
    color: var(--text-color);
    margin: 0;
    padding: calc(1rem + (0.9 * env(safe-area-inset-top, 0px))) 0.6rem calc(1.5rem + env(safe-area-inset-bottom, 0px)) 0.6rem;
    display: flex;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 500px;
    background: var(--container-bg);
    padding: 1.5rem;
    border-radius: 1.2rem;
    box-shadow: 0 0.6rem 1.5rem var(--shadow);
}

h1 {
    text-align: center;
    font-size: 1.6rem;
    margin-bottom: 1.5rem;
}

/* --- CARD MATERIE --- */
.subject-wrapper {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 600px;
    opacity: 1;
    overflow: hidden;
    margin-bottom: 1.2rem;
}

.subject-wrapper.removing {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    margin-top: 0;
    transform: scaleY(0);
    pointer-events: none;
}

.subject-card {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 1rem;
    padding: 1rem;

}

.subject-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
}

.subject-title-input {
    flex: 1;
    font-weight: bold;
    font-size: 1rem;
    border: none;
    border-bottom: 2px solid var(--primary-btn);
    background: transparent;
    color: var(--text-color);
    outline: none;
    padding: 5px 0;
}

.remove-btn {
    background: none;
    border: none;
    color: var(--remove-btn);
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
}

/* --- GRILA NOTE --- */
.grades-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.grade-item {
    position: relative;
    display: flex;
    align-items: center;
}

.grade-input {
    width: 100%;
    padding: 0.6rem;
    border-radius: 0.6rem;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-text);
    text-align: center;
    font-size: 1rem;
    outline: none;
}

/* Butonul de ștergere notă - STANGA SUS */
.remove-grade-btn {
    position: absolute;
    top: -6px;
    left: -6px;
    background: var(--remove-btn);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 2;
    transition: transform 0.2s;
}

.remove-grade-btn:active {
    transform: scale(0.8);
}

.add-grade-btn {
    background: var(--suggestion-bg);
    color: var(--text-color);
    border: 1px dashed var(--input-border);
    border-radius: 0.6rem;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
}

/* --- FOOTER CARD --- */
.subject-footer {
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--input-border);
    padding-top: 0.7rem;
    font-size: 0.9rem;
}

.partial-average {
    font-weight: bold;
    color: var(--primary-btn);
}

/* --- BUTOANE PRINCIPALE & ACTIONS --- */
.add-btn {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 10px;
    border-radius: 0.8rem;
    background: var(--primary-btn);
    color: white;
    border: none;
    cursor: pointer;
}

.actions-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 10px;
}

.clear-all-btn {
    flex: 1;
    padding: 0.8rem;
    background: transparent;
    color: var(--remove-btn);
    border: 1.5px solid var(--remove-btn);
    border-radius: 0.8rem;
    cursor: pointer;
    font-weight: bold;
}

.undo-btn {
    background: var(--suggestion-bg);
    border: 1px solid var(--input-border);
    color: var(--text-color);
    padding: 0.8rem 1.2rem;
    border-radius: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
}

/* --- AFIȘARE MEDIE FINALĂ (Sticky) --- */
.average {
    position: sticky;
    /* Adunăm 1rem la spațiul sigur de jos al telefonului */
    bottom: calc(1rem + env(safe-area-inset-bottom));
    margin-top: 2rem;
    text-align: center;
    padding: 1.2rem;
    border-radius: 1rem;
    background: var(--average-bg);
    border: 2.5px solid var(--average-border);
    z-index: 100;
    box-shadow: 0 8px 20px var(--shadow);
    backdrop-filter: blur(5px);
}

#average {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-btn);
    transition: transform 0.1s;
    display: inline-block;
}

.average-label {
    font-size: 1.1rem;
    display: block;
    margin-bottom: 0.2rem;
}

/* --- SUGESTII --- */
.common-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 10px;
}

.common-item {
    background: var(--suggestion-bg);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    cursor: pointer;
    font-size: 0.9rem;
}

/* --- MODE TOGGLE --- */
.mode-toggle-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 0.5rem;
    background: var(--container-bg);
    border-radius: 0.8rem;
}

.toggle-label {
    font-weight: bold;
    font-size: 0.9rem;
}

.toggle-switch {
    position: relative;
    width: 140px;
    height: 34px;
}

.toggle-switch input {
    display: none;
}

.toggle-switch label {
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--input-border);
    border-radius: 17px;
    cursor: pointer;
    width: 100%;
    height: 100%;
    position: relative;
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-color);
}

.toggle-handle {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 68px;
    height: 30px;
    background: var(--primary-btn);
    border-radius: 15px;
    transition: transform 0.3s ease;
    z-index: 1;
}

.toggle-switch input:checked+label .toggle-handle {
    transform: translateX(68px);
}

.toggle-text-left,
.toggle-text-right {
    z-index: 2;
    transition: color 0.3s;
}

.toggle-switch input:checked+label .toggle-text-left {
    color: var(--text-color);
}

.toggle-switch input:checked+label .toggle-text-right {
    color: white;
}

.toggle-switch input:not(:checked)+label .toggle-text-left {
    color: white;
}

/* Utilitare pentru schimbare mod */
body.mode-single-avg .grades-container {
    display: none;
}

body.mode-single-avg .subject-footer span:first-child {
    display: none;
}

body:not(.mode-single-avg) .single-avg-input {
    display: none;
}

.single-avg-input {
    width: 100%;
    padding: 0.8rem;
    border-radius: 0.6rem;
    border: 2px solid var(--primary-btn);
    background: var(--input-bg);
    color: var(--input-text);
    text-align: center;
    font-size: 1.1rem;
    font-weight: bold;
}

/* Adaugă această regulă în style.css */

.avg-details {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.9rem;
}

.rounded-wrapper {
    font-weight: bold;
    color: var(--text-color);
}

.rounded-average {
    background: var(--primary-btn);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 4px;
}

/* Ne asigurăm că footer-ul rămâne ascuns în modul "Medie" conform cerinței anterioare */
body.mode-single-avg .subject-footer {
    display: none;
}