/* ==========================================================================
   Skattegränsen – The Game
   Myndighetsestetik: papper, bläck, stämplar och blanketter.
   ========================================================================== */

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

html {
    font-size: 16px;
}

/* --------------------------------------------------------------------------
   Designtokens
   -------------------------------------------------------------------------- */
:root {
    /* Papper & bläck */
    --paper: #efece2;
    --card: #fdfcf6;
    --card-edge: #ddd6c3;
    --ink: #23201a;
    --ink-soft: #5b5443;
    --ink-faint: #8d8471;
    --line: #d6cfba;
    --field: #f5f2e8;

    /* Ålands flagga */
    --aland-blue: #0053a5;
    --aland-yellow: #ffce00;
    --aland-red: #d21034;

    /* Stämplar */
    --stamp-red: #b3202f;
    --stamp-green: #1d7a44;
    --stamp-blue: #26558f;

    /* Resurser */
    --money-1: #a97f14;
    --money-2: #e0b53a;
    --patience-1: #2c7a4d;
    --patience-2: #5cb182;
    --danger: #b3202f;
    --success: #1d7a44;

    --shadow-card: 0 1px 2px rgba(35, 32, 26, 0.08), 0 14px 40px rgba(35, 32, 26, 0.12);
    --shadow-soft: 0 1px 2px rgba(35, 32, 26, 0.06), 0 6px 18px rgba(35, 32, 26, 0.08);
    --radius: 10px;

    --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
    --font-body: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

/* Mörkt läge är ett aktivt val via 🌙-knappen (sparas i localStorage) –
   pappersblanketten är ljus som standard oavsett systeminställning. */
:root[data-theme='dark'] {
        --paper: #16140f;
        --card: #201d16;
        --card-edge: #37321f;
        --ink: #ece7d8;
        --ink-soft: #b5ac97;
        --ink-faint: #857c67;
        --line: #3d382a;
        --field: #262218;

        --stamp-red: #e05a66;
        --stamp-green: #4fae77;
        --stamp-blue: #6d9bd6;

        --money-1: #c69a24;
        --money-2: #e8c257;
        --patience-1: #3d9563;
        --patience-2: #6fc493;
        --danger: #e05a66;
        --success: #4fae77;

        --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 40px rgba(0, 0, 0, 0.5);
        --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.35);
}

