/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --teal: #1a7a6d;
    --teal-dark: #145f55;
    --teal-light: #e6f5f2;
    --amber: #e8a838;
    --amber-light: #fdf3e0;
    --amber-glow: #f5c563;
    --charcoal: #2d2d2d;
    --slate: #5a6872;
    --light-grey: #f4f5f7;
    --white: #ffffff;
    --border: #dde1e5;
    --gold: #c9952c;
    --silver: #8a9bae;
    --bronze: #b07340;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    color: var(--charcoal);
    background-color: var(--light-grey);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 {
    font-family: 'Playfair Display', Georgia, serif;
}

/* ===== Confetti Canvas ===== */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

/* ===== Toast Notifications ===== */
#toast-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: var(--charcoal);
    color: var(--white);
    padding: 0.7rem 1.2rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.35s ease-out, toast-out 0.35s ease-in 2.6s forwards;
    text-align: center;
    line-height: 1.4;
}

.toast .toast-icon {
    margin-right: 0.4rem;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ===== Header ===== */
header {
    background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
    color: var(--white);
    padding: 2rem 1.5rem 1.8rem;
    text-align: center;
}

header h1 {
    font-size: 2.4rem;
    letter-spacing: 0.02em;
    margin-bottom: 0.6rem;
}

.definition {
    max-width: 520px;
    margin: 0 auto;
    text-align: left;
    font-size: 0.88rem;
    opacity: 0.92;
    line-height: 1.55;
}

.phonetic {
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
    font-size: 1rem;
    margin-bottom: 0.2rem;
    opacity: 0.8;
}

.part-of-speech {
    margin-bottom: 0.4rem;
    font-size: 0.82rem;
    opacity: 0.7;
}

.meanings {
    padding-left: 1.2rem;
    margin-bottom: 0.6rem;
}

.meanings li {
    margin-bottom: 0.25rem;
}

.origin {
    font-size: 0.8rem;
    opacity: 0.7;
    border-top: 1px solid rgba(255,255,255,0.2);
    padding-top: 0.5rem;
    margin-top: 0.3rem;
}

/* ===== Main ===== */
main {
    flex: 1;
    max-width: 540px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem 2rem;
}

/* ===== Record Section ===== */
.record-section {
    text-align: center;
    padding: 1.5rem 0 1rem;
}

.prompt-text {
    font-size: 1rem;
    color: var(--slate);
    margin-bottom: 1rem;
    font-weight: 500;
}

.big-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    border: 4px solid var(--amber);
    background: linear-gradient(145deg, var(--amber) 0%, var(--amber-glow) 100%);
    color: var(--charcoal);
    cursor: pointer;
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    box-shadow: 0 6px 24px rgba(232,168,56,0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    -webkit-user-select: none;
    user-select: none;
    position: relative;
    overflow: hidden;
}

.big-btn:active {
    transform: scale(0.93);
    box-shadow: 0 2px 8px rgba(232,168,56,0.25);
}

.big-btn .btn-icon {
    font-size: 2.2rem;
    margin-bottom: 0.15rem;
    line-height: 1;
}

.big-btn .btn-text {
    font-size: 1.05rem;
    letter-spacing: 0.04em;
}

/* Button press animation */
.big-btn.pressed {
    animation: pulse-ring 0.6s ease-out;
}

@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(232,168,56,0.6); }
    100% { box-shadow: 0 0 0 50px rgba(232,168,56,0); }
}

/* Counter bounce */
#total-count {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 3rem;
    font-weight: 700;
    color: var(--teal);
    line-height: 1;
    display: inline-block;
    transition: transform 0.15s ease;
}

#total-count.bump {
    animation: count-bump 0.35s ease;
}

@keyframes count-bump {
    0% { transform: scale(1); }
    40% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.counter {
    margin-top: 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.counter-label {
    font-size: 0.85rem;
    color: var(--slate);
    margin-top: 0.15rem;
}

/* ===== Notes Section ===== */
.notes-section {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-top: 1rem;
    box-shadow: var(--shadow);
    animation: slide-down 0.25s ease-out;
}

@keyframes slide-down {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.notes-section.hidden {
    display: none;
}

.notes-section h2 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--teal);
}

.notes-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#note-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

#note-input:focus {
    outline: none;
    border-color: var(--teal);
}

