/* =====================================
   FONT
   Railway by Greg Fleming, an open-source
   version of Edward Johnston's 1916 Underground
   typeface (SIL Open Font License, see fonts/).
   It only comes in one weight, so text is set
   at 400 rather than letting the browser fake bold.
   ===================================== */

@font-face {
    font-family: "Railway";
    src:
        url("fonts/railway.woff") format("woff"),
        url("fonts/Railway.otf") format("opentype");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

:root {
    --page: #f5f5f5;   /* replaced daily with a tube line colour by game.js */
    --on-page: #ffffff;  /* text on the page colour; black on light lines */
    --card: #ffffff;
    --panel: #ffffff;
    --ink: #111111;
    --border: #d3d3d3;          /* thin outlines on cards, map and pills */
    --border-strong: #b5b5b5;
    --placeholder: #9a9a9a;
    --wrong: #fdf3d8;
    --wrong-border: #e5b53f;
    --far: #eeeeee;
    --far-border: #c8c8c8;
    --correct: #6aaa64;
    --hover: #f3f3f3;
    --radius: 12px;

    --font: "Railway", "Gill Sans", "Gill Sans MT", -apple-system,
        BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;

    /* Sizes below are for phones; tablet and desktop override them */
    --card-width: 440px;
    --card-padding: 14px;
    --title-top: 10px;
    --title-spacing: 0.05em;
    --row-height: 52px;
    --row-text: 18px;
    --gap: 10px;
    --label-size: 18px;   /* in map units; the map shrinks on phones */
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;

    position: relative;
    overflow-x: hidden;

    /* Bottom padding leaves room to scroll past the test button */
    padding: 0 16px 80px;

    display: flex;
    flex-direction: column;
    align-items: center;

    background-color: var(--page);

    font-family: var(--font);
    font-weight: 400;
    font-synthesis: none;
    color: var(--ink);
}


/* =====================================
   TITLE
   Giant white lettering fixed behind the page.
   game.js sizes it to fill the screen width, stores
   its height in --title-height, and reveals extra
   copies of the title underneath as the page scrolls.
   ===================================== */

.title-stack {
    position: fixed;
    top: var(--title-top);
    left: 0;
    right: 0;
    z-index: 0;

    text-align: center;
    white-space: nowrap;
    color: var(--on-page);

    font-size: 15vw;   /* rough size until game.js measures it */
    font-weight: 400;

    /* Railway has no bold, so thicken the strokes */
    -webkit-text-stroke: 0.045em currentColor;

    /* Extra room between letters, since the thicker strokes close the gaps */
    letter-spacing: var(--title-spacing);

    pointer-events: none;
    user-select: none;
}

.title,
.title-repeat {
    margin: 0;

    /* Letter-spacing also adds a gap after the last letter; matching
       it on the left keeps the words centred */
    padding-left: var(--title-spacing);
    font-size: 1em;
    font-weight: 400;
    line-height: 0.78;
}

.title-repeat {
    margin-top: 0.08em;
    opacity: 0;
    transform: translateY(-20%);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.title-repeat.shown {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    .title-repeat {
        transform: none;
        transition: none;
    }
}


/* =====================================
   CARD
   ===================================== */

/* On phones the card sits just below the title */
.game {
    position: relative;
    z-index: 2;   /* above the rules card, so the dropdown can overlap it */

    width: 100%;
    max-width: var(--card-width);
    margin-top: calc(var(--title-top) + var(--title-height, 13vw) + 14px);
    padding: var(--card-padding);

    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}


/* =====================================
   RULES
   ===================================== */

.rules {
    position: relative;
    z-index: 1;

    width: 100%;
    max-width: var(--card-width);
    margin-top: 16px;
    padding: 20px 22px;

    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);

    font-size: 17px;
    line-height: 1.45;
}

.rules h2 {
    margin: 0 0 10px;
    font-size: 26px;
    font-weight: 400;
}

.rules p {
    margin: 0 0 12px;
}

.rules ol {
    margin: 0;
    padding-left: 22px;
}

.rules li + li {
    margin-top: 6px;
}


/* =====================================
   CREDIT
   ===================================== */

.credit {
    position: relative;
    z-index: 1;

    margin-top: 28px;
    padding: 6px 16px;

    /* Its own backing, so it stays readable over the big background title */
    background: var(--page);
    border-radius: 999px;

    text-align: center;
    font-size: 15px;
    color: var(--on-page);
}

.credit a {
    color: inherit;
}


/* =====================================
   MAP
   ===================================== */

.map-container {
    padding: 6px;

    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

#tube-map {
    width: 100%;
    display: block;
}

.tube-line {
    stroke-width: 10;
    stroke-linecap: butt;
    transition: stroke 0.5s ease;
}

/* The white outline cuts a small gap between line and dot */
/* A thin white outline keeps side-by-side dots (12 apart) from merging */
.stop {
    stroke: var(--panel);
    stroke-width: 1.5;
    transition: fill 0.5s ease, opacity 0.5s ease;
}

/* End dots stay hidden until the next stops are revealed */
.stop.hidden {
    opacity: 0;
}

/* White circle with a black ring, like an interchange on the tube map */
.central-station {
    fill: #ffffff;
    stroke: var(--ink);
    stroke-width: 9;
}

.station-label {
    font-family: var(--font);
    font-size: var(--label-size);
    fill: var(--ink);
    transition: opacity 0.5s ease;

    /* White halo keeps labels readable where they cross a line */
    stroke: var(--panel);
    stroke-width: 5px;
    stroke-linejoin: round;
    paint-order: stroke;
}

.station-label.hidden {
    opacity: 0;
}

/* Small name written inside each line once the colours show */
.line-name {
    font-family: var(--font);
    font-size: 7px;   /* in map units: fits inside the 10-wide line */
    letter-spacing: 0.02em;
    pointer-events: none;
    transition: opacity 0.5s ease, fill 0.5s ease;
}

.line-name.hidden {
    opacity: 0;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}


/* =====================================
   ANSWER + GUESS ROWS
   ===================================== */

.answer-area {
    position: relative;
    margin-top: var(--gap);
}

#answer-input,
.row {
    width: 100%;
    height: var(--row-height);
    padding: 0 22px;

    display: flex;
    align-items: center;

    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: 999px;

    font-family: var(--font);
    font-size: var(--row-text);   /* 16px or more stops iOS zooming in */
    font-weight: 400;
    color: var(--ink);
}

#answer-input {
    outline: none;
    -webkit-appearance: none;
    appearance: none;

    /* Small arrow on the right so it reads as a dropdown */
    padding-right: 48px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23111' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 22px center;
    background-size: 12px 8px;
}

