/* spell-editor.css
 * Styles for the reusable Custom Spell Editor (page + modal modes).
 * Uses site theme variables so it inherits dark mode automatically.
 */

/* Scoped accent — amber/gold matches Spell Creator's identity.
   Other surface tokens come from main_style.css :root. */
.cc-spell-editor {
    --accent-color: #ffb84d;
}
html.dark .cc-spell-editor {
    --accent-color: #ffc769;
}

/* ─── Modal overlay ────────────────────────────────────── */

.cc-spell-editor-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
}

.cc-spell-editor {
    background: var(--bg-secondary, #1e1f24);
    color: var(--text-primary, #f0f0f0);
    border: 1px solid var(--border-color, #444);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

.cc-spell-editor-modal {
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
}

.cc-spell-editor-page {
    width: 100%;
    max-width: 800px;
    margin: 1rem auto;
}

/* ─── Header ───────────────────────────────────────────── */

.cc-se-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color, #444);
    padding-bottom: 1rem;
    margin-bottom: 1.25rem;
    gap: 0.75rem;
}

.cc-se-title {
    font-family: 'MedievalSharp', serif;
    font-size: 1.5rem;
    color: var(--accent-color, #ffb84d);
    margin: 0;
}

.cc-se-close {
    background: transparent;
    border: none;
    color: var(--text-secondary, #aaa);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.5rem;
}
.cc-se-close:hover {
    color: var(--text-primary, #fff);
}

.cc-se-completeness {
    width: 100%;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary, #aaa);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.cc-se-completeness-bar {
    flex: 1;
    min-width: 100px;
    height: 6px;
    background: var(--bg-tertiary, #2c2d33);
    border-radius: 3px;
    overflow: hidden;
}

.cc-se-completeness-fill {
    height: 100%;
    transition: width 0.3s ease, background-color 0.3s ease;
    background: #888;
}
.cc-se-completeness-fill.cc-se-completeness-red { background: #d65a4a; }
.cc-se-completeness-fill.cc-se-completeness-amber { background: #e8a43d; }
.cc-se-completeness-fill.cc-se-completeness-green { background: #4caf50; }

.cc-se-completeness-value {
    font-weight: 600;
    color: var(--text-primary, #f0f0f0);
    min-width: 3em;
}

/* ─── Form ─────────────────────────────────────────────── */

.cc-se-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.cc-se-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-start;   /* keep labels aligned at the top when fields wrap */
}

.cc-se-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    /* min-width 180px + flex-basis 200px means narrow widths wrap one field
       per row before any overlap. The old min-width:0 let inputs collapse
       smaller than their content, causing visible overlap with the next
       wrapped field. */
    flex: 1 1 200px;
    min-width: 180px;
}

.cc-se-field-name {
    flex: 1 1 100%;
}

.cc-se-field-full {
    flex: 1 1 100%;
}

.cc-se-field > span,
.cc-se-components legend {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary, #aaa);
    margin-bottom: 0.15rem;
}

.cc-se-field input[type="text"],
.cc-se-field input[type="number"],
.cc-se-field select,
.cc-se-field textarea {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-tertiary, #2c2d33);
    border: 1px solid var(--border-color, #444);
    color: var(--text-primary, #f0f0f0);
    border-radius: 6px;
    padding: 0.55rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
}

.cc-se-field input[type="text"]:focus,
.cc-se-field input[type="number"]:focus,
.cc-se-field select:focus,
.cc-se-field textarea:focus {
    outline: none;
    border-color: var(--accent-color, #ffb84d);
    box-shadow: 0 0 0 2px rgba(255, 184, 77, 0.25);
}

.cc-se-field textarea {
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
    line-height: 1.5;
}

/* Custom inputs (text fields shown after preset dropdown selects "Custom...") */
.cc-se-field input[name$="Custom"],
.cc-se-field input[name$="Material"] {
    margin-top: 0.4rem;
}

/* ─── Components fieldset ──────────────────────────────── */

.cc-se-components {
    border: 1px solid var(--border-color, #444);
    border-radius: 6px;
    padding: 0.75rem;
    margin: 0;
    flex: 1 1 100%;
    background: var(--bg-tertiary, #2c2d33);
}

.cc-se-components legend {
    padding: 0 0.5rem;
}

.cc-se-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-right: 1rem;
    cursor: pointer;
    color: var(--text-primary, #f0f0f0);
    font-size: 0.9rem;
}

.cc-se-checkbox input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent-color, #ffb84d);
}

/* ─── Error message ────────────────────────────────────── */

.cc-se-error {
    background: rgba(214, 90, 74, 0.12);
    border: 1px solid rgba(214, 90, 74, 0.4);
    color: #ff8c7a;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* ─── Action buttons ───────────────────────────────────── */

.cc-se-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color, #444);
    margin-top: 0.5rem;
}

.cc-se-btn {
    padding: 0.6rem 1.4rem;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.cc-se-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.cc-se-btn-primary {
    background: var(--accent-color, #ffb84d);
    color: #1a1a1a;
}
.cc-se-btn-primary:hover:not(:disabled) {
    background: #ffc769;
    transform: translateY(-1px);
}

.cc-se-btn-secondary {
    background: var(--bg-tertiary, #2c2d33);
    color: var(--text-primary, #f0f0f0);
    border-color: var(--border-color, #444);
}
.cc-se-btn-secondary:hover:not(:disabled) {
    background: #383a42;
}

.cc-se-btn-danger {
    background: rgba(214, 90, 74, 0.18);
    color: #ff8c7a;
    border-color: rgba(214, 90, 74, 0.4);
    margin-right: auto;  /* push delete to far left */
}
.cc-se-btn-danger:hover:not(:disabled) {
    background: rgba(214, 90, 74, 0.3);
}

.cc-se-btn-ghost {
    background: transparent;
    color: var(--accent-color, #ffb84d);
    border-color: rgba(255, 184, 77, 0.4);
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
}
.cc-se-btn-ghost:hover:not(:disabled) {
    background: rgba(255, 184, 77, 0.12);
}

/* ─── Fieldset wrapper (Attack/Save, Damage, AOE, Classes) ─ */

.cc-se-fieldset {
    border: 1px solid var(--border-color, #444);
    border-radius: 8px;
    padding: 1rem 1.1rem 1.1rem;
    /* Larger top margin so the legend doesn't visually crash into the
       previous fieldset's content, fixing the "overlapping entry boxes"
       symptom — fieldsets were sitting too close to each other before. */
    margin: 0 0 1.4rem;
    background: rgba(255, 255, 255, 0.02);
}

.cc-se-fieldset > legend {
    padding: 0 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-color, #ffb84d);
    font-weight: 600;
}

/* Rows inside a fieldset can wrap on narrow widths — make sure each field
   has enough breathing room so labels and inputs don't visually overlap
   when fieldsets contain multiple .cc-se-field side-by-side. */
.cc-se-fieldset .cc-se-row {
    gap: 0.85rem;
    flex-wrap: wrap;
}
.cc-se-fieldset .cc-se-field {
    min-width: 140px;
}
.cc-se-fieldset .cc-se-field input,
.cc-se-fieldset .cc-se-field select,
.cc-se-fieldset .cc-se-field textarea {
    width: 100%;
    box-sizing: border-box;
}

/* Flags row (Concentration + Ritual toggles) */
.cc-se-flags-row {
    gap: 1.5rem;
}

/* ─── Damage row ──────────────────────────────────────── */

.cc-se-damage-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.cc-se-damage-row {
    display: grid;
    /* Column widths bumped from 80px / 90px to 96px / 110px so the number
       spinner doesn't crowd the value and the die <select> has room for
       padding + "d12" without overflowing into the type column. The 1fr
       type column has a min so it never collapses below readable width. */
    grid-template-columns: 96px 110px minmax(140px, 1fr) 36px;
    gap: 0.6rem;
    align-items: center;
    min-width: 0;
}

.cc-se-damage-row input,
.cc-se-damage-row select {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border-radius: 5px;
    border: 1px solid var(--border-color, #444);
    background: var(--bg-tertiary, #2c2d33);
    color: var(--text-primary, #f0f0f0);
    font-size: 0.9rem;
}

.cc-se-btn-remove-damage {
    background: transparent;
    border: 1px solid var(--border-color, #444);
    color: var(--text-secondary, #aaa);
    border-radius: 5px;
    padding: 0.3rem 0;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}
.cc-se-btn-remove-damage:hover {
    background: rgba(214, 90, 74, 0.15);
    color: #ff8c7a;
    border-color: rgba(214, 90, 74, 0.4);
}

/* ─── Remix banner (shown when editor opened via gallery Remix) ─ */
.cc-se-remix-banner {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, rgba(123, 47, 247, 0.15), rgba(74, 105, 189, 0.15));
    border: 1px solid rgba(123, 47, 247, 0.4);
    border-left: 4px solid #7b2ff7;
    border-radius: 8px;
    color: var(--text-primary, #f0f0f0);
    line-height: 1.5;
}
.cc-se-remix-banner i {
    color: #7b2ff7;
    font-size: 1.2rem;
    margin-top: 0.15rem;
    flex-shrink: 0;
}
.cc-se-remix-banner strong {
    display: block;
    color: #b66cff;
    font-size: 1.05rem;
    margin-bottom: 0.15rem;
}
.cc-se-remix-attribution {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary, #aaa);
    margin-bottom: 0.4rem;
    font-style: italic;
}
.cc-se-remix-banner p {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
    color: var(--text-secondary, #aaa);
}
html:not(.dark) body .cc-se-remix-banner {
    background: linear-gradient(135deg, rgba(123, 47, 247, 0.08), rgba(74, 105, 189, 0.08));
    color: #1a1a1a;
}
html:not(.dark) body .cc-se-remix-banner strong {
    color: #7b2ff7;
}
html:not(.dark) body .cc-se-remix-banner p,
html:not(.dark) body .cc-se-remix-attribution {
    color: #666;
}

/* ─── Tag suggestion chips ────────────────────────────── */

.cc-se-tag-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.cc-se-tag-chip {
    background: transparent;
    border: 1px solid var(--border-color, #444);
    color: var(--text-secondary, #aaa);
    padding: 0.2rem 0.7rem;
    border-radius: 12px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
    font-family: inherit;
}

.cc-se-tag-chip:hover {
    background: rgba(255, 184, 77, 0.15);
    border-color: var(--accent-color, #ffb84d);
    color: var(--accent-color, #ffb84d);
    transform: translateY(-1px);
}

.cc-se-tag-chip-added {
    background: rgba(76, 175, 80, 0.2);
    border-color: #4caf50;
    color: #4caf50;
}

/* Persistent "in current tag list" state — set whenever the tag input
   contains this chip's tag. Distinct from the brief .cc-se-tag-chip-added
   flash (which fades after add). Helps the user see at a glance which
   suggestions are already used, including ones added by Codex. */
.cc-se-tag-chip-active {
    background: rgba(255, 184, 77, 0.18);
    border-color: var(--accent-color, #ffb84d);
    color: var(--accent-color, #ffb84d);
}
html:not(.dark) body .cc-se-tag-chip-active {
    background: rgba(181, 110, 31, 0.12);
    border-color: #b56e1f;
    color: #b56e1f;
}

.cc-se-tag-chip-already {
    background: rgba(255, 184, 77, 0.1);
    color: var(--text-secondary, #aaa);
    opacity: 0.6;
}

html:not(.dark) body .cc-se-tag-chip {
    background: #ffffff;
    border-color: #d0d0d0;
    color: #555;
}
html:not(.dark) body .cc-se-tag-chip:hover {
    background: rgba(181, 110, 31, 0.08);
    border-color: #b56e1f;
    color: #b56e1f;
}

/* ─── Effect rows (structured multi-effect builder) ───── */

.cc-se-helper-text {
    color: var(--text-secondary, #aaa);
    font-size: 0.8rem;
    line-height: 1.4;
    margin: -0.25rem 0 0.75rem;
    font-style: italic;
}

.cc-se-effects-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

.cc-se-effect-row {
    border: 1px solid var(--border-color, #444);
    border-radius: 6px;
    padding: 0.6rem;
    background: rgba(255, 255, 255, 0.02);
}

.cc-se-effect-head {
    display: grid;
    grid-template-columns: 180px 1fr 36px;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.cc-se-effect-body {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.cc-se-effect-row input[type="text"],
.cc-se-effect-row select,
.cc-se-effect-row textarea {
    padding: 0.4rem 0.55rem;
    border-radius: 4px;
    border: 1px solid var(--border-color, #444);
    background: var(--bg-tertiary, #2c2d33);
    color: var(--text-primary, #f0f0f0);
    font-size: 0.85rem;
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
}

.cc-se-effect-row textarea {
    resize: vertical;
    min-height: 50px;
}

.cc-se-effect-flags {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.6rem;
    align-items: center;
}

.cc-se-btn-remove-effect {
    background: transparent;
    border: 1px solid var(--border-color, #444);
    color: var(--text-secondary, #aaa);
    border-radius: 4px;
    padding: 0.3rem 0;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}
.cc-se-btn-remove-effect:hover {
    background: rgba(214, 90, 74, 0.15);
    color: #ff8c7a;
    border-color: rgba(214, 90, 74, 0.4);
}

html:not(.dark) body .cc-se-effect-row {
    background: #fefcf6;
    border-color: #d0d0d0;
}
html:not(.dark) body .cc-se-effect-row input[type="text"],
html:not(.dark) body .cc-se-effect-row select,
html:not(.dark) body .cc-se-effect-row textarea {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #d0d0d0;
}
html:not(.dark) body .cc-se-helper-text {
    color: #666;
}

@media (max-width: 600px) {
    .cc-se-effect-head {
        grid-template-columns: 1fr 36px;
        grid-template-areas:
            "kind remove"
            "name name";
    }
    .cc-se-effect-head .cc-se-effect-kind { grid-area: kind; }
    .cc-se-effect-head .cc-se-effect-name { grid-area: name; }
    .cc-se-effect-head .cc-se-btn-remove-effect { grid-area: remove; }
    .cc-se-effect-flags {
        grid-template-columns: 1fr;
    }
}

/* ─── Class pills (multi-select grid) ──────────────────── */

.cc-se-class-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.cc-se-class-pill {
    background: var(--bg-tertiary, #2c2d33);
    border: 1px solid var(--border-color, #444);
    border-radius: 16px;
    padding: 0.3rem 0.85rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-size: 0.85rem;
    margin: 0;
}

.cc-se-class-pill input[type="checkbox"] {
    /* Hide the actual checkbox; visual state lives on the label */
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.cc-se-class-pill:has(input[type="checkbox"]:checked) {
    background: rgba(255, 184, 77, 0.18);
    border-color: var(--accent-color, #ffb84d);
    color: var(--accent-color, #ffb84d);
}

.cc-se-class-pill:hover {
    border-color: var(--accent-color, #ffb84d);
}

/* ─── Light mode overrides ─────────────────────────────── */

html:not(.dark) body .cc-spell-editor {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #d0d0d0;
}
html:not(.dark) body .cc-se-title {
    color: #b56e1f;
}
html:not(.dark) body .cc-se-completeness-value {
    color: #1a1a1a;
}
html:not(.dark) body .cc-se-field > span,
html:not(.dark) body .cc-se-components legend {
    color: #555;
}
html:not(.dark) body .cc-se-field input[type="text"],
html:not(.dark) body .cc-se-field select,
html:not(.dark) body .cc-se-field textarea,
html:not(.dark) body .cc-se-components,
html:not(.dark) body .cc-se-completeness-bar {
    background: #f8f8f8;
    color: #1a1a1a;
    border-color: #d0d0d0;
}
html:not(.dark) body .cc-se-btn-secondary {
    background: #f0f0f0;
    color: #1a1a1a;
}
html:not(.dark) body .cc-se-btn-secondary:hover:not(:disabled) {
    background: #e0e0e0;
}
html:not(.dark) body .cc-se-actions {
    border-top-color: #d0d0d0;
}
html:not(.dark) body .cc-se-header {
    border-bottom-color: #d0d0d0;
}

/* Light-mode overrides for the new comprehensive-spell fieldsets */
html:not(.dark) body .cc-se-fieldset {
    background: #f8f8f8;
    border-color: #d0d0d0;
}
html:not(.dark) body .cc-se-fieldset > legend {
    color: #b56e1f;
}
html:not(.dark) body .cc-se-damage-row input,
html:not(.dark) body .cc-se-damage-row select {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #d0d0d0;
}
html:not(.dark) body .cc-se-class-pill {
    background: #ffffff;
    border-color: #d0d0d0;
    color: #1a1a1a;
}
html:not(.dark) body .cc-se-class-pill:has(input[type="checkbox"]:checked) {
    background: rgba(181, 110, 31, 0.12);
    border-color: #b56e1f;
    color: #b56e1f;
}
html:not(.dark) body .cc-se-btn-ghost {
    color: #b56e1f;
    border-color: rgba(181, 110, 31, 0.4);
}
html:not(.dark) body .cc-se-btn-ghost:hover:not(:disabled) {
    background: rgba(181, 110, 31, 0.08);
}
html:not(.dark) body .cc-se-btn-remove-damage {
    border-color: #d0d0d0;
    color: #777;
}

/* ─── Mobile ───────────────────────────────────────────── */

@media (max-width: 600px) {
    .cc-spell-editor {
        padding: 1rem;
    }
    .cc-se-row {
        flex-direction: column;
        gap: 0.75rem;
    }
    .cc-se-actions {
        flex-direction: column-reverse;
    }
    .cc-se-btn {
        width: 100%;
    }
    .cc-se-btn-danger {
        margin-right: 0;
    }
    /* Damage row: collapse to 2 rows on small screens — count + die
       on top, type + remove on bottom. */
    .cc-se-damage-row {
        grid-template-columns: 1fr 1fr 36px;
        grid-template-areas:
            "count die remove"
            "type type type";
        gap: 0.4rem;
    }
    .cc-se-damage-row .cc-se-dmg-count { grid-area: count; }
    .cc-se-damage-row .cc-se-dmg-die { grid-area: die; }
    .cc-se-damage-row .cc-se-dmg-type { grid-area: type; }
    .cc-se-damage-row .cc-se-btn-remove-damage { grid-area: remove; }
}
