html,
body {
    width: 100%;
    min-width: 100%;
    overflow-x: hidden;
}

:root {
    --card-width: clamp(70px, 11vw, 100px);
    --card-height: 130px;
    --card-gap: 20px;
    --border-radius: 12px;
    --main-bg-color: #f0f2f5;
    --card-bg-color: #ffffff;
    --primary-color: #007bff;
    --primary-hover-color: #0056b3;
    --phoneme-color: #d9534f;
    --gray-color: #adb5bd;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--card-bg-color);
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.site-header {
    padding: 12px 0;
    background-color: #0a2f59;
    color: #ffffff;
    box-sizing: border-box;
    width: 100vw;
    max-width: 100%;
    min-width: 100%;
    align-self: stretch;
}

.site-header-inner {
    max-width: 1024px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.site-logo {
    height: 32px;
    width: auto;
    display: block;
}

.site-title {
    font-family: 'Montserrat', 'Segoe UI Black', 'Arial Black', 'Helvetica Neue', Arial, sans-serif;
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.site-title .vowel {
    color: #ff3b30;
}

.site-title-card {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 3px;
    margin-right: 0;
    background: transparent;
    color: #ffffff;
    border: 2px solid #ffffff;
    border-radius: 8px;
    line-height: 1;
}

.site-footer {
    padding: 8px 0;
    background-color: #0a2f59;
    color: #ffffff;
    box-sizing: border-box;
    width: 100vw;
    max-width: 100%;
    min-width: 100%;
    align-self: stretch;
    margin-top: auto;
}

.site-footer-inner {
    max-width: 1024px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
}

.orientation-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 47, 89, 0.65);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #ffffff;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 999;
    box-sizing: border-box;
}

.orientation-card {
    background: #0a2f59;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 18px;
    padding: 20px 24px;
    text-align: center;
    max-width: 320px;
    width: 100%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.orientation-title {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    margin-bottom: 8px;
}

.orientation-subtitle {
    font-size: 0.98rem;
    line-height: 1.5;
    opacity: 0.9;
}

@media (max-width: 800px) and (orientation: portrait) {
    .page-content {
        display: none;
    }

    .orientation-overlay {
        display: flex;
    }
}

@media (max-width: 379px) {
    .site-header-inner {
        font-size: 0.9rem;
    }

    .site-title {
        font-size: 1.6rem;
    }
}

.page-content {
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 0;
    box-sizing: border-box;
    max-width: 96%;
    margin: 0;
    width: 96%;
    align-self: center;
    flex: 1 0 auto;
    background-color: var(--card-bg-color);
}

.workshop-container {
    width: 96%;
    max-width: 96%;
    background-color: var(--main-bg-color);
    border-radius: 0;
    border-left: 1px solid #f0dcc7;
    border-right: 1px solid #f0dcc7;
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1 0 auto;
    min-height: 100%;
}

.workshop-container.mode-book {
    background-color: #4bae6c99;
}

.workshop-container.mode-random {
    background-color: #eeec8099;
}

.controls-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 96%;
    margin: 0 auto;
    align-self: center;
    box-sizing: border-box;
}

.card-settings {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    min-height: 60px;
}

.card-count-selector {
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, #ffffff, #f7fbff);
    border: 1px solid #d9e2f3;
    padding: 8px 12px;
    border-radius: 16px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
    min-height: 52px;
    height: 52px;
}

.card-count-selector label {
    margin-right: 8px;
    font-weight: 700;
    color: #0a2f59;
    font-size: 1.1rem;
}

.card-count-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-count-selector input {
    width: 30px;
    text-align: center;
    border: 1px solid #ccd5e6;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    padding: 4px 5px;
    background: #fff;
    -moz-appearance: textfield;
}

.card-count-selector input::-webkit-outer-spin-button,
.card-count-selector input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.count-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #2a9d6f;
    background: #2a9d6f;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.count-btn:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.count-btn.disabled {
    border: 1px solid #b8bec7;
    background: #b8bec7;
    color: #fff;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.card-display-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    margin-top: 16px;
    margin-bottom: 16px;
    overflow: visible;
    width: 96%;
    box-sizing: border-box;
    min-height: calc(var(--card-height) + var(--phoneme-tag-height) + 8px + 48px);
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.06);
    --card-count: 8;
    --card-width: calc((100% - (var(--card-gap) * (var(--card-count) - 1))) / var(--card-count));
    --card-height: 130px;
    --phoneme-tag-height: 46px;
}