#answer-input::placeholder {
    color: var(--placeholder);
}

#answer-input:focus {
    border-color: var(--ink);
}

#result {
    margin-top: var(--gap);
}

#guesses {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    margin-top: var(--gap);
}

/* Wrong but within a few stops of the answer */
.row.close {
    background: var(--wrong);
    border-color: var(--wrong-border);
}

/* Wrong and further away */
.row.far {
    background: var(--far);
    border-color: var(--far-border);
}

.row.correct {
    background: var(--correct);
    border-color: var(--correct);
    color: #ffffff;
}

.row.revealed {
    background: var(--ink);
    border-color: var(--ink);
    color: #ffffff;
}

.row {
    animation: fade-in 0.3s ease;
}

/* Once the game ends: Play another (unlimited) or a link to unlimited (daily) */
.next-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: var(--row-height);
    margin-top: var(--gap);

    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;

    font-family: var(--font);
    font-size: var(--row-text);
    text-decoration: none;
    cursor: pointer;
    animation: fade-in 0.3s ease;
}

.next-button:hover {
    background: var(--hover);
}


/* =====================================
   DROPDOWN
   ===================================== */

.suggestions {
    position: absolute;
    top: calc(var(--row-height) + 6px);
    left: 0;
    right: 0;
    z-index: 10;

    /* Short enough to stay above a phone's on-screen keyboard */
    max-height: min(300px, 40vh);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 4px;
    list-style: none;

    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.suggestions li {
    padding: 12px 18px;
    border-radius: 8px;

    font-size: var(--row-text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.suggestions li.active {
    background: var(--hover);
}

/* Only show hover on devices with a real pointer, so taps don't stick */
@media (hover: hover) {
    .suggestions li:hover {
        background: var(--hover);
    }
}

.suggestions li.empty {
    color: var(--placeholder);
    cursor: default;
    background: none;
}


/* =====================================
   LANDING SCREEN
   Covers the game until Play is pressed. Uses the
   same daily tube-line colour as the page.
   ===================================== */

body.on-landing {
    overflow: hidden;
}

.landing {
    position: fixed;
    inset: 0;
    z-index: 15;   /* above the game, below the test button */

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;

    background: var(--page);
    color: var(--on-page);
    text-align: center;

    transition: opacity 0.3s ease;
}

.landing.leaving {
    opacity: 0;
    pointer-events: none;
}

.landing-title {
    margin: 0;

    font-size: min(14vw, 120px);
    line-height: 0.8;
    white-space: nowrap;

    /* Same treatment as the background title */
    -webkit-text-stroke: 0.045em currentColor;
    letter-spacing: var(--title-spacing);
    padding-left: var(--title-spacing);
}

.landing-text {
    max-width: 22em;
    margin: 28px 0 0;

    font-size: clamp(19px, 2.2vw, 26px);
    line-height: 1.35;
}

.play-button {
    min-width: min(300px, 100%);
    height: 58px;
    margin-top: 36px;
    padding: 0 40px;

    background: #ffffff;
    color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;

    font-family: var(--font);
    font-size: 20px;

    cursor: pointer;
    transition: transform 0.15s ease;
}

.play-button:hover {
    transform: scale(1.03);
}

.play-button:focus-visible {
    outline: 3px solid var(--on-page);
    outline-offset: 3px;
}

/* Link to unlimited.html: an outline version of the Play button */
.unlimited-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 14px;

    background: transparent;
    color: var(--on-page);
    border-color: var(--on-page);

    text-decoration: none;
}

.landing-date {
    margin: 30px 0 0;
    font-size: 20px;
}

@media (prefers-reduced-motion: reduce) {
    .landing,
    .play-button {
        transition: none;
    }
}


/* =====================================
   END-OF-GAME POP-UP
   ===================================== */

.popup {
    width: min(400px, calc(100% - 32px));
    padding: 0;

    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--border);
    border-top: 8px solid var(--page);   /* today's line colour */
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);

    font-family: var(--font);
    text-align: center;
}

