/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #d4d8de;
    background: linear-gradient(135deg, #0d0d0f 0%, #171719 100%);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Layout container — wide by default on desktop (Uto-qsxw) */
.container {
    max-width: 95vw;
    margin: 0 auto;
    padding: 20px;
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
}

/* Header styling */
header {
    background: rgba(10, 10, 12, 0.97);
    text-align: center;
    padding: 0.5rem;
    margin-bottom: 0;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.header-content {
    display: inline-flex;
    align-items: center;
    gap: 1rem;
}

.site-logo {
    width: 90px;
    height: 90px;
    object-fit: contain;
    flex-shrink: 0;
}

header h1 {
    color: #8aafc8;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }
}

header p {
    color: #7a8290;
    font-size: 1.1rem;
}

@media (max-width: 768px) {
    header p {
        font-size: 1rem;
    }
}

/* Main content area — single top-down column layout */
main {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Left column wrapper — display:contents so its children join the main grid directly */
.left-col {
    display: contents;
}

/* Section order: Input (1) → Formatted Output (2) → Advanced Settings (3) */
.input-section  { order: 1; }
.output-section { order: 2; }
.adv-panel      { order: 3; }

/* Desktop: Advanced Settings max width */
@media (min-width: 768px) {
    #advanced-settings {
        max-width: 800px;
    }
}

/* Section styling */
section {
    background: rgba(18, 18, 20, 0.97);
    padding: 1rem;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    margin-bottom: 1rem;
}

.input-section {
    max-width: 1200px;
}

section h2 {
    color: #8aafc8;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

section > p,
section > label {
    color: #7a8290;
    margin-bottom: 1rem;
    display: block;
}

/* =====================================================
   Advanced Settings Panel
   ===================================================== */

.adv-panel {
    padding: 0;
    overflow: visible;
}

.adv-toggle-btn {
    background: none;
    border: none;
    border-radius: 10px;
    width: 100%;
    text-align: left;
    padding: 1rem 2rem;
    color: #8aafc8;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transform: none;
    box-shadow: none;
}

.adv-toggle-btn:hover {
    background: rgba(138, 175, 200, 0.08);
    transform: none;
    box-shadow: none;
}

.adv-toggle-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    display: inline-block;
}

.adv-toggle-btn[aria-expanded="true"] .adv-toggle-icon {
    transform: rotate(90deg);
}

#adv-content[hidden] {
    display: none;
}

#adv-content {
    padding: 0 2rem 1.5rem;
    border-top: 1px solid #2a2a2e;
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.adv-col {
    flex: 1;
    min-width: 0;
}

@media (max-width: 900px) {
    #adv-content {
        flex-direction: column;
    }
}

.adv-group-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #7a8290;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 1rem 0 0.5rem;
}

.adv-subgroup-title {
    font-size: 0.68rem;
    font-weight: 600;
    color: #7a8290; /* was #4e5560 — failed 4.5:1 contrast against dark background */
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0.75rem 0 0.2rem;
    padding-left: 0.1rem;
}

.adv-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
}

.adv-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #d4d8de;
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: 0;
}

.adv-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #8aafc8;
    cursor: pointer;
    flex-shrink: 0;
}

.adv-group input[type="number"] {
    width: 56px;
    padding: 0.15rem 0.4rem;
    border: 1px solid #2a2a2e;
    border-radius: 4px;
    background: #0d0d0f;
    color: #d4d8de;
    font-size: 0.9rem;
    text-align: center;
}

/* ── Hint (?) tooltip ─────────────────────────────────────────────────────── */

/* Wrapper provides the hover target and tooltip anchor */
.adv-hint-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

/* The ? button */
.adv-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    border: 1px solid #3a3a3e;
    background: #1a1a1f;
    color: #7a8290;
    font-size: 0.6rem;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

@media (pointer: coarse) {
    .adv-hint {
        width: 12px;
        height: 12px;
        min-width: 0;
        min-height: 0;
    }
}

.adv-hint:hover,
.adv-hint:focus-visible {
    color: #8aafc8;
    border-color: #8aafc8;
    outline: 2px solid #8aafc8;
    outline-offset: 1px;
}

