:root {
    --bg: #f0f2f5;
    --container-bg: #ffffff;
    --card-bg: #f8f9fa;
    --accent: #1a73e8;
    --accent-hover: rgba(26, 115, 232, 0.08);
    --spinner-track: rgba(26, 115, 232, 0.2);
    --border: #e8eaed;
    --text: #202124;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;
    --error: #d93025;
    --warp-on: #188038;
    --warp-plus: #7b1fa2;
    --history-header: #5f6368;
    --history-cell: #202124;
    --disabled: #c0c0c0;
    --shadow: rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a1a;
        --container-bg: #2d2d2d;
        --card-bg: #383838;
        --accent: #4285f4;
        --accent-hover: rgba(66, 133, 244, 0.15);
        --spinner-track: rgba(66, 133, 244, 0.25);
        --border: #404040;
        --text: #e8eaed;
        --text-secondary: #9aa0a6;
        --warp-on: #4caf50;
        --warp-plus: #ba68c8;
        --history-header: #e8eaed;
        --history-cell: #9aa0a6;
        --disabled: #555;
        --shadow: rgba(0, 0, 0, 0.3);
    }
}

body {
    overflow-wrap: break-word;
    font-family: "Open Sans", sans-serif;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    background-color: var(--bg);
    padding: 8px 10px;
}