.popup[open] {
    animation: popup-in 0.3s ease;
}

.popup-body {
    position: relative;
    padding: 36px 28px 28px;
}

.popup::backdrop {
    background: rgba(0, 0, 0, 0.45);
}

@keyframes popup-in {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

.popup-heading {
    margin: 0;
    font-size: 26px;
    font-weight: 400;
}

.popup-station {
    margin: 16px 0 0;
    font-size: 38px;
    line-height: 1.1;
}

/* A darker green than the guess pill, so the name is easy to read */
.popup.won .popup-station {
    color: #3f7f3a;
}

.popup-message {
    margin: 16px 0 0;
    font-size: 19px;
}

.popup-close {
    min-width: 160px;
    height: 50px;
    margin-top: 26px;
    padding: 0 32px;

    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;

    font-family: var(--font);
    font-size: 18px;
    cursor: pointer;
}

.popup-close:hover {
    background: var(--hover);
}

/* Play another (or Play unlimited) sits beside Close */
.popup-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 26px;
}

.popup-buttons .popup-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 140px;
    margin-top: 0;
    text-decoration: none;
}

.popup-next {
    background: var(--ink);
    color: #ffffff;
}

.popup-next:hover {
    background: #333333;
}

@media (prefers-reduced-motion: reduce) {
    .popup[open] {
        animation: none;
    }
}


/* =====================================
   SIDE MENU
   Burger button in the bottom-left corner opens a
   panel that slides in from the left, blurring
   the page behind it.
   ===================================== */

.menu-button {
    position: fixed;
    left: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 25;   /* above the landing screen and the corner buttons */

    width: 44px;
    height: 44px;
    padding: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;

    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.menu-button svg {
    width: 20px;
    height: 14px;
}

.menu-button:hover {
    background: var(--hover);
}

.menu-button:focus-visible {
    outline: 3px solid var(--on-page);
    outline-offset: 3px;
}

.side-menu {
    /* Undo the browser's centred dialog so it hugs the left edge */
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 85vw);
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;

    background: var(--card);
    color: var(--ink);
    border: none;
    border-right: 8px solid var(--page);   /* today's line colour */
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);

    font-family: var(--font);
}

