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

:root {
    --bg: #f5f2ed;
    --fg: #1a1a1a;
    --muted: #8a8580;
    --accent: #c45d3e;
    --border: #d5d0c8;
    --card-bg: #ffffff;
    --hover: #faf8f5;
    --coffee-bg: #ede4d4;
}

.dark {
    --bg: #181714;
    --fg: #e2ddd7;
    --muted: #6b6760;
    --accent: #c45d3e;
    --border: #2e2b27;
    --card-bg: #1f1e1b;
    --hover: #252320;
    --coffee-bg: #26211a;
}

body {
    font-family: 'DM Mono', monospace;
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.3s, color 0.3s;
}

/* ── Top-left bar: coffee + theme ── */

.top-bar {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
}

.top-bar > * { pointer-events: all; }

.theme-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, border-color 0.3s, color 0.2s, transform 0.15s;
}

.coffee-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px 5px 7px;
    background: var(--coffee-bg);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-family: 'DM Mono', monospace;
    font-size: 0.5rem;
    font-weight: 300;
    letter-spacing: 0.05em;
    color: var(--fg);
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    white-space: nowrap;
}

.coffee-btn:hover { border-color: var(--accent); color: var(--accent); }

.coffee-btn img { width: 14px; height: 14px; object-fit: contain; }

.theme-btn:hover {
    color: var(--fg);
    transform: scale(1.08);
}

.theme-btn svg {
    position: absolute;
    transition: opacity 0.25s, transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

:root:not(.dark) .icon-moon { opacity: 1; transform: rotate(0deg); }
:root:not(.dark) .icon-sun  { opacity: 0; transform: rotate(90deg) scale(0.6); }
.dark .icon-moon { opacity: 0; transform: rotate(-90deg) scale(0.6); }
.dark .icon-sun  { opacity: 1; transform: rotate(0deg); }

/* ── Layout ── */

.container {
    width: 100%;
    max-width: 640px;
    padding: 0 24px;
}

header {
    text-align: center;
    padding: 15vh 0 0;
    transition: padding 0.4s ease;
}

header.compact {
    padding: 40px 0 0;
}

h1 {
    font-family: 'Instrument Serif', serif;
    font-size: 3.2rem;
    font-weight: 400;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.subtitle {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 400;
    letter-spacing: 0.01em;
}

/* ── Search ── */

.search-wrap {
    margin-top: 36px;
    position: relative;
}

.search-wrap input {
    width: 100%;
    padding: 14px 20px;
    font-family: 'DM Mono', monospace;
    font-size: 0.9rem;
    font-weight: 300;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 2px;
    color: var(--fg);
    outline: none;
    transition: border-color 0.2s;
}

.search-wrap input::placeholder { color: var(--muted); }
.search-wrap input:focus { border-color: var(--accent); }

.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 2px 2px;
    max-height: 320px;
    overflow-y: auto;
    display: none;
    z-index: 10;
}

.dropdown.visible { display: block; }

.dropdown-item {
    padding: 11px 20px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 300;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.dropdown-item:last-child { border-bottom: none; }

.dropdown-item:hover,
.dropdown-item.active {
    background: var(--hover);
    color: var(--accent);
}

.dropdown-item .match {
    color: var(--accent);
    font-weight: 400;
}

.result-count {
    padding: 9px 20px;
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}

/* ── Climate display ── */

#climate-display {
    margin-top: 32px;
    padding-bottom: 64px;
    width: 100vw;
    display: flex;
    justify-content: center;
}

#climate-display:empty { margin-top: 0; }

#climate-display .table-wrapper {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 32px;
    border-radius: 2px;
    overflow-x: auto;
    max-width: 96vw;
    animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

#climate-display h1 {
    font-family: 'Instrument Serif', serif;
    font-size: 1.6rem;
    margin-bottom: 4px;
}

#climate-display h2 {
    font-family: 'DM Mono', monospace;
    font-size: 0.72rem;
    font-weight: 300;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 16px;
}

#climate-display .source-link {
    font-size: 0.72rem;
    margin: 16px 0;
    padding: 8px 12px;
    background: var(--hover);
    border-left: 2px solid var(--accent);
    font-family: 'DM Mono', monospace;
    font-weight: 300;
}

#climate-display .source-link a {
    color: var(--accent);
    text-decoration: none;
}

#climate-display table {
    font-size: 0.8rem;
    font-family: 'Lora', serif;
}

#climate-display .wikitable td,
#climate-display .wikitable th {
    padding: 0.55em 0.6em;
    height: auto;
    min-height: 2.4em;
    line-height: 1.5;
}

#climate-display .wikitable tr:first-child th {
    padding-top: 10px;
    padding-bottom: 14px;
}

#climate-display .wikitable td[colspan] {
    padding-top: 12px;
    font-family: 'DM Mono', monospace;
    font-size: 0.68rem;
    font-weight: 300;
}

/* ── Dark mode wikitable overrides ── */

.dark #climate-display .wikitable {
    background: var(--card-bg) !important;
    color: var(--fg) !important;
    border-color: var(--border) !important;
}

.dark #climate-display .wikitable th {
    background: #272521 !important;
    color: var(--fg) !important;
    border-color: var(--border) !important;
}

.dark #climate-display .wikitable td {
    border-color: var(--border) !important;
}

/* ── Cross-hair hover highlight ── */

#climate-display .wikitable tr.row-hl > td,
#climate-display .wikitable tr.row-hl > th {
    box-shadow: inset 0 0 0 9999px rgba(196, 93, 62, 0.13);
}

#climate-display .wikitable td.col-hl,
#climate-display .wikitable th.col-hl {
    box-shadow: inset 0 0 0 9999px rgba(196, 93, 62, 0.13);
}

#climate-display .wikitable tr.row-hl > td.col-hl,
#climate-display .wikitable tr.row-hl > th.col-hl {
    box-shadow: inset 0 0 0 9999px rgba(196, 93, 62, 0.28);
    cursor: default;
}

/* ── Footer ── */

footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 14px 24px 18px;
    background: linear-gradient(transparent, var(--bg) 40%);
    pointer-events: none;
    text-align: center;
    font-size: 0.65rem;
    color: var(--muted);
    font-weight: 300;
    letter-spacing: 0.04em;
}

footer a {
    color: var(--muted);
    text-decoration: none;
    pointer-events: all;
}

footer a:hover { color: var(--accent); }

/* ── Unit toggles ── */

.unit-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 22px 0 0;
}

.unit-toggle.visible { display: flex; }

.toggle-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
}

.toggle-pill {
    position: relative;
    display: flex;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 3px;
    cursor: pointer;
    user-select: none;
}

.toggle-pill-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(50% - 3px);
    bottom: 3px;
    background: var(--accent);
    border-radius: 100px;
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-pill.f-active .toggle-pill-slider {
    transform: translateX(100%);
}

.toggle-opt {
    position: relative;
    z-index: 1;
    padding: 5px 18px;
    font-size: 0.72rem;
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--fg);
    transition: color 0.22s;
    border-radius: 100px;
}

.toggle-pill:not(.f-active) .toggle-opt:first-child,
.toggle-pill.f-active .toggle-opt:last-child {
    color: #fff;
}
