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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f4f8;
    color: #1a2840;
    min-height: 100vh;
    padding: 2rem 1rem 3rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

h1 {
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 2.1rem;
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: #1a2840;
    text-align: left;
    flex: 1 1 auto;
    margin: 0;
    min-width: 0;
}

.page-header__locale {
    position: relative;
    display: flex;
    justify-content: flex-end;
    flex: 0 0 auto;
    width: 3.45rem;
    height: 2rem;
    border: 1px solid rgba(125, 142, 161, 0.35);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
    overflow: hidden;
}

.page-header__locale::before {
    content: attr(data-current-flag);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-right: 0.6rem;
    font-size: 1rem;
    line-height: 1;
    pointer-events: none;
}

.page-header__locale::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 0.65rem;
    width: 0.38rem;
    height: 0.38rem;
    border-right: 1.5px solid #6f8094;
    border-bottom: 1.5px solid #6f8094;
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

.page-header__locale-select {
    width: 100%;
    min-width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: transparent;
    font-size: 1rem;
    line-height: 1;
    box-shadow: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.page-header__locale-select:focus {
    outline: 0;
}

.page-header__locale:focus-within {
    border-color: #4477aa;
    box-shadow: 0 0 0 3px rgba(68, 119, 170, 0.18);
}

.page-header__locale-select option {
    color: #1a2840;
}

.controls {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    margin-bottom: 1.5rem;
}

.controls__country {
    min-width: 0;
    font-size: 1.08rem;
    font-weight: 600;
    color: #1a2840;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.controls__pickers {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    min-width: 0;
    grid-column: 2 / 4;
}

select {
    width: 100%;
    background: #ffffff;
    color: #1a2840;
    border: 1px solid #c0ccd8;
    border-radius: 7px;
    padding: 0.45rem 1rem;
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus {
    outline: none;
    border-color: #4477aa;
    box-shadow: 0 0 0 3px rgba(68, 119, 170, 0.18);
}

.chart-container {
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    position: relative;
    /* Height lives here, not on the canvas, so Chart.js reads the container
       on every resize and picks up the updated vw value correctly. */
    height: 80vw;
}

.chart-header {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 2.75rem;
    margin: 0 0 1rem;
}

.chart-header__title {
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 2rem;
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: #1a2840;
    text-align: center;
}

/* The canvas fills its container; Chart.js controls the pixel dimensions. */
#tideChart {
    width: 100%;
    height: 100%;
}

.status {
    min-height: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.today-card {
    background: #ffffff;
    border: 1px solid rgba(125, 158, 187, 0.18);
    border-radius: 14px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.10);
    padding: 1rem 1.15rem;
    margin-bottom: 1rem;
}

.today-card__header {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 1rem;
    margin-bottom: 0.75rem;
    padding-right: 1.8rem;
    list-style: none;
    cursor: pointer;
}

.today-card__header::-webkit-details-marker {
    display: none;
}

.today-card__title-wrap {
    display: grid;
    gap: 0.1rem;
    min-width: 0;
    align-self: center;
}

.today-card__title-line {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.45rem 0.6rem;
    min-width: 0;
}

.today-card__eyebrow {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #2d7fb9;
}

.today-card__date {
    font-size: 0.98rem;
    font-weight: 700;
    color: #1a2840;
    white-space: nowrap;
}

.today-card__toggle {
    position: absolute;
    top: 0.2rem;
    right: 0;
    width: 1rem;
    height: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.today-card__toggle::before {
    content: "";
    width: 0.42rem;
    height: 0.42rem;
    border-right: 2px solid #60758f;
    border-bottom: 2px solid #60758f;
    transform: rotate(-45deg);
    transform-origin: center;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.today-card[open] .today-card__toggle,
.today-card__header:hover .today-card__toggle {
    color: inherit;
}

.today-card[open] .today-card__toggle::before {
    transform: rotate(45deg);
}

.today-card[open] .today-card__toggle::before,
.today-card__header:hover .today-card__toggle::before {
    border-color: #2d7fb9;
}

.today-card__body {
    display: grid;
    gap: 0.8rem;
    padding-right: 1.8rem;
}

.today-card__quick-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.7rem;
    flex: 0 1 calc(50% - 0.35rem);
    width: calc(50% - 0.35rem);
    max-width: calc(50% - 0.35rem);
    min-width: 0;
    align-self: center;
    justify-content: end;
}

.today-card__grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.7rem;
}

.today-card__item {
    display: grid;
    gap: 0.22rem;
    padding: 0.7rem 0.8rem;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(68, 119, 170, 0.10);
    border-radius: 12px;
}

.today-card__item--quick {
    gap: 0.12rem;
    padding: 0.48rem 0.62rem 0.52rem;
    background: rgba(45, 127, 185, 0.05);
    border-color: rgba(45, 127, 185, 0.10);
    border-radius: 10px;
    min-width: 0;
}

.today-card__label {
    display: flex;
    align-items: center;
    gap: 0.38rem;
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #667788;
    min-width: 0;
    overflow: hidden;
}

.today-card__label .tsm-chart-tooltip__icon {
    flex: 0 0 auto;
}

.today-card__label > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.today-card__value {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.55rem;
    min-width: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #1a2840;
}

.today-card__value-main {
    min-width: 0;
    overflow-wrap: anywhere;
}

.today-card__item--quick .today-card__value {
    font-size: 0.96rem;
}

.today-card__item--quick .today-card__label {
    font-size: 0.68rem;
    letter-spacing: 0.06em;
}

.today-card__value-offset {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 500;
    color: #92a3b5;
    white-space: nowrap;
}

.today-card__message {
    font-size: 0.9rem;
    color: #667788;
}

.error {
    color: #cc2222;
    background: rgba(200, 30, 30, 0.07);
    border: 1px solid rgba(200, 30, 30, 0.25);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: none;
}

.loading {
    color: #667788;
    display: none;
}

.credits {
    margin-top: 0.9rem;
    font-size: 0.82rem;
    color: #778899;
    text-align: center;
    line-height: 1.5;
}

.credits__line {
    display: block;
    margin-bottom: 0.5rem;
}

.credits a {
    color: #4477aa;
    text-decoration: none;
}

.credits a:hover {
    text-decoration: underline;
}

.disclaimer,
.version-info {
    display: block;
    font-size: 0.72rem;
    line-height: 1.4;
    color: #aabbcc;
}

.tsm-chart-tooltip {
    position: absolute;
    left: 0;
    top: 0;
    width: min(18rem, calc(100% - 1rem));
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(69, 98, 124, 0.18);
    border-radius: 12px;
    box-shadow: 0 14px 36px rgba(22, 39, 60, 0.16);
    color: #1a2840;
    font-size: 0.86rem;
    line-height: 1.35;
    padding: 0.75rem 0.8rem;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, calc(-100% - 0.4rem));
    transition: opacity 0.14s ease;
    z-index: 5;
}

