/* The calculator's Details popout, in the home page's language: the dark
   surfaces, the simulation's phase gradient (red inactive -> cyan active),
   cyan eyebrows, and cards with a gradient edge. Scoped to #details-modal so
   nothing else on the page moves. Tokens mirror public/home.css. */

#details-modal {
    --dm-bg:        #0a0b0d;
    --dm-raise:     #111318;
    --dm-card:      #14161c;
    --dm-line:      #23262e;
    --dm-text:      #e8eaef;
    --dm-dim:       #9aa1ad;
    --dm-mute:      #6b7280;
    --dm-p0:        #ff3366;
    --dm-mid:       #b05cc4;
    --dm-p1:        #35e8e0;
    --dm-grad:      linear-gradient(100deg, var(--dm-p0), var(--dm-mid) 55%, var(--dm-p1));
    --dm-mono:      ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

    background: rgba(5, 6, 8, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 16px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Arial, sans-serif;
    color: var(--dm-text);
    line-height: 1.55;
    /* Above the visitor welcome banner (10001), which otherwise covers the
       bottom of the panel and its buttons. Opened on purpose, so it wins. */
    z-index: 10050;
}

html.dm-open, html.dm-open body { overflow: hidden; }

#details-modal .modal-content {
    position: relative;
    width: 100%;
    max-width: 720px;
    max-height: min(88vh, 900px);
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--dm-raise);
    border: 1px solid var(--dm-line);
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(53, 232, 224, 0.05);
    animation: dm-in .22s ease-out;
}
/* The phase gradient as a hairline across the top edge. */
#details-modal .modal-content::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: var(--dm-grad);
    opacity: .9;
}

@keyframes dm-in {
    from { opacity: 0; transform: translateY(10px) scale(.985); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    #details-modal .modal-content { animation: none; }
}

#details-modal .close-modal {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    font-family: inherit;
    font-size: 22px;
    line-height: 1;
    color: var(--dm-dim);
    background: var(--dm-card);
    border: 1px solid var(--dm-line);
    border-radius: 50%;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease;
}
#details-modal .close-modal:hover { color: var(--dm-text); border-color: var(--dm-p1); }
#details-modal .close-modal:focus-visible,
#details-modal .dm-btn:focus-visible,
#details-modal summary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(53, 232, 224, 0.35);
}

#details-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

/* ---- Header ---- */

.dm-head {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    padding: 28px 64px 22px 26px;
    background: linear-gradient(160deg, var(--dm-card), var(--dm-raise) 70%);
    border-bottom: 1px solid var(--dm-line);
}

/* The symbol in a tile ringed with the phase gradient. */
.dm-glyph {
    flex: 0 0 auto;
    min-width: 76px;
    max-width: 44%;
    height: 76px;
    padding: 0 14px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    border: 1px solid transparent;
    background:
        linear-gradient(var(--dm-bg), var(--dm-bg)) padding-box,
        var(--dm-grad) border-box;
    box-shadow: 0 0 34px rgba(53, 232, 224, 0.16);
}
.dm-glyph span {
    font-size: 2.1rem;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    color: var(--dm-text);
    text-shadow: 0 0 18px rgba(53, 232, 224, 0.35);
}

.dm-title { min-width: 0; flex: 1; }

/* A symbol that is a whole expression (⇌① : ∅ → (𝟘 ⟷ 𝟙)) wraps at a
   smaller size instead of being cut off. */
.dm-glyph.is-long { height: auto; min-height: 76px; padding: 12px 14px; max-width: 46%; }
.dm-glyph.is-long span { font-size: 1.15rem; line-height: 1.35; white-space: normal; text-align: center; overflow-wrap: anywhere; }

.dm-eyebrow {
    display: block;
    margin: 0 0 8px;
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--dm-p1);
}
.dm-eyebrow-top { margin-bottom: 6px; }

#details-modal h2 {
    margin: 0;
    font-size: clamp(1.3rem, 3.2vw, 1.7rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.015em;
    text-wrap: balance;
    overflow-wrap: anywhere;
}
.dm-long {
    margin: 4px 0 0;
    font-size: 0.9rem;
    color: var(--dm-mute);
    overflow-wrap: anywhere;
}

.dm-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.dm-chips-flags { margin-top: 12px; }