.cards-container {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--card-height) var(--phoneme-tag-height);
    row-gap: 8px;
    align-items: start;
    min-height: calc(var(--card-height) + var(--phoneme-tag-height) + 8px);
    justify-items: stretch;
    flex: 1 1 auto;
}

.letters-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: var(--card-width);
    gap: var(--card-gap);
    width: 100%;
    margin: 0 auto;
    justify-content: center;
    height: var(--card-height);
    align-items: stretch;
}

.phoneme-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: var(--card-width);
    gap: var(--card-gap);
    min-height: var(--phoneme-tag-height);
    height: var(--phoneme-tag-height);
    width: 100%;
    margin: 0 auto;
    justify-content: center;
    align-items: stretch;
}

.phoneme-cell {
    width: 100%;
    min-width: 0;
}

.phoneme-spacer {
    height: var(--phoneme-tag-height);
}

.card-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
}

.nav-btn {
    min-width: 92px;
}

#next-word-btn {
    margin-right: 12px;
}

.phoneme-card {
    width: 100%;
    height: var(--card-height);
    background-color: var(--card-bg-color);
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
}

.phoneme-card.disabled {
    background-color: #f8f9fa;
    border-style: dashed;
}

.phoneme-card .toggle-btn {
    position: absolute;
    top: 0;
    right: 0;
    transform: translate(50%, -50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    font-size: 1.2rem;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    display: none;
}

.phoneme-card .toggle-btn.add {
    background-color: #28a745;
    color: white;
}

.phoneme-card .toggle-btn.remove {
    background-color: #dc3545;
    color: white;
}

.phoneme-card .main-char {
    font-family: 'Montserrat', 'Segoe UI Black', 'Arial Black', 'Helvetica Neue', Arial, sans-serif;
    font-size: 2.6rem;
    font-weight: bold;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 70px;
}

.phoneme-card .main-char.no-phoneme {
    color: #8c8c8c;
}

.phoneme-tag {
    height: var(--phoneme-tag-height);
    background: #f4f5f7;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 0;
    width: 100%;
}

@media (min-height: 768px) and (hover: hover) and (pointer: fine) {
    .card-display-area {
        --card-height: max(130px, calc(var(--card-width) * 4 / 3));
        --phoneme-tag-height: calc(var(--card-height) * 2 / 5);
    }
}

.phoneme-tag.disabled {
    background: #f8f9fa;
    border-style: dashed;
}

.phoneme-text {
    font-family: 'Montserrat', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    color: #4a4a4a;
}

.vowel-text {
    color: #ff3b30 !important;
}

.controls-area-bottom {
    margin-top: 0;
    padding-top: 0;
    margin-bottom: 24px;
}

.controls-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    min-height: 80px;
}

.main-controls-row {
    margin-top: -6px;
}

.choice-capsule-row {
    display: flex;
    align-items: center;
    justify-content: center;
}

.choice-capsule {
    display: inline-flex;
    border: 1px solid #d9e2f3;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
    background: #ffffff;
}

.choice-option {
    border: none;
    background: transparent;
    padding: 12px 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: 'Montserrat', 'Segoe UI Black', 'Arial Black', 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: #111111;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.choice-option:not(.active) {
    color: #111111;
}

.choice-option svg {
    width: 20px;
    height: 20px;
}

.choice-option.left.active {
    background: var(--primary-color);
    color: #ffffff;
}

.choice-option.right.active {
    background: #ff7a1a;
    color: #ffffff;
}