.btn-save {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--teal);
    color: var(--white);
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.btn-save:active {
    background: var(--teal-dark);
}

.notes-hint {
    font-size: 0.75rem;
    color: var(--slate);
    margin-top: 0.4rem;
    text-align: center;
}

.btn-link {
    background: none;
    border: none;
    color: var(--slate);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.75rem;
    font-family: inherit;
    padding: 0;
}

.btn-link:active {
    color: var(--charcoal);
}

/* ===== Milestones / Achievements ===== */
.milestones-section {
    margin-top: 2rem;
}

.milestones-section h2 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    color: var(--charcoal);
}

.milestones-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
}

.milestone {
    background: var(--white);
    border-radius: var(--radius);
    padding: 0.75rem;
    box-shadow: var(--shadow);
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.milestone.locked {
    opacity: 0.45;
    filter: grayscale(1);
}

.milestone.unlocked {
    border: 2px solid var(--amber);
}

.milestone.just-unlocked {
    animation: milestone-pop 0.5s ease-out;
}

@keyframes milestone-pop {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); opacity: 1; }
}

.milestone-icon {
    font-size: 1.8rem;
    line-height: 1;
    margin-bottom: 0.3rem;
}

.milestone-name {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--charcoal);
    margin-bottom: 0.15rem;
}

.milestone-desc {
    font-size: 0.72rem;
    color: var(--slate);
    line-height: 1.3;
}

.milestone-progress {
    margin-top: 0.4rem;
    height: 4px;
    background: var(--light-grey);
    border-radius: 2px;
    overflow: hidden;
}

.milestone-progress-bar {
    height: 100%;
    background: var(--teal);
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ===== Chart Section ===== */
.chart-section {
    margin-top: 2rem;
}

.chart-section h2 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    color: var(--charcoal);
}

.chart-container {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    position: relative;
    min-height: 180px;
}

#usage-chart {
    width: 100%;
    height: 160px;
    display: block;
}

.chart-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--slate);
    font-size: 0.88rem;
    font-style: italic;
}

.chart-empty.hidden {
    display: none;
}

/* ===== Leaderboard ===== */
.leaderboard-section {
    margin-top: 2rem;
}

.leaderboard-section h2 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    color: var(--charcoal);
}

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.leader-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--white);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    box-shadow: var(--shadow);
}

.leader-rank {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--white);
    flex-shrink: 0;
}

.leader-rank.gold { background: var(--gold); }
.leader-rank.silver { background: var(--silver); }

.leader-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
}

.leader-name .you-tag {
    font-size: 0.72rem;
    font-weight: 500;
    background: var(--teal-light);
    color: var(--teal);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.leader-score {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--teal);
}

/* ===== History ===== */
.history-section {
    margin-top: 2rem;
    padding-bottom: 1rem;
}

.history-section h2 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    color: var(--charcoal);
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.history-item {
    background: var(--white);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
}

.history-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--amber);
    flex-shrink: 0;
    margin-top: 0.35rem;
}

.history-content {
    flex: 1;
    min-width: 0;
}

.history-date {
    font-size: 0.78rem;
    color: var(--slate);
}

.history-note {
    font-size: 0.88rem;
    color: var(--charcoal);
    margin-top: 0.15rem;
    word-break: break-word;
}

.history-empty {
    text-align: center;
    color: var(--slate);
    font-size: 0.88rem;
    font-style: italic;
    padding: 1.5rem 0;
}

.history-empty.hidden {
    display: none;
}

/* ===== Footer ===== */
footer {
    background: var(--teal-dark);
    color: var(--white);
    text-align: center;
    padding: 1rem;
    margin-top: auto;
    font-size: 0.82rem;
    opacity: 0.9;
}

/* ===== Utility ===== */
.hidden {
    display: none !important;
}

/* ===== Responsive ===== */
@media (min-width: 600px) {
    header {
        padding: 2.5rem 2rem 2rem;
    }

    header h1 {
        font-size: 3rem;
    }

    .big-btn {
        width: 200px;
        height: 200px;
    }

    .big-btn .btn-text {
        font-size: 1.15rem;
    }

    main {
        padding: 2rem 1.5rem 3rem;
    }
}
