:root {
    --bg: #f4f5fb;
    --surface: #ffffff;
    --text-main: #1f2430;
    --text-muted: #636a80;
    --accent: #5565ff;
    --accent-dark: #3644d8;
    --border: #dfe3f0;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    color: var(--text-main);
    line-height: 1.5;
}

.app-shell {
    max-width: 1250px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.app-header {
    margin-bottom: 16px;
}

.app-header h1 {
    font-size: 1.7rem;
    margin: 0;
}

.layout {
    display: grid;
    grid-template-columns: minmax(260px, 0.85fr) minmax(420px, 1.5fr);
    gap: 16px;
    align-items: start;
}

.limit-message {
    margin: 0 0 16px;
    padding: 16px 20px;
    border-radius: 12px;
    border: 1px solid #f3c8ca;
    background: #fff5f5;
    color: #a4282a;
    font-weight: 600;
}

.limit-message span {
    font-weight: 400;
    display: block;
    margin-top: 4px;
}

.unlock-card {
    margin: 16px auto 0;
    padding: 18px 20px;
    max-width: 520px;
}

.unlock-card h2 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.unlock-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.unlock-row input {
    flex: 1;
    min-width: 220px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    background: #f8f9ff;
}

.unlock-row button {
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.unlock-row button:hover {
    background: var(--accent-dark);
}

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.link-button:hover,
.link-button:focus {
    color: var(--accent-dark);
}

.form-unlock-helper {
    margin-top: 6px;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.unlimited-badge {
    font-size: 0.85rem;
    color: #0a8754;
    font-weight: 600;
    line-height: 1.4;
}

.unlock-status {
    margin-top: 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.unlock-status.success {
    color: #0a8754;
}

.unlock-status.error {
    color: #c9402f;
}


body.limit-reached .unlock-card {
    filter: none;
    opacity: 1;
    pointer-events: auto;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;

    box-shadow: 0 8px 24px rgba(20, 24, 38, 0.05);
}

.form-card {
    max-width: 420px;
    width: 100%;
    padding: 28px 26px;
}

.form-card form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 6px 4px 0;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-row .form-field {
    flex: 1;
    min-width: 100%;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-field label {
    font-weight: 600;
}

.form-field input,
.form-field textarea,
.form-field select,
.mode-select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    background: #f8f9ff;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus,
.mode-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(85, 101, 255, 0.25);
    background: #fff;
}

.form-field textarea {
    min-height: 96px;
    resize: vertical;
}

.inline-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f7f8ff;
}

.model-toggle,
.mode-toggle,
.icon-theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mode-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin: -4px 0 0;
}

.mode-toggle {
    position: relative;
    flex-wrap: wrap;
    width: 100%;
}

.replacement-help {
    flex-shrink: 0;
}

.replacement-help summary {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: var(--accent-dark);
    cursor: pointer;
    list-style: none;
}

.replacement-help summary::-webkit-details-marker {
    display: none;
}

.replacement-help summary span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 2px solid currentColor;
    border-radius: 50%;
    font-family: Georgia, serif;
    font-weight: bold;
    line-height: 1;
}

.replacement-help summary:hover,
.replacement-help[open] summary {
    background: #eaf0f6;
    border-radius: 50%;
}

.replacement-help summary:focus-visible {
    outline: 3px solid var(--accent-dark);
    outline-offset: 2px;
    border-radius: 50%;
}

.replacement-help-content {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 2;
    width: min(320px, 100%);
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 6px 20px rgba(31, 36, 48, 0.15);
    font-size: 14px;
}

.replacement-help-content p {
    margin: 0 0 10px;
}

.replacement-help-content ul {
    margin: 0;
    padding-left: 20px;
}

.replacement-help-content li + li {
    margin-top: 8px;
}

.hidden {
    display: none !important;
}

.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #cfd5ff;
    transition: 0.3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: '';
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.switch input:checked + .slider {
    background-color: var(--accent);
}

.switch input:checked + .slider:before {
    transform: translateX(24px);
}

.model-toggle-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.length-toggle {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f7f8ff;
}

.length-label {
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
}

.length-slider-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.length-slider-wrapper input[type='range'] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #d9def5;
    outline: none;
}

