/* ==========================================================================
   COMMON STYLES FOR ALL PAGES
   ========================================================================== */

/* 14 CATEGORIES OF FONT SIZES 
   All units are in rem.
   Font-weight: normal or bold
*/
:root {

    color-scheme: only light;

    /* 1. Page Headings */
    --fs-h1-first: 3rem;
    --fw-h1-first: normal;

    --fs-h1-sub: 1.5rem;
    --fw-h1-sub: normal;

    --fs-h1-second: 2rem;
    --fw-h1-second: normal;

    /* 2. Open Labels (Labels, "Enter Name", "Language:") */
    --fs-label: 1.1rem;
    --fw-label: normal;

    /* 3. Main Buttons (Instructions, Results, Navigation, Keyboard Toggle) */
    --fs-btn-main: 0.9rem;
    --fw-btn-main: normal;

    /* 4. Menus (Select inputs) */
    --fs-menu: 0.9rem;
    --fw-menu: normal;

    /* 5. Date Digits (Input fields) */
    --fs-date-input: 1rem;
    --fw-date-input: normal;

    /* 6. Info & Result Body Text */
    --fs-body-text: 1rem;
    --fw-body-text: normal;

    /* 7. Info & Result Headings */
    --fs-result-heading: 1.1rem;
    --fw-result-heading: bold;

    /* 8. Index Input Area (The main typing box) */
    --fs-input-area: 1rem;
    --fw-input-area: bold;

    /* 9. Keyboard Buttons (Standard & Large) */
    --fs-keyboard-std: 0.9rem;
    --fw-keyboard-std: normal;

    --fs-keyboard-lg: 1.3rem;
    --fw-keyboard-lg: normal;

    /* 10. Calendar & Controls */
    --fs-calendar-text: 0.9rem;
    --fw-calendar-text: normal;

    --fs-control-service: 0.8rem;
    --fw-control-service: normal;

    /* 11. Error Messages */
    --fs-error: 0.8rem;
    --fw-error: normal;

    /* Global Settings */
    --btnArrow: rgb(130, 140, 140);
    --btnDark: rgb(135, 155, 155);
    --btnNorma: rgb(150, 170, 170);
    --btnLight: rgb(170, 190, 190);
    --btnSelected: rgb(10, 90, 90);

    /* Letter colouring (index.html, tandem.html) */
    --vowel-color:     rgb(110, 50, 40);
    --consonant-color: rgb(40, 80, 120);

    /* CN/JP suggestion buttons (index.html, tandem.html) */
    --sugg-font-size:       1.0rem;
    --sugg-font-size-large: calc(var(--sugg-font-size) * 1.5);
    --sugg-btn-w1:          1.8em;
    --sugg-btn-w2:          2.8em;
    --sugg-btn-padding:     5px;
    --sugg-gap:                   1px;
    --sugg-min-height:      0.5rem;

    --actual-font: 'Book Antiqua';
    --actual-font-fallback: 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
    --actual-weight: normal;
}

/* Default font loaded immediately via CSS.
   All other fonts are loaded on demand via the FontFace API in common-scripts.js. */

/* ==========================================================================
   GLOBAL STYLES
   ========================================================================== */

* {forced-color-adjust: none !important;}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    margin: 10px;
    font-family: var(--actual-font), var(--actual-font-fallback);
    background-color: rgb(130, 160, 165) !important; /* rgb(130, 160, 165) rgb(165, 160, 130) */
    color: black;
}

/* Default text alignment */
body * {
    text-align: center;
}

/* Alignment Exceptions */
select,
select option {
    text-align: left;
}

#info-container p,
#results-container p,
#results-container li,
.result-content {
    text-align: justify;
}

body.font-override {
    font-family: var(--actual-font), var(--actual-font-fallback) !important;
}

* {
    font-family: var(--actual-font), var(--actual-font-fallback);
    box-sizing: border-box;
}

input,
select,
textarea,
button {
    font-family: var(--actual-font), var(--actual-font-fallback);
}

/* === 1. Headings === */
.first-heading {
    font-size: var(--fs-h1-first);
    font-weight: var(--fw-h1-first);
    line-height: 1.2;
    color: rgb(30, 20, 30);
    margin-bottom: 0px;
}

.sub-heading {
    font-size: var(--fs-h1-sub);
    font-weight: var(--fw-h1-sub);
    line-height: 1.2;
    color: rgb(30, 20, 30);
    margin-bottom: 15px;
}

.second-heading {
    font-size: var(--fs-h1-second);
    font-weight: var(--fw-h1-second);
    line-height: 1.2;
    color: rgb(30, 20, 30);
    margin-bottom: 20px;
}