/* Tooltip bubble */
.adv-hint-tooltip {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e1e24;
    color: #d4d8de;
    font-size: 0.78rem;
    line-height: 1.45;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid #3a3a3e;
    width: 220px;
    white-space: normal;
    z-index: 200;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

/* Arrow pointing up toward the ? */
.adv-hint-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: #3a3a3e;
}

/* Show on desktop hover over the whole wrapper (satisfies WCAG 1.4.13 — hoverable) */
.adv-hint-wrap:hover .adv-hint-tooltip,
/* Show when the ? button is focused (keyboard access) */
.adv-hint-wrap:focus-within .adv-hint-tooltip,
/* Show when toggled open on touch */
.adv-hint-wrap.is-open .adv-hint-tooltip {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Parent-child checkbox groups in Show/Hide */
.adv-parent-group {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.adv-children {
    display: flex;
    flex-direction: column;
    padding-left: 1.6rem;
}

.adv-child-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.15rem 0;
}

.adv-child-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #b8bec8;
    font-size: 0.85rem;
    cursor: pointer;
    margin-bottom: 0;
}

.adv-child-group input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #8aafc8;
    cursor: pointer;
    flex-shrink: 0;
}

.adv-children.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* Section order list */
.section-order-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.section-order-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
    color: #d4d8de;
    font-size: 0.9rem;
}

.section-order-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #8aafc8;
    cursor: pointer;
    flex-shrink: 0;
}

.order-btn {
    background: rgba(138, 175, 200, 0.12);
    border: 1px solid rgba(138, 175, 200, 0.3);
    border-radius: 4px;
    color: #8aafc8;
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    transform: none;
    box-shadow: none;
    min-width: unset;
    min-height: unset;
    line-height: 1;
}

.order-btn:hover {
    background: rgba(138, 175, 200, 0.22);
    transform: none;
    box-shadow: none;
}

.order-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.section-order-parent {
    margin-top: 0.4rem;
}

.section-order-group-label {
    font-weight: 600;
    color: #8aafc8;
    font-size: 0.9rem;
}

.section-order-child {
    padding-left: 2rem;
}

/* Mobile */
@media (max-width: 768px) {
    .adv-toggle-btn {
        padding: 1rem;
    }

    #adv-content {
        padding: 0 1rem 1rem;
        flex-direction: column;
    }
}

/* Auto-detect badge */
.detect-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.65rem;
    border-radius: 12px;
    background: rgba(138, 175, 200, 0.15);
    color: #8aafc8;
    border: 1px solid rgba(138, 175, 200, 0.35);
    margin-top: 0.5rem;
}

/* Focus indicators — keyboard navigation */
button:focus-visible,
input:focus-visible,
details > summary:focus-visible {
    outline: 3px solid #8aafc8;
    outline-offset: 2px;
}

textarea:focus-visible {
    outline: 2px solid #8aafc8;
    outline-offset: 2px;
}