.generate-btn {
    background: linear-gradient(120deg, #4f46e5, #7c3aed, #ec4899, #f59e0b, #22c55e);
    color: #ffffff;
    border: none;
    padding: 14px 20px;
    border-radius: 28px;
    font-weight: 800;
    font-size: 1.1rem;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.generate-btn:hover {
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
    transform: translateY(-1px);
}

.hidden {
    display: none !important;
}
.control-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 1.1rem;
    border-radius: 25px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.main-action-btn {
    background-color: var(--primary-color);
    color: white;
}

.main-action-btn:hover {
    background-color: var(--primary-hover-color);
}

.secondary-action-btn {
    background-color: #ffffff;
    color: #2f3542;
    border: 1px solid #1f5fa7;
}

.secondary-action-btn:hover {
    background-color: #f1f6ff;
}

.play-btn {
    background-color: #2a9d6f;
    color: #ffffff;
    border: 1px solid #2a9d6f;
}

.play-btn:hover {
    background-color: #23885f;
}

.clear-btn {
    background-color: #ffd54f;
    color: #ffffff;
    border: 1px solid #e6b800;
}

.clear-btn:hover {
    background-color: #fcd96e;
}

select,
input[type="number"] {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #ccc;
}

.book-select {
    font-size: 1.1rem;
    padding: 10px 14px;
    min-width: 240px;
    width: 100%;
    min-height: 52px;
    height: 52px;
    box-sizing: border-box;
    border: none;
    background: transparent;
    outline: none;
}

.book-select-wrapper {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, #ffffff, #f7fbff);
    border: 1px solid #d9e2f3;
    padding: 4px 10px;
    border-radius: 16px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
    min-height: 52px;
    height: 52px;
    box-sizing: border-box;
}

@media (max-width: 667px) and (orientation: landscape),
       (max-height: 450px) and (orientation: landscape),
       (max-width: 399px) and (orientation: portrait) {
    .site-header {
        height: 33px;
        padding: 0;
        display: flex;
        align-items: center;
    }

    .site-header-inner {
        width: 100%;
        justify-content: center;
        padding: 0 8px;
    }

    .site-logo {
        height: 18px;
    }

    .site-title {
        font-size: 1.1rem;
    }

    .site-title-card {
        padding: 2px 2px;
        border-width: 1px;
        border-radius: 6px;
    }

    .site-footer-inner {
        font-size: 0.75rem;
    }

    .card-display-area {
        margin-top: 8px;
        margin-bottom: 8px;
        padding: 8px;
        height: calc(100vh - 128px);
        min-height: 0;
        overflow-y: auto;
        --card-height: clamp(84px, 18vh, 120px);
    }

    .cards-container {
        min-height: 0;
        flex: 1 1 auto;
        align-content: center;
    }

    .card-actions {
        margin-top: 0;
    }

    .controls-area {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding-top: 8px;
    }

    .page-content {
        flex: 1 0 auto;
    }

    .workshop-container {
        min-height: 100%;
    }

    .controls-row {
        flex-wrap: nowrap;
        gap: 8px;
        min-height: 40px;
        height: 40px;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .choice-option {
        font-size: 0.9rem;
        padding: 4px 20px;
        height: 40px;
        white-space: nowrap;
    }

    .choice-option svg {
        width: 16px;
        height: 16px;
    }

    .control-btn {
        font-size: 0.9rem;
        padding: 4px 10px;
        min-height: 40px;
        height: 40px;
    }

    .card-actions .control-btn {
        padding-top: 0;
        padding-bottom: 0;
    }

    .card-count-selector {
        padding: 2px 6px;
        min-height: 40px;
        height: 40px;
    }

    .card-count-selector label {
        font-size: 0.9rem;
    }

    .card-count-selector input {
        font-size: 0.9rem;
        padding: 2px 4px;
        height: 28px;
    }

    .count-btn {
        width: 28px;
        height: 28px;
        font-size: 0.95rem;
    }

    .book-select-wrapper {
        min-height: 40px;
        height: 40px;
        padding: 2px 8px;
    }

    .book-select {
        min-height: 40px;
        height: 40px;
        font-size: 0.9rem;
        padding: 2px 8px;
        min-width: 160px;
    }

    .generate-btn {
        padding: 4px 20px;
        font-size: 0.95rem;
    }

    .phoneme-card .main-char {
        font-size: 2.2rem;
    }
}
