/* ============================================
   Text Rewrap - Styles
   ============================================ */

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

:root {
    --bg-primary: #0f172a;
    --bg-surface: #1e293b;
    --bg-elevated: #273548;
    --bg-input: #16233a;
    --accent: #2dd4bf;
    --accent-solid: #14b8a6;
    --accent-deep: #0d9488;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.14);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --join: #4ade80;
    --join-bg: rgba(34, 197, 94, 0.14);
    --break: #fbbf24;
    --break-bg: rgba(250, 204, 21, 0.14);
    --mono: 'SF Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

[hidden] { display: none !important; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---- Header ---- */
.header {
    background: linear-gradient(135deg, #134e4a 0%, #0d9488 45%, #2563eb 100%);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 15px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}

.header-left { display: flex; align-items: center; gap: 14px; }

.logo {
    width: 44px;
    height: 44px;
    flex: none;
    background: rgba(255, 255, 255, 0.16);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    backdrop-filter: blur(8px);
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.015em;
    line-height: 1.25;
}

.header-subtitle {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.72);
    font-weight: 400;
    line-height: 1.4;
}

.header-right { display: flex; align-items: center; gap: 8px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: none;
    color: inherit;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .1s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn svg { flex: none; }

.header-right .btn {
    background: rgba(0, 0, 0, 0.22);
    border-color: rgba(255, 255, 255, 0.16);
    color: rgba(255, 255, 255, 0.92);
}
.header-right .btn:hover { background: rgba(0, 0, 0, 0.34); border-color: rgba(255, 255, 255, 0.3); }

.btn-ghost {
    background: var(--bg-elevated);
    border-color: var(--border);
    color: var(--text-secondary);
}
.btn-ghost:hover { background: #31425a; color: var(--text-primary); border-color: var(--border-light); }

.btn-primary {
    background: var(--accent-deep);
    border-color: var(--accent-solid);
    color: #ecfeff;
}
.btn-primary:hover { background: var(--accent-solid); }

.btn-small { padding: 6px 10px; font-size: 0.76rem; }

/* ---- Options bar ---- */
.options-bar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}

.options-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 26px;
}

.opt-group {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
}

.opt-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.seg {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
    gap: 2px;
}

.seg-btn {
    padding: 5px 11px;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.79rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.seg-btn:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.05); }
.seg-btn.active {
    background: var(--accent-deep);
    color: #f0fdfa;
}

.num-field {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.79rem;
    color: var(--text-secondary);
}
.num-field[hidden] { display: none; }

.num-field input {
    width: 62px;
    padding: 5px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.79rem;
    font-variant-numeric: tabular-nums;
}
.num-field input:focus { outline: 2px solid var(--accent-solid); outline-offset: -1px; }
.num-field .unit { color: var(--text-dim); }

.detected {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}
.detected strong { color: var(--accent); font-weight: 600; }

/* ---- More options ---- */
.opt-more { position: relative; }

.opt-more summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.79rem;
    font-weight: 500;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.opt-more summary::-webkit-details-marker { display: none; }
.opt-more summary:hover { color: var(--text-primary); border-color: var(--border-light); }
.opt-more[open] summary { background: var(--accent-deep); color: #f0fdfa; border-color: var(--accent-solid); }

.opt-more-panel {
    position: absolute;
    z-index: 60;
    top: calc(100% + 8px);
    right: 0;
    min-width: 262px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.toggle-option {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.toggle-option:hover { color: var(--text-primary); }
.toggle-option input { position: absolute; opacity: 0; width: 0; height: 0; }

.toggle-switch {
    flex: none;
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: #3f5068;
    position: relative;
    transition: background .18s;
}
.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #cbd5e1;
    transition: transform .18s, background .18s;
}
.toggle-option input:checked + .toggle-switch { background: var(--accent-solid); }
.toggle-option input:checked + .toggle-switch::after { transform: translateX(14px); background: #fff; }
.toggle-option input:focus-visible + .toggle-switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Main / panes ---- */
.main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px 24px 48px;
}

.panes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.pane {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-width: 0;
}

.pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px 10px 14px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.pane-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}
.pane-title svg { color: var(--accent); }

.pane-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.mini-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.76rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.mini-toggle:hover { color: var(--text-primary); border-color: var(--border-light); }
.mini-toggle input { accent-color: var(--accent-solid); margin: 0; }
.mini-toggle:has(input:checked) { color: var(--accent); border-color: var(--accent-deep); background: rgba(20, 184, 166, 0.1); }

.pane-body {
    position: relative;
    flex: 1;
    min-height: 0;
}

.pane-body textarea,
.decisions {
    display: block;
    width: 100%;
    height: 58vh;
    min-height: 320px;
    padding: 14px 16px;
    border: none;
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--mono);
    font-size: 0.83rem;
    line-height: 1.65;
    resize: vertical;
    tab-size: 4;
}
.pane-body textarea:focus { outline: 2px solid var(--accent-solid); outline-offset: -2px; }
.pane-body textarea::placeholder { color: var(--text-dim); }
#output { background: #14203a; }
/* When a re-wrap width is set, show the real line breaks instead of
   letting the textarea soft-wrap and hide them. */
#output.nowrap { white-space: pre; overflow-x: auto; }

/* Decisions view */
.decisions {
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    resize: none;
}
.decisions .dline {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.decisions .dtext {
    flex: 1 1 auto;
    min-width: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.decisions .mark {
    flex: 0 0 auto;
    padding: 0 5px;
    border-radius: 4px;
    font-size: 0.72rem;
    line-height: 1.5;
    user-select: none;
}
.decisions .mark-join   { background: var(--join-bg);  color: var(--join);  }
.decisions .mark-break  { background: var(--break-bg); color: var(--break); }
.decisions .dtext-joined { color: var(--text-primary); }
.decisions .dtext-kept   { color: var(--text-primary); }
.decisions .dblank {
    display: block;
    color: var(--text-dim);
    font-size: 0.72rem;
}

/* Drop overlay */
.drop-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(13, 148, 136, 0.16);
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
    pointer-events: none;
    font-weight: 600;
    color: var(--accent);
}
#dropZone.dragging .drop-overlay { display: flex; }

.pane-foot {
    padding: 8px 14px;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    font-size: 0.74rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    min-height: 33px;
}
.pane-foot b { color: var(--text-secondary); font-weight: 600; }
.pane-foot .good { color: var(--join); }

/* ---- Explainer ---- */
.explainer { margin-top: 32px; }

.explainer h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.explain-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 14px;
}

.explain-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
}

.explain-card h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    font-weight: 600;
    margin-bottom: 7px;
}

.explain-card p {
    font-size: 0.83rem;
    color: var(--text-secondary);
    line-height: 1.62;
}
.explain-card code {
    font-family: var(--mono);
    font-size: 0.92em;
    background: rgba(255, 255, 255, 0.07);
    padding: 1px 4px;
    border-radius: 4px;
}
.explain-card strong { color: var(--text-primary); font-weight: 600; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-join   { background: var(--join); }
.dot-break  { background: var(--break); }
.dot-manual { background: var(--accent); }
.dot-priv   { background: #a78bfa; }

/* ---- Toast ---- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translate(-50%, 16px);
    padding: 10px 18px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: 999px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    font-size: 0.83rem;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 2147483000;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Responsive ---- */
@media (max-width: 980px) {
    .panes { grid-template-columns: 1fr; }
    .pane-body textarea, .decisions { height: 42vh; min-height: 240px; }
    .opt-more-panel { right: auto; left: 0; }
}

@media (max-width: 640px) {
    .header-inner, .options-inner, .main { padding-left: 14px; padding-right: 14px; }
    .header-subtitle { display: none; }
    .options-inner { gap: 10px 16px; }
}