body {
    font-family: var(--font-body);
    line-height: 1.6;
    color: var(--ink);
    background:
        repeating-linear-gradient(0deg, transparent 0 2px, rgba(35, 32, 26, 0.012) 2px 4px),
        radial-gradient(1100px 600px at 15% -10%, rgba(0, 83, 165, 0.05), transparent 60%),
        radial-gradient(900px 500px at 110% 10%, rgba(210, 16, 52, 0.04), transparent 55%),
        var(--paper);
    min-height: 100vh;
    padding: 20px 12px 40px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Ålandsflaggan som list högst upp (tvärsnitt genom korsets arm) */
.flag-stripe {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    z-index: 100;
    background: linear-gradient(
        180deg,
        var(--aland-blue) 0 28%,
        var(--aland-yellow) 28% 42%,
        var(--aland-red) 42% 58%,
        var(--aland-yellow) 58% 72%,
        var(--aland-blue) 72% 100%
    );
}

/* --------------------------------------------------------------------------
   Dokumentet (spelbehållaren)
   -------------------------------------------------------------------------- */
.game-container {
    max-width: 920px;
    margin: 0 auto;
    background: var(--card);
    border: 1px solid var(--card-edge);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    min-height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Hålslag i marginalen, som på ett arkiverat dokument */
.game-container::before {
    content: '';
    position: absolute;
    top: 150px;
    left: 14px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--paper);
    box-shadow:
        inset 0 1px 2px rgba(35, 32, 26, 0.25),
        0 220px 0 0 var(--paper);
    opacity: 0.9;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Sidhuvud
   -------------------------------------------------------------------------- */
.game-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 26px 28px 20px;
    border-bottom: 3px double var(--line);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.brand-seal {
    flex: 0 0 auto;
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    color: var(--stamp-blue);
    border: 2px solid var(--stamp-blue);
    border-radius: 50%;
    box-shadow: inset 0 0 0 3px var(--card), inset 0 0 0 4px var(--stamp-blue);
    transform: rotate(-6deg);
    opacity: 0.85;
}

.brand-eyebrow {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 4px;
}

.game-title {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(1.5rem, 4.2vw, 2.2rem);
    line-height: 1.1;
    letter-spacing: -0.01em;
    color: var(--ink);
}

.game-subtitle {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 0.98rem;
    color: var(--ink-soft);
    margin-top: 4px;
}

.header-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 0 0 auto;
    padding-top: 4px;
}

.audio-toggle,
.change-role-button,
.change-role-button-inline {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.audio-toggle {
    font-size: 1rem;
    padding: 6px 10px;
    line-height: 1;
}

@media (hover: hover) and (pointer: fine) {
    .audio-toggle:hover,
    .change-role-button:hover,
    .change-role-button-inline:hover {
        border-color: var(--aland-blue);
        color: var(--aland-blue);
    }
}

.audio-toggle:active,
.change-role-button:active,
.change-role-button-inline:active {
    transform: scale(0.96);
}

/* --------------------------------------------------------------------------
   Skärmar
   -------------------------------------------------------------------------- */
.game-main {
    flex: 1;
    padding: 26px 28px 34px;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
    animation: screenIn 0.4s ease both;
}

@keyframes screenIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* --------------------------------------------------------------------------
   Val av ärendetyp (roller)
   -------------------------------------------------------------------------- */
.role-cards h3 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.45rem;
    text-align: center;
    color: var(--ink);
}

.role-note {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
    margin: 6px 0 24px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.role-card {
    position: relative;
    background: var(--card);
    border: 1px solid var(--card-edge);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 20px 20px 18px;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    outline: none;
}

/* Streckad "blankettram" innanför kortet */
.role-card::after {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px dashed var(--line);
    border-radius: calc(var(--radius) - 4px);
    pointer-events: none;
}

.role-card:focus-visible {
    transform: translateY(-3px);
    box-shadow: var(--shadow-card);
    border-color: var(--aland-blue);
}

@media (hover: hover) and (pointer: fine) {
    .role-card:hover {
        transform: translateY(-3px);
        box-shadow: var(--shadow-card);
        border-color: var(--aland-blue);
    }
}

.role-card:focus-visible {
    outline: 2px solid var(--aland-blue);
    outline-offset: 2px;
}

.role-card.selected {
    border-color: var(--aland-blue);
    box-shadow: 0 0 0 2px var(--aland-blue), var(--shadow-card);
}

.card-code {
    position: absolute;
    top: 14px;
    right: 16px;
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 2px 7px;
    background: var(--field);
}

.role-icon {
    font-size: 2.1rem;
    line-height: 1;
    margin-bottom: 10px;
}

.role-card h4 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.18rem;
    color: var(--ink);
    margin-bottom: 6px;
}

.role-card p {
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--ink-soft);
}

/* Personligt rekord på rollkortet */
.role-best {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--stamp-blue);
    margin-top: 10px;
    min-height: 1em;
}

.role-best:empty {
    display: none;
}

/* Svårighetsgrad som gummistämpel */
.difficulty {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    padding: 3px 9px;
    border: 1.5px solid currentColor;
    border-radius: 4px;
    transform: rotate(-2deg);
    margin-bottom: 10px;
    opacity: 0.9;
}

.difficulty.super-easy { color: var(--stamp-green); }
.difficulty.easy       { color: var(--stamp-blue); }
.difficulty.medium     { color: var(--money-1); }
.difficulty.hard       { color: var(--stamp-red); }

/* --------------------------------------------------------------------------
   HUD – handläggningsstatus
   -------------------------------------------------------------------------- */
.hud {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 20px;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 20px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.player-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.player-role {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--ink);
    line-height: 1.3;
}

.term-timer {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--stamp-blue);
    border: 1px dashed var(--stamp-blue);
    border-radius: 4px;
    padding: 1px 7px;
    margin-top: 4px;
    width: fit-content;
    white-space: nowrap;
}

.term-timer.urgent {
    color: var(--stamp-red);
    border-color: var(--stamp-red);
    animation: timerBlink 1s steps(2, start) infinite;
}

@keyframes timerBlink {
    50% { opacity: 0.45; }
}

.resources {
    display: flex;
    gap: 22px;
    flex: 0 1 460px;
}

.resource {
    flex: 1;
    min-width: 130px;
}

.resource-label {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink-soft);
    margin-bottom: 5px;
}

.resource-icon {
    font-size: 0.85rem;
}