/* === 2. Labels === */
.input-label,
.language-selector label,
#selector-label,
#feedback-container span {
    font-size: var(--fs-label);
    font-weight: var(--fw-label);
    line-height: 1.2;
    color: black;
    margin-bottom: 5px;
}

/* === 3. Main Buttons === */
button {
    font-size: var(--fs-btn-main);
    font-weight: var(--fw-btn-main);
    margin: 0 5px;
    padding: 10px;
    width: 80px;
    height: 40px;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: darkgrey;
    color: black;
    cursor: pointer;
    border: none;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    line-height: 1;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

/* Standard Desktop Sizes for Main Buttons */
#info-Btn,
#results-Btn {
    width: 180px;
    height: 40px;
    margin: 10px 0;
    background-color: var(--btnDark);
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.large-button {
    font-size: var(--fs-btn-main);
    font-weight: var(--fw-btn-main);
    width: 200px;
    height: 40px;
    margin: 5px 0;
    background-color: var(--btnDark);/* rgb(130, 150, 150) */
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    color: black;
}

/* === 4. Menus === */
.language-selector select,
#page-language-select,
#font-selector,
#font-weight-selector,
#name-language-select {
    font-size: var(--fs-menu);
    font-weight: var(--fw-menu);
    padding: 5px;
    border-radius: 0;
    background-color: var(--btnLight);
    border: 1px solid black;
}

/* === 5. Date Digits === */
.digit-input {
    font-size: var(--fs-date-input);
    font-weight: var(--fw-date-input);
    width: 30px;
    height: 30px;
    background-color: var(--btnLight);
    border: 1px solid black;
    padding: 0;
    border-radius: 0;
    direction: ltr !important;
}

.digit-input::placeholder {
    color: rgb(140, 165, 165);
    opacity: 1;
}

/* === 6. & 7. Info & Results === */
#info-container h3,
#results-container h3 {
    font-size: var(--fs-result-heading);
    font-weight: var(--fw-result-heading);
    margin: 1em 0;
}

.result-content {
    font-size: var(--fs-body-text);
    font-weight: var(--fw-body-text);
    white-space: pre-wrap;
    word-wrap: break-word;
    hyphens: auto;
    tab-size: 8;
    -moz-tab-size: 8;
    margin-bottom: 15px;
}

/* === 8. Index Input Area === */
#input-area {
    font-size: var(--fs-input-area);
    font-weight: var(--fw-input-area);
}

/* === 10. Calendar & Controls Base === */
.calendar button,
.year-buttons button,
.result-buttons button {
    font-size: var(--fs-calendar-text);
    font-weight: var(--fw-calendar-text);
}

.calendar-header {
    font-size: var(--fs-result-heading);
    font-weight: var(--fw-result-heading);
}

.arrow-button,
.nav-arrow {
    font-size: var(--fs-control-service);
    font-weight: var(--fw-control-service);
}

/* === 11. Errors === */
.date-error {
    font-size: var(--fs-error);
    font-weight: var(--fw-error);
    color: rgb(120, 60, 60);
    margin: 5px 0;
    display: none;
}

/* === Layout Structure === */
.date-input-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 10px;
    width: 100%;
}

.date-input-row {
    display: flex;
    gap: 5px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    direction: ltr !important;
}

/* Dots in date fields */
.date-input-row span {
    font-size: var(--fs-date-input);
    font-weight: var(--fw-date-input);
}

#info-container,
#results-container {
    width: 600px;
    max-width: 95%;
    margin: 10px 0;
}

.language-selector {
    margin: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.language-selector option:checked,
#font-selector option:checked,
#font-weight-selector option:checked {
    background-color: var(--btnNorma) !important;
}

/* === Button States === */
button:active {
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.3);
    transform: translateY(2px);
}

button:disabled {
    opacity: 0.5;
    cursor: default;
}

button:focus {
    outline: none;
    box-shadow: none;
}

#toggle-name-btn:focus {
    outline: 3px solid rgba(0, 128, 255, 0.8);
    box-shadow: 0 0 5px rgba(0, 128, 255, 0.6);
}

#feedback-send-btn:focus,
#feedback-clear-btn:focus,
#feedback-close-btn:focus {
    outline: none;
    box-shadow: none;
}

.digit-input:focus {
    outline: 3px solid rgba(0, 128, 255, 0.8);
    box-shadow: 0 0 5px rgba(0, 128, 255, 0.6);
}

body.no-date-focus .digit-input:focus {
    outline: none;
    box-shadow: none;
}

#input-area:focus {
    outline: none;
    box-shadow: none;
}