/* Textarea styling */
textarea {
    width: 100%;
    padding: 1rem;
    border: 2px solid #2a2a2e;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: vertical;
    background-color: #141416;
    color: #d4d8de;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

@media (max-width: 768px) {
    textarea {
        font-size: 16px;
        padding: 0.75rem;
        min-height: 120px;
    }
}

textarea:focus {
    border-color: #8aafc8;
    box-shadow: 0 0 0 3px rgba(138, 175, 200, 0.2);
}

textarea[readonly] {
    background-color: #0d0d0f;
    color: #d4d8de;
    white-space: pre-wrap;
    word-wrap: break-word;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Button styling */
.button-group {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .button-group {
        gap: 0.75rem;
    }
}

button {
    background: linear-gradient(135deg, #4a7a9b 0%, #2d5470 100%);
    color: #ffffff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 700;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

@media (max-width: 768px) {
    button {
        padding: 1rem;
        font-size: 1.1rem;
        min-height: 44px;
        min-width: 44px;
    }
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(138, 175, 200, 0.4);
}

button:active {
    transform: translateY(0);
}

#clear-btn {
    background: linear-gradient(135deg, #c53030 0%, #8b2323 100%);
    color: #fff;
}

#copy-btn {
    background: linear-gradient(135deg, #2d6a4f 0%, #40916c 100%);
    color: #fff;
}

#discord-copy-btn {
    background: linear-gradient(135deg, #3c3263 0%, #5c4d9a 100%);
    color: #e0d9ff;
}

/* Feedback message */
.feedback {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    font-weight: 600;
}

.feedback.hidden {
    display: none;
}

.feedback:not(.hidden) {
    background: #1c2e1c;
    color: #68d391;
    border: 1px solid #2d4a2d;
}

.feedback:not(.hidden):has([style*="fed7d7"]) {
    background: #2e1a1a;
    color: #fc8181;
    border: 1px solid #742a2a;
}

.feedback:not(.hidden):has([style*="feebc8"]) {
    background: #2e2014;
    color: #f6ad55;
    border: 1px solid #744210;
}

/* Keyboard shortcuts hint — hidden on touch devices (shortcuts require a physical keyboard) */
@media (pointer: coarse) {
    .kbd-shortcuts {
        display: none;
    }
}

.kbd-shortcuts {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: #7a8290;
}

.kbd-shortcuts summary {
    cursor: pointer;
    color: #7a8290;
    user-select: none;
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.kbd-shortcuts summary::-webkit-details-marker {
    display: none;
}

.kbd-shortcuts summary::before {
    content: '▶';
    font-size: 0.6rem;
    transition: transform 0.2s ease;
}

.kbd-shortcuts[open] summary::before {
    transform: rotate(90deg);
}

.kbd-shortcuts summary:hover {
    color: #8aafc8;
}

.kbd-shortcuts ul {
    list-style: none;
    margin-top: 0.5rem;
    padding-left: 0.75rem;
}

.kbd-shortcuts li {
    padding: 0.2rem 0;
    color: #7a8290;
}

kbd {
    display: inline-block;
    padding: 0.1rem 0.35rem;
    font-size: 0.8rem;
    border: 1px solid #2a2a2e;
    border-radius: 3px;
    background: #0d0d0f;
    color: #8aafc8;
    font-family: 'Courier New', monospace;
    line-height: 1.4;
}

/* Footer styling */
footer {
    background: rgba(10, 10, 12, 0.97);
    text-align: center;
    padding: 1.5rem;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    color: #7a8290;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Visually hidden — accessible to screen readers, invisible to sighted users */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* Skip navigation link — appears on keyboard focus, hidden otherwise */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 9999;
    padding: 0.75rem 1.5rem;
    background: #8aafc8;
    color: #0d0d0f;
    font-weight: 700;
    font-size: 1rem;
    text-decoration: none;
    border-radius: 0 0 8px 0;
}

.skip-link:focus {
    top: 0;
}

@media (max-width: 768px) and (orientation: portrait) {
    .site-logo {
        display: none;
    }
}

/* Mobile-specific optimizations */
@media (max-width: 768px) {
    section {
        padding: 1.5rem;
        margin-bottom: 1rem;
    }

    section h2 {
        font-size: 1.3rem;
    }

    section p,
    section label {
        font-size: 0.95rem;
    }

    /* Enhanced text selection for mobile copy-paste */
    textarea[readonly] {
        font-size: 16px;
        line-height: 1.5;
        padding: 0.75rem;
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
        -webkit-touch-callout: default;
    }

    /* Feedback message adjustments for mobile */
    .feedback {
        font-size: 0.9rem;
        padding: 1rem;
        text-align: center;
    }

    /* Expand order button touch targets to 44×44 on mobile */
    .order-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 1rem;
    }
}

/* Footer link — GitHub Issues (Uto-htd9) */
.footer-issues {
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.footer-issues a {
    color: #7a8290;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.footer-issues a:hover {
    color: #8aafc8;
}

.optional-label {
    font-size: 0.8em;
    font-weight: 400;
    opacity: 0.7;
}

/* Reduced motion — disable transitions and animations */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* ── Enhanced Output View ──────────────────────────────────────────────────── */

.enhanced-output {
    width: 100%;
}

.output-empty-state {
    text-align: center;
    color: #555566;
    font-size: 0.9rem;
    padding: 2.5rem 1rem;
    border: 1px dashed #2a2a2e;
    border-radius: 8px;
}

.output-empty-state strong {
    color: #7a8290;
    font-weight: 600;
}

.ev-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: start;
}

.ev-column {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    /* align-items: stretch (default) makes all cards expand to the widest card's width */
}

.ev-full-width {
    flex: 0 0 100%;
    width: 100%;
}

/* Content-sized card: shrinks to fit its content (used for Highlights) */
.ev-fit-width {
    flex: 0 0 auto;
    width: fit-content;
    max-width: 100%;
}

.ev-report-header {
    flex: 0 0 100%;
    width: 100%;
    padding-bottom: 0.6rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid #2a2a2e;
}

.ev-report-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #8aafc8;
    margin-bottom: 0.15rem;
}

.ev-report-meta {
    font-size: 0.82rem;
    color: #7a8290;
}

.ev-card {
    flex: 0 0 auto;
    min-width: 220px;
    background: #1a1a1f;
    border: 1px solid #2a2a2e;
    border-left: 3px solid #555566;
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
}

/* Section accent colours applied via inline style border-left-color */

.ev-card-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #8aafc8;
    margin-bottom: 0.4rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid #2a2a2e;
}

.ev-stat-row {
    display: flex;
    align-items: baseline;
    gap: 0.3em;
    padding: 0.12rem 0;
    font-size: 0.85rem;
    color: #d4d8de;
}

.ev-stat-label {
    color: #b8bec8;
    flex-shrink: 0;
}

.ev-stat-value {
    font-weight: 600;
}

.ev-stat-value.ev-pos { color: #68d391; }
.ev-stat-value.ev-neg { color: #fc8181; }

.ev-subsection {
    font-size: 0.78rem;
    font-weight: 700;
    color: #7a8290;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0.5rem 0 0.15rem;
}

.ev-list-item {
    font-size: 0.83rem;
    color: #d4d8de;
    padding: 0.1rem 0 0.1rem 0.75rem;
    position: relative;
}

.ev-list-item::before {
    content: '·';
    position: absolute;
    left: 0;
    color: #555566;
}

.ev-plain-row {
    font-size: 0.85rem;
    color: #d4d8de;
    padding: 0.1rem 0;
}

.ev-divider {
    border: none;
    border-top: 1px solid #2a2a2e;
    margin: 0.4rem 0;
}

.ev-kn-block {
    flex: 0 0 auto;
    min-width: 220px;
    background: #1a1a1f;
    border: 1px solid #2a2a2e;
    border-left: 3px solid #555566;
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
}

.ev-kn-block-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #8aafc8;
    margin-bottom: 0.35rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid #2a2a2e;
}

.ev-kn-block-title.ev-own-kn {
    color: #6a9aba;
}

.ev-kn-block-title.ev-war-kn {
    color: #c87070;
}

.ev-province-row {
    font-size: 0.82rem;
    color: #b8bec8;
    padding: 0.1rem 0 0.1rem 0.5rem;
    border-left: 2px solid #2a2a2e;
    margin-top: 0.15rem;
}

/* ── Mobile ev-card fixes (Uto-b2h1) ────────────────────────────────────── */
@media (max-width: 768px) {
    .ev-card,
    .ev-kn-block {
        padding: 0.75rem 0.8rem;
        margin: 0 0.1rem;
        max-width: 600px;
    }

    /* Allow long values to wrap below their label rather than overflow */
    .ev-stat-row {
        flex-wrap: wrap;
    }

    .ev-stat-value {
        overflow-wrap: break-word;
        word-break: break-word;
        min-width: 0;
    }
}

/* ── Collapsed input section on mobile (Uto-b2kf) ───────────────────────── */
.input-section.collapsed > *:not(h2) {
    display: none !important;
}

.input-section.collapsed {
    cursor: pointer;
    padding-bottom: 0.5rem;
}

.input-section.collapsed h2 {
    cursor: pointer;
    margin-bottom: 0;
}

.input-section.collapsed h2::after {
    content: ' \25B6';
    font-size: 0.7rem;
    color: #7a8290;
    margin-left: 0.5rem;
}