.resource-value {
    margin-left: auto;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.resource-bar {
    position: relative;
    height: 10px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    /* overflow måste vara synligt så att de flytande +/- -siffrorna inte klipps;
       fyllnaden cappas till 100% i JS och över max visas med randning */
    overflow: visible;
}

.resource-fill {
    height: 100%;
    width: 0%;
    max-width: 100%;
    border-radius: 5px;
    transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.money-fill {
    background: linear-gradient(90deg, var(--money-1), var(--money-2));
}

.patience-fill {
    background: linear-gradient(90deg, var(--patience-1), var(--patience-2));
}

/* Över maximum: randig "övertrasserad" markering istället för att spränga layouten */
.money-fill.over-max {
    background-image: repeating-linear-gradient(
        -45deg,
        rgba(255, 255, 255, 0.35) 0 6px,
        transparent 6px 12px
    ), linear-gradient(90deg, var(--money-1), var(--money-2));
    animation: overMaxSlide 1.2s linear infinite;
}

.patience-fill.over-max {
    background-image: repeating-linear-gradient(
        -45deg,
        rgba(255, 255, 255, 0.35) 0 6px,
        transparent 6px 12px
    ), linear-gradient(90deg, var(--patience-1), var(--patience-2));
    animation: overMaxSlide 1.2s linear infinite;
}

@keyframes overMaxSlide {
    to { background-position: 17px 0, 0 0; }
}

/* Flytande +/- vid resursändring (mitt över stapeln, krockar inte med värdet) */
.resource-change-animation {
    position: absolute;
    top: -22px;
    right: 40%;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.85rem;
    pointer-events: none;
    animation: floatUp 1.8s ease-out forwards;
    z-index: 5;
}

.resource-change-positive { color: var(--success); }
.resource-change-negative { color: var(--danger); }

@keyframes floatUp {
    0%   { opacity: 0; transform: translateY(6px); }
    15%  { opacity: 1; transform: translateY(0); }
    75%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(-14px); }
}

/* --------------------------------------------------------------------------
   Berättelsen – själva handlingen i ärendet
   -------------------------------------------------------------------------- */
.story-container {
    background: var(--card);
    border: 1px solid var(--card-edge);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 22px 26px 26px;
    margin-bottom: 18px;
    position: relative;
}

.story-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px dotted var(--line);
    padding-bottom: 8px;
    margin-bottom: 16px;
}

.scene-counter {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--stamp-blue);
}

.story-meta-note {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.story-image {
    font-size: 2.6rem;
    line-height: 1;
    margin-bottom: 12px;
}

.story-text {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1.14rem;
    line-height: 1.65;
    color: var(--ink);
}

.story-container.scene-enter {
    animation: sceneIn 0.45s ease both;
}

@keyframes sceneIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* --------------------------------------------------------------------------
   Val – alternativen i blanketten
   -------------------------------------------------------------------------- */
.choices-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice-button {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    text-align: left;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.45;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--card-edge);
    border-radius: 8px;
    padding: 13px 16px;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.choice-button:focus-visible {
    transform: translateX(4px);
    border-color: var(--aland-blue);
    outline: 2px solid var(--aland-blue);
    outline-offset: 2px;
}

.choice-button:active {
    transform: translateX(4px) scale(0.99);
}

.choice-key {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--ink-soft);
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 5px;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.choice-button:focus-visible .choice-key {
    color: #fff;
    background: var(--aland-blue);
    border-color: var(--aland-blue);
}

/* Hover-effekter enbart på enheter med riktig pekare – på pekskärmar
   fastnar simulerad hover på knappen vid samma skärmposition efter tryck
   ("sticky hover") och ser ut som ett förvalt alternativ */
@media (hover: hover) and (pointer: fine) {
    .choice-button:hover {
        transform: translateX(4px);
        border-color: var(--aland-blue);
    }

    .choice-button:hover .choice-key {
        color: #fff;
        background: var(--aland-blue);
        border-color: var(--aland-blue);
    }
}

.choices-container.scene-enter .choice-button {
    animation: sceneIn 0.4s ease both;
}

.choices-container.scene-enter .choice-button:nth-child(1) { animation-delay: 0.08s; }
.choices-container.scene-enter .choice-button:nth-child(2) { animation-delay: 0.16s; }
.choices-container.scene-enter .choice-button:nth-child(3) { animation-delay: 0.24s; }
.choices-container.scene-enter .choice-button:nth-child(4) { animation-delay: 0.32s; }

/* --------------------------------------------------------------------------
   Game over – beslutet
   -------------------------------------------------------------------------- */
.game-over-content {
    max-width: 620px;
    margin: 24px auto 0;
    text-align: center;
    background: var(--card);
    border: 1px solid var(--card-edge);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 40px 34px 34px;
    position: relative;
    overflow: hidden;
}

.stamp {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--stamp-red);
    border: 4px double currentColor;
    border-radius: 6px;
    padding: 8px 22px 8px 26px; /* kompenserar letter-spacing */
    transform: rotate(-8deg);
    margin-bottom: 18px;
    opacity: 0.92;
    -webkit-mask-image: radial-gradient(circle at 30% 40%, #000 92%, transparent 100%);
    mask-image: radial-gradient(circle at 30% 40%, #000 92%, transparent 100%);
}

.stamp.stamp-win     { color: var(--stamp-green); }
.stamp.stamp-neutral { color: var(--stamp-blue); }

.stamp.stamp-slam {
    animation: stampSlam 0.5s cubic-bezier(0.36, 0, 0.66, -0.3) both;
}

@keyframes stampSlam {
    0% {
        opacity: 0;
        transform: rotate(-8deg) scale(2.6);
    }
    70% {
        opacity: 1;
        transform: rotate(-8deg) scale(0.94);
    }
    100% {
        opacity: 0.92;
        transform: rotate(-8deg) scale(1);
    }
}

#gameOverTitle {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 1.7rem;
    line-height: 1.2;
    color: var(--ink);
    margin-bottom: 12px;
}

.game-over-message {
    font-family: var(--font-display);
    font-size: 1.05rem;
    line-height: 1.65;
    color: var(--ink-soft);
    margin-bottom: 22px;
}

.game-over-stats {
    text-align: left;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 24px;
}

.game-over-stats h3 {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 10px;
}

.game-over-stats p {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 0.88rem;
    color: var(--ink);
    padding: 5px 0;
    border-bottom: 1px dotted var(--line);
}

.game-over-stats p:last-child {
    border-bottom: none;
}

.game-over-stats strong {
    font-weight: 600;
    color: var(--ink-soft);
}

.game-over-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

.primary-button {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #fff;
    background: var(--aland-blue);
    border: none;
    border-radius: 8px;
    padding: 13px 26px;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: transform 0.15s ease, filter 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
    .primary-button:hover {
        filter: brightness(1.12);
        transform: translateY(-1px);
    }
}

.primary-button:active {
    transform: translateY(0) scale(0.98);
}

.secondary-button {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--aland-blue);
    background: transparent;
    border: 1.5px solid var(--aland-blue);
    border-radius: 8px;
    padding: 12px 22px;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
    .secondary-button:hover {
        background: var(--aland-blue);
        color: #fff;
        transform: translateY(-1px);
    }
}