.side-menu[open] {
    animation: menu-in 0.3s ease;
}

.side-menu.closing {
    animation: menu-out 0.25s ease forwards;
}

.side-menu::backdrop {
    background: rgba(0, 0, 0, 0.25);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.side-menu[open]::backdrop {
    animation: fade-in 0.3s ease;
}

.side-menu.closing::backdrop {
    animation: fade-out 0.25s ease forwards;
}

@keyframes menu-in {
    from { transform: translateX(-100%); }
    to { transform: none; }
}

@keyframes menu-out {
    from { transform: none; }
    to { transform: translateX(-100%); }
}

@keyframes fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

.menu-body {
    height: 100%;
    padding: calc(24px + env(safe-area-inset-top)) 22px calc(24px + env(safe-area-inset-bottom));

    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.menu-close {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    right: 14px;

    width: 40px;
    height: 40px;
    padding: 0;

    background: none;
    color: var(--ink);
    border: none;
    border-radius: 999px;

    font-family: var(--font);
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
}

.menu-close:hover {
    background: var(--hover);
}

.menu-close:focus-visible,
.menu-link:focus-visible,
.menu-footer a:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 3px;
}

.menu-title {
    margin: 6px 0 0;
    padding-left: var(--title-spacing);

    font-size: 34px;
    line-height: 0.9;
    letter-spacing: var(--title-spacing);
    -webkit-text-stroke: 0.045em currentColor;   /* same as the big title */
}

.menu-links {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    margin-top: 32px;
}

/* Pills like the guess rows; the page you're on is filled in */
.menu-link {
    display: flex;
    align-items: center;
    height: var(--row-height);
    padding: 0 22px;

    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;

    font-size: var(--row-text);
    text-decoration: none;
}

.menu-link:hover {
    background: var(--hover);
}

.menu-link[aria-current="page"] {
    background: var(--ink);
    color: #ffffff;
}

/* Pinned to the bottom of the panel */
.menu-footer {
    margin-top: auto;
    padding-top: 24px;
    border-top: 1px solid var(--border);

    font-size: 16px;
    line-height: 1.4;
}

.menu-footer p {
    margin: 0;
}

.menu-footer p + p {
    margin-top: 6px;
}

.menu-footer a {
    color: inherit;
    overflow-wrap: anywhere;   /* long email address on narrow phones */
}

@media (prefers-reduced-motion: reduce) {
    .side-menu[open],
    .side-menu.closing,
    .side-menu[open]::backdrop,
    .side-menu.closing::backdrop {
        animation: none;
    }
}


/* =====================================
   EASY MODE LINK
   ===================================== */

.easy-mode {
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 20;

    padding: 10px 16px;

    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 999px;

    font-family: var(--font);
    font-size: 15px;
    text-decoration: none;
}

.easy-mode:hover {
    background: var(--hover);
}

.easy-mode:focus-visible {
    outline: 3px solid var(--on-page);
    outline-offset: 3px;
}

/* Only offered once the game is showing */
body.on-landing .easy-mode {
    display: none;
}


/* =====================================
   TEST BUTTON
   ===================================== */

.test-button {
    position: fixed;
    left: 72px;   /* beside the burger button */
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 20;

    padding: 10px 14px;

    background: var(--ink);
    color: #ffffff;
    border: none;
    border-radius: 999px;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);   /* visible on the black Northern day */

    font-family: var(--font);
    font-size: 14px;

    cursor: pointer;
    opacity: 0.85;
}

.test-button:hover {
    opacity: 1;
}


/* =====================================
   TABLET (600px and up)
   ===================================== */

@media (min-width: 600px) {

    :root {
        --card-width: 520px;
        --card-padding: 20px;
        --title-top: 14px;
        --row-height: 56px;
        --row-text: 19px;
        --gap: 12px;
        --label-size: 15px;
    }

    body {
        padding: 0 24px 96px;
    }

    /* Wider screens: the card overlaps the lower part of the title */
    .game {
        margin-top: calc(var(--title-top) + var(--title-height, 13vw) * 0.55);
    }
}


/* =====================================
   DESKTOP (1024px and up)
   ===================================== */

@media (min-width: 1024px) {

    :root {
        --card-width: 540px;
    }
}