.dm-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--dm-dim);
    background: var(--dm-card);
    border: 1px solid var(--dm-line);
    border-radius: 999px;
}
.dm-chip-dims {
    font-family: var(--dm-mono);
    font-size: 0.86rem;
    color: var(--dm-text);
    border-color: transparent;
    background:
        linear-gradient(var(--dm-card), var(--dm-card)) padding-box,
        var(--dm-grad) border-box;
}
.dm-chip-hot  { color: #ffd0da; background: rgba(255, 51, 102, 0.12); border-color: rgba(255, 51, 102, 0.4); }
.dm-chip-cool { color: #c6fbf8; background: rgba(53, 232, 224, 0.09); border-color: rgba(53, 232, 224, 0.35); }
.dm-chip-mute { color: var(--dm-mute); }

/* ---- Body ---- */

.dm-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 22px 26px 8px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-color: var(--dm-line) transparent;
}
/* A scrolling flex column shrinks its children to fit before it scrolls;
   without this the meaning cards collapsed to their labels on a phone. */
.dm-body > * { flex-shrink: 0; }

.dm-facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}
.dm-fact {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 12px 14px;
    background: var(--dm-card);
    border: 1px solid var(--dm-line);
    border-radius: 11px;
    min-width: 0;
}
.dm-fact-k {
    font-size: 0.7rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--dm-mute);
}
.dm-fact-v {
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

/* Meaning cards: the home page's premise card, gradient rail and all. */
.dm-card {
    position: relative;
    padding: 16px 18px 16px 20px;
    background: var(--dm-card);
    border: 1px solid var(--dm-line);
    border-radius: 13px;
    overflow: hidden;
}
.dm-card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, var(--dm-p0), var(--dm-p1));
    opacity: .8;
}
.dm-card p { margin: 0; color: var(--dm-dim); font-size: 0.96rem; }

.dm-section h3 {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin: 4px 0 10px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--dm-p1);
}
.dm-count { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: none; color: var(--dm-mute); font-weight: 400; }

.dm-mono { font-family: var(--dm-mono); }

.dm-code, .dm-sig {
    margin: 0;
    padding: 12px 14px;
    font-family: var(--dm-mono);
    font-size: 0.92rem;
    color: var(--dm-text);
    background: var(--dm-bg);
    border: 1px solid var(--dm-line);
    border-radius: 10px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.dm-arrow { color: var(--dm-p1); padding: 0 4px; }

.dm-args {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.dm-args li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
    padding: 8px 12px;
    background: var(--dm-card);
    border: 1px solid var(--dm-line);
    border-radius: 9px;
}
.dm-arg-t { font-size: 0.82rem; color: var(--dm-mute); }
.dm-arg-d { margin-left: auto; font-size: 0.86rem; color: var(--dm-dim); }

.dm-notes { margin: 0; color: var(--dm-dim); white-space: pre-wrap; }

/* Every field, folded. */
.dm-raw {
    margin: 4px 0 14px;
    border: 1px solid var(--dm-line);
    border-radius: 11px;
    background: var(--dm-bg);
}
.dm-raw summary {
    cursor: pointer;
    padding: 11px 14px;
    font-size: 0.82rem;
    color: var(--dm-dim);
    border-radius: 11px;
    list-style: none;
}
.dm-raw summary::-webkit-details-marker { display: none; }
.dm-raw summary::before { content: "▸"; display: inline-block; margin-right: 8px; color: var(--dm-p1); transition: transform .15s ease; }
.dm-raw[open] summary::before { transform: rotate(90deg); }
.dm-raw-scroll { overflow-x: auto; padding: 0 14px 12px; }
.dm-raw table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.dm-raw th, .dm-raw td { padding: 6px 10px 6px 0; text-align: left; vertical-align: top; border-top: 1px solid var(--dm-line); }
.dm-raw th { width: 38%; font-weight: 500; color: var(--dm-mute); white-space: nowrap; }
.dm-raw td { color: var(--dm-text); overflow-wrap: anywhere; }

/* ---- Actions ---- */

.dm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 26px 20px;
    border-top: 1px solid var(--dm-line);
    background: var(--dm-raise);
}
.dm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    /* Longhand: `inherit` is not allowed inside the `font` shorthand, so that
       dropped the whole declaration and a <button> kept the browser's font. */
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    border-radius: 9px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--dm-text);
    text-decoration: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}
.dm-btn-primary { background: var(--dm-grad); color: #07080a; }
.dm-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(53, 232, 224, 0.22); }
.dm-btn-ghost { border-color: var(--dm-line); }
.dm-btn-ghost:hover { border-color: var(--dm-p1); background: rgba(53, 232, 224, 0.06); }

/* ---- Phones: a bottom sheet ---- */

@media (max-width: 600px) {
    #details-modal { padding: 0; align-items: flex-end; }
    #details-modal .modal-content {
        max-width: none;
        max-height: 92vh;
        border-radius: 18px 18px 0 0;
        border-bottom: none;
    }
    .dm-head { padding: 22px 56px 18px 16px; gap: 14px; }
    .dm-glyph { min-width: 58px; height: 58px; border-radius: 12px; }
    .dm-glyph span { font-size: 1.6rem; }
    .dm-glyph.is-long { min-height: 58px; max-width: 40%; }
    .dm-glyph.is-long span { font-size: 0.95rem; }
    .dm-body { padding: 18px 16px 6px; }
    .dm-actions { padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
    .dm-actions .dm-btn { flex: 1 1 auto; }
}