.length-slider-wrapper input[type='range']::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(85, 101, 255, 0.4);
}

.length-slider-wrapper input[type='range']::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(85, 101, 255, 0.4);
}

.length-options {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.length-value {
    margin-top: 4px;
    font-weight: 600;
    color: var(--accent-dark);
}

.primary-action {
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    cursor: pointer;
    transition: transform 0.2s ease;
}

.primary-action:hover {
    transform: translateY(-1px);
}

.output-card h2 {
    margin: 0 0 12px;
    font-size: 1.2rem;
}

.output-container {
    margin: 0;
    position: relative;
}

.output {
    padding-left: 28px;
    padding-right: 28px;
    border: 1px solid #ccc;
    border-radius: 14px;
    font-size: 22px;
    line-height: 1.9;
    font-family: Comic Sans MS, serif;
    position: relative;
    padding-bottom: 12px;
    background: #fff;
    min-height: 500px;
}

.story-editor {
    width: 100%;
    min-height: 500px;
    border: 1px solid #ccc;
    border-radius: 14px;
    font-size: 22px;
    line-height: 1.7;
    font-family: Comic Sans MS, serif;
    padding: 18px 24px;
    background: #fff;
    resize: vertical;
}

.story-editor:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(85, 101, 255, 0.25);
}

#output:not(.has-pages)::after,
.story-page::after {
    content: 'Dysclick.fr';
    position: absolute;
    right: 16px;
    bottom: 12px;
    font-size: 20px;
    font-family: 'Arial', sans-serif;
    color: #333;
    pointer-events: none;
}

.emoji-container {
    display: inline-block;
    text-align: center;
    vertical-align: middle;
}

.emoji {
    font-size: 52px;
}

.emoji-word {
    font-size: 22px;
    display: block;
    margin-top: 65px;
    margin-left: -70px;
    font-family: Comic Sans MS, serif;
}

.picto-container {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 90px;
    margin: 0 6px;
}

.picto-image {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 8px;
    border: 0px solid #dcdcdc;
    background: #fff;
}

.picto-caption {
    margin-top: 6px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.15;
    color: #333;
    text-align: center;
}

.picto-fallback {
    display: inline-block;
    padding: 6px 10px;
    border: 1px dashed #888;
    border-radius: 6px;
    margin: 0 4px;
    font-weight: 600;
}

.error {
    color: red;
}

.buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.buttons button {
    flex: 1;
    min-width: 140px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f5f6ff;
    color: var(--text-main);
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.buttons button:hover {
    border-color: var(--accent);
}

.story-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.story-navigation button {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f5f6ff;
    color: var(--text-main);
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.story-navigation button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.story-page-indicator {
    font-weight: 600;
    color: var(--accent-dark);
}

.story-page {
    display: block;
    position: relative;
    min-height: 488px;
    padding-bottom: 48px;
}

.story-page.is-hidden {
    display: none;
}

.vocab-page {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vocab-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px 16px;
    width: 100%;
}

.vocab-item {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
}

.vocab-item .emoji-word {
    margin-top: 6px;
    margin-left: 0;
}

.vocab-item .emoji {
    font-size: 90px;
}

.vocab-item .picto-image {
    width: 120px;
    height: 120px;
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }
}


.tool-switch { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 18px; }
.tool-switch a { padding: 8px 14px; border-radius: 20px; color: #254767; text-decoration: none; background: #eaf0f6; }
.tool-switch a[aria-current="page"] { background: #254767; color: white; }
.app-header h1 { text-align: center; font-size: 1.6rem; }

.writing-toolbar { display: flex; justify-content: flex-end; padding: 12px; }
.writing-toolbar button, .picker-heading button {
    padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
    background: #f5f6ff; color: var(--text-main); font: inherit; font-weight: 600; cursor: pointer;
}
.writing-help { padding: 16px 24px; background: #f7f8ff; border-top: 1px solid var(--border); }
.writing-help summary { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    font-weight: 600; cursor: pointer; list-style: none; }
.writing-help summary::-webkit-details-marker { display: none; }
.writing-help:not([open]) summary i { transform: rotate(-90deg); }
.writing-help summary:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 4px; }
.writing-help ol { padding-left: 22px; }
.writing-help li + li { margin-top: 6px; }
.writing-help p { font-size: 14px; margin-bottom: 0; }
#imagePicker { width: min(640px, calc(100% - 24px)); max-height: 85vh; overflow: auto;
    border: 1px solid var(--border); border-radius: 16px; padding: 20px; color: var(--text-main); }
#imagePicker::backdrop { background: rgb(31 36 48 / 45%); }
.picker-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.picker-heading h2 { font-size: 1.2rem; }
#imagePicker .form-field { margin-bottom: 12px; }
.image-search label { font-weight: 600; }
.image-search input { min-width: 0; width: 100%; }
.image-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px;
    max-height: 300px; overflow: auto; margin-bottom: 16px; }
.image-choice { display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 10px; border: 2px solid var(--border); border-radius: 10px; background: white;
    color: var(--text-main); cursor: pointer; font: inherit; overflow-wrap: anywhere; }
.image-choice img { width: 64px; height: 64px; object-fit: contain; }
.picker-emoji { font-size: 42px; }
.image-choice[aria-pressed="true"] { border-color: var(--accent-dark); background: #edf0ff; }
.image-choice[aria-pressed="true"]::after { content: 'Sélectionnée'; font-size: 12px; font-weight: 600; }
button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 3px; }
@media (max-width: 480px) {
    .app-shell { padding: 20px 12px; }
    .story-editor { padding: 16px; }
    .writing-help { padding: 16px; }
}

#storyEmail { width: 100%; box-sizing: border-box; }
#quotaStatus, #accessStatus { overflow-wrap: anywhere; }
#generationStatus:empty { display: none; }

/* Couleurs et macaron identiques au générateur d’agendas. */
.premium-badge { align-items: center; background: #FFF1B8; border: 1px solid #E2A900; border-radius: 999px; color: #6B4A00; display: inline-flex; font-size: 11px; font-weight: 800; gap: 4px; line-height: 1; padding: 5px 8px; white-space: nowrap; }
.model-label { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.premium-banner { background: #FFF8E0; border: 2px solid #FFC20A; border-radius: 12px; color: #6B4A00; padding: 14px; margin: 12px 0; font-size: 0.9rem; line-height: 1.5; }
.premium-banner strong { display: block; }
.premium-banner p { margin: 0.4rem 0 0; }
.support-button { width: 100%; background: #fff; border: 2px solid #FFC20A; border-radius: 10px; color: var(--accent-dark); padding: 12px; margin: 12px 0; font: inherit; font-weight: 600; cursor: pointer; }
.support-button.active { background: #FFF8E0; }
#premiumInfo { max-width: 520px; max-height: 85vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 16px; padding: 20px; color: var(--text-main); }
#premiumInfo::backdrop { background: rgba(38,50,56,0.42); }
#premiumInfoButton { margin-top: 12px; }

#storyShareDialog { box-sizing: border-box; width: min(520px, calc(100% - 24px)); max-height: 85vh;
    overflow: auto; border: 1px solid var(--border); border-radius: 16px; padding: 20px; color: var(--text-main); }
#storyShareDialog::backdrop { background: rgb(31 36 48 / 45%); }
.share-options { display: flex; flex-direction: column; gap: 12px; }
.share-options button, .share-options a { padding: 12px 16px; border: 1px solid var(--border);
    border-radius: 10px; background: #f5f6ff; color: var(--text-main); font: inherit; cursor: pointer; text-decoration: none; }
.share-options a:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 3px; }
.share-destinations { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 12px; }
.share-destinations a, .share-destinations button { display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 8px; padding: 14px 6px; text-align: center; font-size: 14px; }
.share-destinations img { width: 32px; height: 32px; }
.share-link-row { display: flex; align-items: stretch; gap: 8px; }
.share-link-row #storyShareLink { flex: 1; width: 0; }
#copyStoryLink { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    flex-shrink: 0; padding: 10px 12px; font-size: 14px; }
#copyStoryLink img { width: 22px; height: 22px; }
.share-button-icon { width: 20px; height: 20px; vertical-align: middle; margin-right: 6px; }
#storyShareLink { box-sizing: border-box; min-width: 0; padding: 10px; font: inherit; }