.tsm-chart-tooltip.is-visible {
    opacity: 1;
}

.tsm-chart-tooltip__title {
    font-weight: 700;
    margin-bottom: 0.45rem;
}

.tsm-chart-tooltip__body {
    display: grid;
    gap: 0.3rem;
}

.tsm-chart-tooltip__row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.45rem;
}

.tsm-chart-tooltip__divider {
    height: 1px;
    background: rgba(68, 119, 170, 0.14);
    margin: 0.1rem 0 0.2rem;
}

.tsm-chart-tooltip__label {
    color: #42556e;
}

.tsm-chart-tooltip__value {
    font-weight: 600;
    text-align: right;
}

.tsm-chart-tooltip__icon {
    width: 1rem;
    height: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tsm-chart-tooltip__icon svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.tsm-chart-tooltip__icon--sunrise {
    color: #d28b16;
}

.tsm-chart-tooltip__icon--sunset {
    color: #c45b3c;
}

.tsm-chart-tooltip__icon--tide {
    color: #2d7fb9;
}

.tsm-chart-tooltip__icon--now {
    color: #5c7896;
}

.tsm-chart-tooltip__icon--air {
    color: #ba7a2a;
}

.tsm-chart-tooltip__icon--water {
    color: #2d7fb9;
}

.tsm-chart-tooltip__icon--moonrise {
    color: #6078b8;
}

.tsm-chart-tooltip__icon--moonset {
    color: #7b6aa9;
}

.tsm-chart-tooltip__icon--moon {
    font-size: 0.95rem;
    line-height: 1;
}

/* ── Narrow desktop / wide tablet ─────────────────────────────────────────── */
@media (max-width: 1023px) and (min-width: 481px) {
    .today-card__value {
        flex-wrap: wrap;
        gap: 0.2rem 0.45rem;
    }

    .today-card__value-offset {
        flex-basis: 100%;
        margin-left: 0;
        text-align: left;
    }
}

/* ── Tablet ────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    body {
        padding: 1.25rem 1rem 2rem;
    }

    .page-header {
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    h1 {
        font-size: 1.65rem;
    }

    .today-card__quick-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .today-card__grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

}

@media (max-width: 640px) {
    .controls {
        grid-template-columns: 1fr;
        gap: 0.55rem;
    }

    .controls__country {
        font-size: 0.98rem;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }

    .controls__pickers {
        grid-column: 1 / -1;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .today-card__header {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 0.7rem;
    }

    .today-card__quick-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
        max-width: none;
        flex: none;
        justify-content: stretch;
    }

    .today-card__item--quick .today-card__value {
        gap: 0.2rem 0.45rem;
    }

    .today-card__item--quick .today-card__value-offset {
        margin-left: 0;
    }
}


/* ── Mobile portrait — double height so the chart fills the screen ─────────── */
@media (max-width: 480px) and (orientation: portrait) {
    .chart-container {
        height: 160vw;
    }
}

/* ── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    body {
        padding: 1rem 0.5rem 1.5rem;
    }

    .page-header {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    h1 {
        font-size: 1.28rem;
        text-align: left;
        min-width: 0;
    }

    .page-header__locale {
        justify-content: flex-end;
        margin-left: auto;
    }

    .page-header__locale-select {
        min-width: 100%;
        max-width: 100%;
    }

    .controls {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.55rem;
        width: 100%;
    }

    .controls__country {
        grid-column: 1 / -1;
        font-size: 0.9rem;
    }

    .controls__pickers {
        grid-column: 1 / -1;
        width: 100%;
        gap: 0.55rem;
    }

    .controls select {
        padding: 0.45rem 0.75rem;
        font-size: 0.9rem;
    }

    .today-card {
        padding: 0.9rem;
    }

    .today-card__header {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
        gap: 0.7rem;
        padding-right: 1.6rem;
    }

    .today-card__body {
        padding-right: 1.6rem;
    }

    .today-card__toggle {
        top: 0.1rem;
    }

    .today-card__title-wrap {
        align-items: center;
        text-align: center;
        gap: 0.12rem;
        min-width: 0;
    }

    .today-card__title-line {
        justify-content: center;
    }

    .today-card__quick-grid {
        display: contents;
    }

    .today-card__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .today-card__item--quick .today-card__value {
        flex-wrap: nowrap;
        gap: 0.3rem 0.45rem;
    }

    .today-card__item--quick .today-card__value-offset {
        margin-left: auto;
        text-align: right;
    }

    .chart-container {
        padding: 0;
    }

    .chart-header {
        min-height: 2.2rem;
        margin-bottom: 0.3rem;
    }

    .chart-header__title {
        font-size: 1.28rem;
    }

    .credits {
        font-size: 0.75rem;
    }
}