.container {
    background-color: var(--container-bg);
    padding: 2.5rem 1rem;
    border-radius: 10px;
    box-shadow: 0 2px 10px var(--shadow);
    text-align: center;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

h1,
.ip-type,
.ip-type a,
.history-toggle {
    color: var(--accent);
}

h1 {
    margin: 1rem 0 2.4rem;
    font-size: 2.6rem;
}

h1 a {
    color: inherit;
    text-decoration: none;
}

.ip-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.ip-card {
    background-color: var(--card-bg);
    border-radius: 8px;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    text-align: center;
}

.ip-card .ip-type {
    width: 110px;
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    text-align: center;
    font-size: 1.25rem;
    font-weight: bold;
    padding: 1rem 0.25rem;
    border-right: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.ip-type a {
    text-decoration: none;
    transition: opacity 0.2s;
}

.ip-type a:hover {
    opacity: 0.8;
}

.ip-card-body {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: 2.4rem 1fr 1fr;
    gap: 0.6rem 0.5rem;
    align-items: stretch;
    align-content: center;
    padding: 1.5rem 0.9rem;
}

/* Unresolved: plain centered flex, empty cells hidden so column gaps don't add phantom space */
.ip-card-body:not(.resolved) {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ip-card-body:not(.resolved)>.ip-cell,
.ip-card-body:not(.resolved)>.ip-address {
    display: none;
}

.ip-type .ip-timer {
    font-size: 0.7rem;
    font-weight: normal;
    color: var(--text-muted);
    margin: 0;
}

.ip-cell {
    min-width: 0;
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.4;
    overflow-wrap: anywhere;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ip-card-body.resolved>.ip-cell+.ip-cell {
    border-left: 1px solid var(--border);
    padding-left: 0.5rem;
}

.ip-address {
    grid-column: 1 / -1;
    font-size: 0.95rem;
    font-style: italic;
    color: var(--text-secondary);
    margin: 0;
    overflow-wrap: anywhere;
}

.ip-card-body.resolved .ip-address {
    border-top: 1px solid var(--border);
    padding-top: 0.6rem;
}

.ip-status {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.25rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.ip-card-body.resolved .ip-status {
    display: none;
}

.ip-card-body.clickable {
    cursor: pointer;
}

.ip-card-mini .ip-type {
    font-size: 1.05rem;
}

.ip-card-mini .ip-card-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 0.9rem;
}

.warp-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 1.4rem;
}

.warp-value {
    font-size: 0.95rem;
    color: var(--text);
}

.warp-on {
    color: var(--warp-on);
}

.warp-plus {
    color: var(--warp-plus);
}

.spinner {
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.15em;
    border: 2px solid var(--spinner-track);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-sm {
    width: 0.85em;
    height: 0.85em;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.raw-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.raw-modal[hidden] {
    display: none;
}

.raw-modal-box {
    background-color: var(--container-bg);
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.raw-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0.6rem 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: bold;
    color: var(--accent);
}

.raw-modal-content {
    margin: 0;
    padding: 1rem;
    overflow: auto;
    text-align: left;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text);
}

.ip-timer {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}

.history-card {
    background-color: var(--card-bg);
    border-radius: 8px;
    margin-top: 1rem;
    padding: 1.4rem 0.5rem 1.6rem;
}

.history-toggle {
    appearance: none;
    border: none;
    background: transparent;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin: 2rem auto 0;
    padding: 0.25rem 0.5rem;
    font-size: 1.05rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 8px;
    transition: opacity 0.2s;
}

.history-toggle:hover {
    opacity: 0.8;
}

.history-toggle svg {
    width: 0.9em;
    height: 0.9em;
    transition: transform 0.2s;
}

.history-toggle.open svg {
    transform: rotate(180deg);
}

.history-table {
    width: 94%;
    border-collapse: collapse;
    margin: 0 auto;
    text-align: center;
}

.history-header {
    padding: 0.75rem;
    font-size: 1rem;
    color: var(--history-header);
}

.history-cell {
    padding: 0.5rem;
    color: var(--history-cell);
}

.history-cell-details {
    font-size: 0.95rem;
    color: var(--text);
}

.history-empty {
    color: var(--text-muted);
}

.history-header,
.history-cell,
.history-cell-details {
    border-bottom: 2px solid var(--border);
}

.col1 {
    width: 35%;
}

.col2 {
    width: 40%;
}

.col3 {
    width: 25%;
    overflow-wrap: anywhere;
}

.history-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin: 1.3rem auto 0;
}

.history-page {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 2.5em;
}

.btn-icon {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--accent);
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.btn-icon:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.btn-icon:disabled {
    color: var(--disabled);
    cursor: default;
}

.btn-icon svg {
    width: 1.05rem;
    height: 1.05rem;
}

/* State class: placed after all component color rules so it always wins the cascade */
.error {
    color: var(--error);
}

@media (max-width: 640px) {
    body {
        padding: 4px 6px;
    }

    .container {
        padding: 1.2rem 1.1rem 1.8rem;
        border-radius: 8px;
    }

    h1 {
        font-size: 2rem;
        margin: 0.3rem 0 1.1rem;
    }

    .ip-cards {
        gap: 0.8rem;
    }

    .ip-card .ip-type {
        width: 76px;
        font-size: 1.05rem;
        padding: 0.35rem 0.15rem;
    }

    .ip-card-body,
    .ip-card-mini .ip-card-body {
        padding: 0.5rem 0.7rem;
    }

    /* Two-column layout: country code spans both info rows,
       city + ISP merge into the second column as two rows */
    .ip-card-body {
        grid-template-columns: 2.2rem 1fr;
        gap: 0.35rem 0.5rem;
    }

    .ip-card-body.resolved .ip-cc {
        grid-row: 1 / 3;
    }

    .ip-card-body.resolved .ip-isp {
        grid-column: 2;
    }

    .ip-type .ip-timer {
        font-size: 0.68rem;
    }

    .ip-cell,
    .ip-status,
    .ip-address,
    .warp-value {
        font-size: 0.92rem;
    }

    .ip-timer {
        font-size: 0.78rem;
    }

    .ip-card-mini .ip-type {
        font-size: 1rem;
    }

    .history-card {
        padding: 1.2rem 0.3rem 1.4rem;
    }

    .history-toggle {
        font-size: 1rem;
    }

    .history-header {
        font-size: 0.9rem;
    }

    .history-cell,
    .history-cell-details {
        font-size: 0.85rem;
    }

    .btn-icon {
        width: 1.9rem;
        height: 1.9rem;
    }

    .history-page {
        font-size: 0.82rem;
    }
}