a {
    text-decoration: none;
}

/* === Lists === */
#results-container ul {
    list-style-type: none;
    padding: 0;
    margin: 10px 0 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#results-container li {
    text-indent: 0;
    margin: 0;
}

/* ==========================================================================
   RTL SUPPORT
   ========================================================================== */
body.rtl {
    direction: rtl;
}

body.rtl select,
body.rtl .language-selector select,
body.rtl #page-language-select,
body.rtl #font-selector,
body.rtl #font-weight-selector,
body.rtl #name-language-select,
body.rtl option {
    direction: rtl !important;
    text-align: right !important;
}

body.rtl #info-container p:not(.terms-text),
body.rtl #results-container p:not(.terms-text),
body.rtl #results-container li:not(.terms-text),
body.rtl .result-content {
    text-align: justify;
    direction: rtl;
}

body.rtl #results-container ul {
    direction: rtl;
    padding-right: 20px;
    padding-left: 0;
}

/* ==========================================================================
   ADAPTIVE / MOBILE
   ========================================================================== */
@media (max-width: 640px) {
    /* Increase Typography by ~1.5x for readability on mobile */
    :root {
        --fs-label: 1.5rem;
        --fs-btn-main: 1.35rem;
        --fs-menu: 1.3rem;
        --fs-date-input: 1.5rem;
        --fs-body-text: 1.4rem;
        --fs-result-heading: 1.5rem;
        --fs-input-area: 1.5rem;
        --fs-error: 1.1rem;
        --fs-calendar-text: 1.2rem;
        --fs-control-service: 1.4rem;
        --fs-keyboard-std: 1.2rem;
        --fs-keyboard-lg: 1.8rem;

        /* CN/JP suggestion buttons — mobile overrides */
        --sugg-font-size:   1.3rem;
        --sugg-btn-padding: 8px;
        --sugg-gap:         3px;
        --sugg-btn-w1:      1.8em;
        --sugg-btn-w2:      3.0em;
    }

    #suggestions button { height: auto !important; min-height: 36px !important; padding: var(--sugg-btn-padding) 5px !important; }
    #suggestions button.syllable,
    #suggestions button.btn-double { padding: var(--sugg-btn-padding) 0 !important; }
    body.keyboard-large #keyboard button:not(.keyboard-button) { font-size: 2.0rem !important; }
    #keyboard button  { height: 46px !important; }
    #input-controls button { height: 36px; font-size: 1rem !important; }
    .date-digit-input { width: 13vw; max-width: 50px; height: 50px; }

    body {
        margin: 0;
        /* Padding to ensure text doesn't touch screen edges */
        padding: 10px 15px;
        width: 100%;
        box-sizing: border-box;
    }

    /* Fixed 1.5x Sizing for Main Buttons */
    /* Desktop was ~200px width. Mobile is 300px. */
    /* Desktop was 40px height. Mobile is 60px. */

    #info-Btn,
    #results-Btn,
    .large-button,
    #toggle-keyboard-btn,
    #day-characteristic-btn,
    #month-characteristic-btn,
    #year-characteristic-btn,
    #compatibility-btn,
    #aboutnumero-btn,
    #feedback-btn {
        width: 300px !important;
        max-width: 100%; /* Safety cap */
        height: 60px !important;
    }

    /* Menus 1.5x width approx */
    #page-language-select,
    #font-selector,
    #font-weight-selector,
    #name-language-select {
        width: 300px;
        max-width: 100%;
        height: 55px;
    }

    .date-input-row {
        gap: 5px;
        max-width: 100%;
    }

    .digit-input {
        width: 13vw;
        max-width: 50px;
        height: 50px;
    }

    #info-container,
    #results-container {
        width: 100%;
        padding: 0;
        box-sizing: border-box;
    }

    #results-container p,
    #results-container li,
    .hyphenate {
        hyphens: auto;
        -webkit-hyphens: auto;
        word-wrap: break-word;
        overflow-wrap: break-word;
        text-align: justify;
    }

    body.rtl .result-content,
    body.rtl .previous-years p,
    body.rtl #results-container p,
    body.rtl #results-container li {
        direction: rtl !important;
        text-align: right !important;
    }
}

/* ==========================================================================
   FONT SELECTOR - каждая опция отображается своим шрифтом
   Назначение font-family опциям выполняется динамически через JS
   в функции initializeFontSelector() / toggleSelectorMode() из common-scripts.js
   ========================================================================== */

#font-selector,
#font-selector option {
    font-weight: normal !important;
}

/* ==========================================================================
   INDEX & TANDEM SHARED STYLES
   (keyboard, suggestions, input controls, letter colouring)
   ========================================================================== */