.secondary-button:active {
    transform: translateY(0) scale(0.98);
}

/* --------------------------------------------------------------------------
   Sidfot
   -------------------------------------------------------------------------- */
.game-footer {
    text-align: center;
    padding: 18px 28px 22px;
    border-top: 3px double var(--line);
    color: var(--ink-soft);
    font-size: 0.85rem;
}

.fine-print {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
    margin-top: 6px;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.toast-popup {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    max-width: min(480px, calc(100vw - 32px));
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--card-edge);
    border-left: 4px solid var(--aland-blue);
    border-radius: 8px;
    box-shadow: var(--shadow-card);
    padding: 13px 18px;
    font-size: 0.9rem;
    line-height: 1.5;
    z-index: 5000;
    animation: toastIn 0.35s ease both, toastOut 0.4s ease 2.9s forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translate(-50%, 12px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
}

/* --------------------------------------------------------------------------
   Modal – meddelande från myndigheten
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(23, 20, 15, 0.55);
    backdrop-filter: blur(2px);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 6000;
    animation: overlayIn 0.25s ease both;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-card {
    width: min(480px, 100%);
    background: var(--card);
    border: 1px solid var(--card-edge);
    border-top: 6px solid var(--aland-blue);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 24px 26px 22px;
    animation: modalIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.modal-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--ink);
    margin-bottom: 10px;
}

.modal-title::before {
    content: 'Meddelande · delges elektroniskt';
    display: block;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 6px;
}

.modal-body {
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--ink-soft);
    margin-bottom: 18px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
}

.modal-button {
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-weight: 700;
    border: none;
    border-radius: 7px;
    padding: 10px 20px;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.1s ease;
}

.modal-button.primary {
    background: var(--aland-blue);
    color: #fff;
}

@media (hover: hover) and (pointer: fine) {
    .modal-button.primary:hover {
        filter: brightness(1.12);
    }
}

.modal-button:active {
    transform: scale(0.97);
}

/* --------------------------------------------------------------------------
   Responsivt
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
    /* Kompakt mobillayout: hela startskärmen (header + fyra kort)
       ska rymmas på en skärmhöjd */
    body {
        padding: 8px 6px 16px;
    }

    .flag-stripe {
        height: 5px;
    }

    .game-header {
        position: relative;
        padding: 10px 14px 8px;
    }

    .header-brand {
        gap: 10px;
    }

    .header-buttons {
        position: absolute;
        top: 10px;
        right: 12px;
        padding: 0;
    }

    .audio-toggle {
        font-size: 0.85rem;
        padding: 4px 7px;
    }

    .brand-seal {
        width: 34px;
        height: 34px;
        font-size: 0.9rem;
        box-shadow: inset 0 0 0 2px var(--card), inset 0 0 0 3px var(--stamp-blue);
    }

    .brand-eyebrow {
        font-size: 0.52rem;
        letter-spacing: 0.1em;
        margin-bottom: 2px;
        padding-right: 78px; /* frigör hörnet för knapparna */
    }

    .eyebrow-extra {
        display: none;
    }

    .game-title {
        font-size: 1.3rem;
    }

    .game-subtitle {
        font-size: 0.8rem;
        margin-top: 2px;
    }

    .game-main {
        padding: 10px 10px 16px;
    }

    .role-cards h3 {
        font-size: 1.1rem;
    }

    .role-note {
        font-size: 0.58rem;
        margin: 3px 0 10px;
    }

    .cards-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    /* Kort i kompakt rad-layout: ikon | titel + stämpel, beskrivning under */
    .role-card {
        display: grid;
        grid-template-columns: 42px 1fr;
        column-gap: 10px;
        align-items: center;
        padding: 10px 12px 9px;
    }

    .role-card::after {
        inset: 4px;
    }

    .card-code {
        top: 8px;
        right: 10px;
        font-size: 0.55rem;
        padding: 1px 5px;
    }

    .role-icon {
        grid-row: 1 / span 2;
        font-size: 1.7rem;
        margin-bottom: 0;
    }

    .role-card h4 {
        grid-column: 2;
        font-size: 1rem;
        margin-bottom: 0;
        padding-right: 52px; /* plats för blankettkoden */
        line-height: 1.2;
    }

    .difficulty {
        grid-column: 2;
        justify-self: start;
        font-size: 0.54rem;
        padding: 2px 6px;
        margin: 3px 0 0;
    }

    .role-card p {
        grid-column: 1 / -1;
        font-size: 0.77rem;
        line-height: 1.38;
        margin-top: 6px;
    }

    .role-best {
        grid-column: 1 / -1;
        font-size: 0.58rem;
        margin-top: 4px;
        min-height: 0;
    }

    .game-footer {
        padding: 10px 14px 14px;
        font-size: 0.72rem;
    }

    .fine-print {
        font-size: 0.52rem;
        margin-top: 3px;
    }

    /* Spelskärmen komprimerad: HUD + scen + val på en skärmhöjd */
    .hud {
        flex-direction: column;
        gap: 8px;
        padding: 8px 12px;
        margin-bottom: 10px;
    }

    .player-info {
        justify-content: space-between;
        align-items: center;
    }

    .player-label {
        display: none;
    }

    .player-role {
        font-size: 0.95rem;
    }

    .term-timer {
        font-size: 0.6rem;
        margin-top: 2px;
    }

    .change-role-button-inline {
        font-size: 0.6rem;
        padding: 5px 8px;
    }

    .resources {
        flex: 1 1 auto;
        width: 100%;
        gap: 12px;
    }

    .resource-label {
        font-size: 0.7rem;
        margin-bottom: 3px;
    }

    .resource-value {
        font-size: 0.75rem;
    }

    .resource-bar {
        height: 8px;
    }

    .story-container {
        padding: 10px 14px 12px;
        margin-bottom: 10px;
    }

    .story-meta {
        padding-bottom: 5px;
        margin-bottom: 10px;
    }

    .scene-counter {
        font-size: 0.65rem;
    }

    .story-meta-note {
        font-size: 0.55rem;
    }

    /* Emojin flyter till vänster om texten i stället för egen rad */
    .story-image {
        float: left;
        font-size: 1.6rem;
        margin: 2px 10px 2px 0;
    }

    .story-text {
        font-size: 0.94rem;
        line-height: 1.5;
    }

    .story-text::after {
        content: '';
        display: block;
        clear: both;
    }

    .choices-container {
        gap: 8px;
    }

    .choice-button {
        gap: 10px;
        padding: 10px 12px;
        font-size: 0.85rem;
        line-height: 1.35;
    }

    .choice-key {
        width: 22px;
        height: 22px;
        font-size: 0.65rem;
    }

    .game-over-content {
        padding: 30px 20px 26px;
    }

    .stamp {
        font-size: 1.2rem;
        letter-spacing: 0.2em;
    }

    .game-container::before {
        display: none;
    }
}

/* --------------------------------------------------------------------------
   Rörelsekänslighet
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
