/* ===========================
   General Styling
   =========================== */
:root {
    --line-height: 40px;
    --columns: 3;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Atkinson Hyperlegible Mono', sans-serif;
    font-size: 18px;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    color: #333333;
}

/* ===========================
   Navigation
   =========================== */
nav {
    background-color: #0056b3;
    padding: 10px 20px;
    text-align: left;
}

nav a {
    color: white;
    text-decoration: none;
    font-size: 16px;
    font-weight: bold;
    transition: color 0.3s ease;
}

nav a:hover {
    color: #ffeb3b;
}

/* ===========================
   Header
   =========================== */
header {
    background-color: #007bff;
    color: white;
    padding: 20px 0;
    text-align: center;
    width: 100%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
    margin: 0;
    font-size: 32px;
    font-weight: bold;
}

header p {
    margin: 10px 0 0 0;
    font-size: 16px;
    font-style: italic;
}

/* ===========================
   Footer
   =========================== */
footer {
    font-size: 14px;
    color: #666666;
    margin: 20px 0;
    text-align: center;
}

/* ===========================
   Container & Layout
   =========================== */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

.controls-section {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.print-notice {
    background-color: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 6px;
    padding: 10px 16px;
    margin-bottom: 25px;
    font-size: 13px;
    color: #5d4037;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 200px;
}

.control-group label {
    font-weight: bold;
    font-size: 14px;
    color: #333333;
}

.control-group select {
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid #cccccc;
    border-radius: 5px;
    font-family: 'Atkinson Hyperlegible Mono', sans-serif;
    background-color: white;
    cursor: pointer;
}

.control-group select:hover {
    border-color: #007bff;
}

.control-group select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.control-group input[type="range"] {
    width: 100%;
    padding: 0;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]:hover::-webkit-slider-thumb {
    background: #0056b3;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    padding: 10px 30px;
    font-size: 16px;
    font-weight: bold;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Atkinson Hyperlegible Mono', sans-serif;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.btn-primary:hover {
    background-color: #0056b3;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-primary:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

/* ===========================
   Practice Container
   =========================== */
.practice-container {
    display: grid;
    grid-template-columns: repeat(var(--columns, 3), 1fr);
    gap: 25px;
}

/* ===========================
   Word Section
   =========================== */
.word-section {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    page-break-inside: avoid;
}

.word-header {
    background-color: #f5f5f5;
    padding: 15px 20px;
    border-bottom: 2px solid #cccccc;
    font-size: 18px;
    font-weight: bold;
    color: #333333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.word-label {
    color: #666666;
    font-size: 14px;
    font-weight: normal;
}

.word-text {
    color: #007bff;
    font-size: 20px;
    font-weight: bold;
}

.lines-container {
    padding: 10px 20px 0 20px;
    background-color: #faf5f0;
    display: flex;
    flex-direction: column;
    gap: 0;
    counter-reset: line-counter;
}

/* Closing dotted line after all practice lines */
.lines-container::after {
    content: '';
    display: block;
    height: 2px;
    margin-bottom: 10px;
    background-image: repeating-linear-gradient(
        90deg,
        #8b7d6b 0px, #8b7d6b 4px,
        transparent 4px, transparent 8px
    );
    background-size: 100% 2px;
    background-repeat: no-repeat;
}

/* ===========================
   Practice Lines (Notebook Style)
   Each div = one writing unit.
   Pattern: dotted (top edge) → gap → blue → gap → blue → gap
   The next div's dotted continues right after, giving:
   dotted → gap → blue → gap → blue → gap → dotted → gap → ...
   The ::after on .lines-container adds the final closing dotted.
   =========================== */
.practice-line {
    height: var(--line-height);
    position: relative;
    counter-increment: line-counter;
    /* Equal gaps: gap = (line-height - 6px) / 3
       Layout: dotted(2px) | gap | blue(2px) | gap | blue(2px) | gap */
    --gap: calc((var(--line-height) - 6px) / 3);
    background-image:
        /* Dotted line at top edge */
        repeating-linear-gradient(
            90deg,
            #8b7d6b 0px, #8b7d6b 4px,
            transparent 4px, transparent 8px
        ),
        /* Blue line 1: starts after dotted(2px) + one gap */
        linear-gradient(to bottom,
            transparent calc(2px + var(--gap)),
            #4a90e2     calc(2px + var(--gap)),
            #4a90e2     calc(4px + var(--gap)),
            transparent calc(4px + var(--gap))
        ),
        /* Blue line 2: starts after dotted(2px) + blue1(2px) + two gaps */
        linear-gradient(to bottom,
            transparent calc(4px + 2 * var(--gap)),
            #4a90e2     calc(4px + 2 * var(--gap)),
            #4a90e2     calc(6px + 2 * var(--gap)),
            transparent calc(6px + 2 * var(--gap))
        );
    background-size: 100% 2px, 100% 100%, 100% 100%;
    background-position: 0 0, 0 0, 0 0;
    background-repeat: no-repeat, no-repeat, no-repeat;
}

/* Line number centered between the two blue lines */
.practice-line::before {
    content: counter(line-counter);
    position: absolute;
    /* center of gap2 = 4px + gap + gap/2 = 4px + 1.5*gap */
    top: calc(4px + var(--gap) + var(--gap) / 2);
    transform: translateY(-50%);
    left: 6px;
    font-size: 9px;
    line-height: 1;
    color: #a0b8d8;
    font-family: 'Atkinson Hyperlegible Mono', sans-serif;
    z-index: 1;
}

.line-margin {
    display: none;
}

.line-content {
    flex: 1;
    position: relative;
}

/* ===========================
   Print Styles
   =========================== */
@media print {
    body {
        background-color: white;
        margin: 0;
        padding: 0;
    }

    header {
        width: 100%;
        margin: 0;
        padding: 15px 0;
        font-size: 18px;
    }

    header h1 {
        font-size: 24px;
        margin: 0;
    }

    header p {
        display: block;
    }

    header p::after {
        content: ' — Liste ' attr(data-list);
    }

    .container {
        max-width: 100%;
        padding: 0.5in;
        margin: 0;
    }

    .controls-section {
        display: none;
    }

    .print-notice {
        display: none;
    }

    .word-section {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #e0e0e0;
        margin-bottom: 20px;
    }

    .word-header {
        background-color: #f9f9f9;
        border-bottom: 1px solid #cccccc;
        padding: 12px 15px;
        font-size: 16px;
    }

    .lines-container {
        padding: 10px 15px;
        background-color: #faf5f0;
    }

    .practice-line {
        --line-height: 30px;
        height: var(--line-height);
    }

    /* Ensure consistent page breaks */
    @page {
        margin: 0.5in;
        size: A4;
    }
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    header h1 {
        font-size: 24px;
    }

    .controls-section {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        min-width: 100%;
    }

    .btn-primary {
        width: 100%;
    }

    .word-header {
        font-size: 16px;
    }

    .word-text {
        font-size: 18px;
    }

    .practice-line {
        --line-height: 28px;
        height: var(--line-height);
    }
        width: 20px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    header {
        padding: 15px 5px;
    }

    header h1 {
        font-size: 20px;
    }

    .controls-section {
        padding: 15px;
        gap: 10px;
    }

    .practice-line {
        --line-height: 26px;
        height: var(--line-height);
    }
        padding: 10px;
    }
}