/* Letter colouring */
.vowel        { color: var(--vowel-color); }
.consonant    { color: var(--consonant-color); }
.mismatch     { color: gray !important; }
.unrecognized { color: rgb(40, 140, 60) !important; }

/* Active state for Format / Memory / Color toggle buttons */
button.button-active {
    background-color: rgb(140, 150, 150) !important;
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* Date digit inputs (tandem creates these with class date-digit-input only;
   index uses digit-input date-digit-input so both classes must work) */
.date-digit-input {
    font-size: var(--fs-date-input);
    font-weight: var(--fw-date-input);
    width: 30px; height: 30px;
    background-color: var(--btnLight);
    border: 1px solid black;
    padding: 0; border-radius: 0;
    text-align: center;
    direction: ltr !important;
    box-sizing: border-box;
}
.date-digit-input::placeholder { color: rgb(140, 165, 165); opacity: 1; }
.date-digit-input:focus { outline: none; box-shadow: none; }

/* Input controls row (Format / Memory / Color buttons) */
#input-controls {
    display: flex; justify-content: center; align-items: center;
    margin: 5px 0; direction: ltr !important;
}
#input-controls button {
    height: 28px;
    font-size: var(--fs-control-service);
    background-color: var(--btnArrow);
}

/* Keyboard toggle button */
#toggle-keyboard-btn {
    margin-top: 10px; height: 35px; width: 240px;
    background-color: var(--btnArrow);
}
#toggle-keyboard-placement-top,
#toggle-keyboard-placement-bottom { display: flex; justify-content: center; width: 100%; }

/* Keyboard area */
#keyboard-area {
    display: none; width: 100%;
    flex-direction: column; align-items: center; justify-content: center;
}
#keyboard { margin-top: 5px; display: flex; flex-direction: column; align-items: center; }
#keyboard button { width: 38px; height: 32px; margin: 3px; }
#keyboard button:not(.keyboard-button) { font-size: var(--fs-keyboard-std); }
body.keyboard-large #keyboard button:not(.keyboard-button) { font-size: var(--fs-keyboard-lg); }
#keyboard button.keyboard-button { font-size: var(--fs-btn-main); }

.keyboard-button { width: 80px; white-space: nowrap !important; }

.keyboard-button-letter {
    box-sizing: border-box;
    align-items: center !important; justify-content: center !important;
    line-height: 1 !important; display: inline-flex !important;
    white-space: nowrap !important;
    padding: 0.30em 0.1em !important;
    background-color: rgb(190, 190, 190) !important;
}
.keyboard-button-letter span { display: inline !important; margin-top: 0; }

.row { display: flex; justify-content: center; margin-bottom: 1.0px; }
body.rtl #keyboard, body.rtl .row { direction: ltr !important; }

/* JP section bar */
#jp-section-bar {
    display: none; justify-content: center; gap: 5px;
    margin-bottom: 4px; width: 100%;
}
#jp-section-bar button {
    width: auto; min-width: 80px; height: 28px; padding: 0 10px;
    font-size: var(--fs-control-service);
    background-color: var(--btnLight); border: 1px solid rgba(0, 0, 0, 0.3);
}
#jp-section-bar button.jp-section-active {
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.4); transform: translateY(1px);
}
#jp-section-bar button:disabled { opacity: 0.35; cursor: default; }

/* CN/JP suggestion buttons */
#suggestions {
    display: flex; flex-wrap: wrap; gap: var(--sugg-gap);
    margin-top: 0.5rem; margin-bottom: 5px;
    max-width: 600px; justify-content: center;
    min-height: var(--sugg-min-height); align-content: flex-start;
}
#suggestions button {
    padding: var(--sugg-btn-padding) 5px;
    font-size: var(--sugg-font-size);
    background-color: lightblue;
    border: 1px solid #ccc; border-radius: 3px;
    flex: 0 0 auto; width: auto; height: auto; min-width: 0;
    margin: var(--sugg-gap);
}
#suggestions button.syllable-key { width: auto; }
#suggestions button.syllable     { width: var(--sugg-btn-w1); padding: var(--sugg-btn-padding) 0; }
#suggestions button.btn-double   { width: var(--sugg-btn-w2); padding: var(--sugg-btn-padding) 0; }
body.keyboard-large #suggestions button            { font-size: var(--sugg-font-size-large); }
body.keyboard-large #suggestions button.syllable   { font-size: var(--sugg-font-size-large); width: var(--sugg-btn-w1); }
body.keyboard-large #suggestions button.btn-double { font-size: var(--sugg-font-size-large); width: var(--sugg-btn-w2); }