:root {
    --ink: #f6f0e4;
    --ink-dim: #c3bcae;
    --glass: rgba(11, 25, 36, 0.62);
    --glass-border: rgba(255, 255, 255, 0.16);
    --accent: #ffb347;
    --accent-2: #ff7a45;
    --key: #ffd36b;
    --hp: #ff5d6c;
    --hunger: #ffa94d;
    --thirst: #4dc3ff;
    --good: #4fd08a;
    --font-display: 'Fredoka', 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
    --font-body: 'Nunito', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background: radial-gradient(ellipse at 50% 40%, #12303f 0%, #07131b 70%);
    color: var(--ink);
    font-family: var(--font-body);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

#game-container {
    position: relative;
    flex: none;
    width: 800px;
    height: 600px;
    transform-origin: center center;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 20px 60px rgba(0,0,0,0.6);
    background: #126b8c;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.hidden { display: none !important; }

/* ---------- Gemensamma delar ---------- */
.key-hint {
    display: inline-block;
    background: linear-gradient(#4a5560, #333c45);
    padding: 1px 7px;
    min-width: 20px;
    text-align: center;
    border-radius: 6px;
    border-bottom: 2px solid #1b2127;
    font-family: var(--font-body);
    font-size: 0.85em;
    font-weight: 800;
    color: var(--key);
    line-height: 1.4;
}

button {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.2px;
    padding: 12px 26px;
    font-size: 18px;
    color: #fff;
    background: linear-gradient(#ff9a4d, #f06a2e);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 0 #b84a1c, 0 8px 18px rgba(0,0,0,0.35);
    transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
button:hover { transform: translateY(-1px); filter: brightness(1.08); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 #b84a1c, 0 3px 8px rgba(0,0,0,0.35); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--key); outline-offset: 2px; }

/* ---------- Skärmeffekter ---------- */
#vignette {
    position: absolute; inset: 0; pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(4,12,20,0.45) 100%);
}
#damage-flash {
    position: absolute; inset: 0; pointer-events: none; opacity: 0;
    background: radial-gradient(ellipse at center, rgba(255,0,0,0) 30%, rgba(200,0,20,0.75) 100%);
}
#game-container.low-hp #vignette {
    animation: lowhp 1.1s ease-in-out infinite;
}
@keyframes lowhp {
    0%, 100% { background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(4,12,20,0.45) 100%); }
    50% { background: radial-gradient(ellipse at center, rgba(0,0,0,0) 38%, rgba(190,10,30,0.55) 100%); }
}

/* ---------- Spelets gränssnitt ---------- */
#ui-layer {
    position: absolute; inset: 0;
    pointer-events: none;
}
#stats, #clock, #inventory, #controls-tooltip {
    position: absolute;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

#stats { top: 14px; left: 14px; padding: 10px 12px; width: 178px; display: flex; flex-direction: column; gap: 8px; }
.stat { display: grid; grid-template-columns: 18px 1fr 28px; align-items: center; gap: 8px; }
.stat svg { width: 18px; height: 18px; }
.stat b { font-size: 13px; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .bar { height: 10px; border-radius: 99px; background: rgba(255,255,255,0.12); overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,0.4); }
.stat .bar i { display: block; height: 100%; width: 100%; border-radius: 99px; transition: width .25s ease; box-shadow: inset 0 2px 0 rgba(255,255,255,0.3); }
.stat.hp svg { color: var(--hp); }       .stat.hp .bar i { background: linear-gradient(90deg, #ff8a94, var(--hp)); }
.stat.hunger svg { color: var(--hunger); } .stat.hunger .bar i { background: linear-gradient(90deg, #ffc98a, var(--hunger)); }
.stat.thirst svg { color: var(--thirst); } .stat.thirst .bar i { background: linear-gradient(90deg, #8ddcff, var(--thirst)); }
.stat.low svg { animation: pulse 0.8s ease-in-out infinite; }
.stat.low b { color: #ff8a8a; }
@keyframes pulse { 50% { transform: scale(1.25); } }

#clock { top: 14px; right: 14px; width: 176px; padding: 10px 12px; }
#clock-top { display: flex; align-items: center; gap: 7px; }
#clock-top svg { width: 20px; height: 20px; flex: none; }
.ic-sun { color: #ffd36b; }
.ic-moon { color: #b9c6ff; display: none; }
#game-container[data-phase="night"] .ic-sun { display: none; }
#game-container[data-phase="night"] .ic-moon { display: block; }
#game-container[data-phase="dusk"] .ic-sun { color: #ff9a5c; }
#time-value { font-family: var(--font-display); font-weight: 600; font-size: 15px; flex: 1; }
.days { display: flex; flex-direction: column; align-items: flex-end; line-height: 1; }
.days b { font-family: var(--font-display); font-size: 20px; color: var(--key); }
.days small { font-size: 9px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-dim); }
#day-progress {
    position: relative; height: 6px; margin-top: 9px; border-radius: 99px;
    background: linear-gradient(90deg, #ffd36b 0 54%, #ff8a4c 54% 60%, #3a4a8a 60% 100%);
    opacity: 0.9;
}
#day-progress-fill {
    position: absolute; top: 50%; left: 0; width: 12px; height: 12px; margin: -6px 0 0 -6px;
    border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,0.35), 0 0 8px rgba(255,255,255,0.7);
}

#inventory { bottom: 14px; left: 50%; transform: translateX(-50%); padding: 8px 10px 10px; }
#inventory h3 { margin: 0 0 6px 2px; font-family: var(--font-display); font-weight: 600; font-size: 12px; letter-spacing: .4px; display: flex; justify-content: space-between; color: var(--ink-dim); }
#inventory h3 small { font-size: 12px; font-family: var(--font-body); font-weight: 800; }
#inventory-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(10, 36px); gap: 4px; }
.slot {
    position: relative; width: 36px; height: 36px; border-radius: 9px;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.10);
    display: flex; align-items: center; justify-content: center;
}
.slot.filled { background: linear-gradient(rgba(255,255,255,0.18), rgba(255,255,255,0.07)); border-color: rgba(255,255,255,0.28); }
.slot svg { width: 26px; height: 26px; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.5)); }
.slot.hotkey::after {
    content: attr(data-key); position: absolute; right: -3px; bottom: -3px;
    background: var(--key); color: #3a2a0a; font-size: 10px; font-weight: 800;
    width: 14px; height: 14px; line-height: 14px; text-align: center; border-radius: 5px;
}

#action-hints {
    position: absolute; bottom: 88px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 8px; white-space: nowrap;
}
#action-hints > span {
    display: none; font-size: 13px; font-weight: 800;
    background: rgba(11,25,36,0.8); border: 1px solid var(--glass-border);
    padding: 5px 12px 5px 8px; border-radius: 99px;
}
#action-hints > span.show { display: inline-block; }
#hint-fire.show { border-color: var(--accent); box-shadow: 0 0 14px rgba(255,150,50,0.55); animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 4px rgba(255,150,50,0.25); } }

#controls-tooltip {
    bottom: 14px; left: 14px; padding: 8px 10px; font-size: 11px; line-height: 1.9;
    border-radius: 12px; opacity: 0.8; color: var(--ink-dim);
}
#controls-tooltip .key-hint { font-size: 10px; margin-right: 3px; }

/* ---------- Startskärm ---------- */
#welcome-screen {
    position: absolute; inset: 0; z-index: 20;
    display: flex; flex-direction: column; align-items: center;
    padding: 20px 28px 22px;
    overflow: hidden;
    background:
        radial-gradient(1.5px 1.5px at 12% 14%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 28% 8%, #fff 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 44% 20%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 63% 10%, #fff 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 80% 16%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 92% 7%, #fff 50%, transparent 51%),
        linear-gradient(180deg, #151a45 0%, #4b2f78 34%, #c0546f 62%, #ff9a62 82%, #ffcc84 100%);
}
.sky-sun {
    position: absolute; left: 50%; bottom: 40px; width: 360px; height: 360px; margin-left: -180px; border-radius: 50%;
    background: radial-gradient(circle, #fff3c4 0 22%, rgba(255,210,120,0.75) 30%, rgba(255,150,80,0.25) 55%, rgba(255,120,60,0) 70%);
}
.palm { position: absolute; bottom: 8px; width: 230px; height: 300px; }
.palm-left { left: -46px; transform: rotate(-4deg); transform-origin: bottom center; animation: sway 7s ease-in-out infinite; }
.palm-right { right: -46px; transform: scaleX(-1) rotate(-4deg); transform-origin: bottom center; animation: sway2 8s ease-in-out infinite; }
@keyframes sway { 50% { transform: rotate(-1.5deg); } }
@keyframes sway2 { 50% { transform: scaleX(-1) rotate(-1.5deg); } }
.waves {
    position: absolute; left: 0; right: 0; bottom: 0; height: 56px;
    background-repeat: repeat-x; background-size: 400px 56px;
}
.waves-back {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='56' viewBox='0 0 400 56'%3E%3Cpath d='M0 26 Q50 6 100 26 T200 26 T300 26 T400 26 V56 H0Z' fill='%231c4f78'/%3E%3C/svg%3E");
    bottom: 10px; opacity: 0.9; animation: drift 14s linear infinite;
}
.waves-front {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='56' viewBox='0 0 400 56'%3E%3Cpath d='M0 30 Q50 12 100 30 T200 30 T300 30 T400 30 V56 H0Z' fill='%23123a5a'/%3E%3C/svg%3E");
    height: 44px; animation: drift 9s linear infinite reverse;
}
@keyframes drift { to { background-position-x: 400px; } }

#welcome-screen h1 {
    position: relative; margin: 0 0 10px; display: flex; flex-direction: column; align-items: center; line-height: 1;
    font-family: var(--font-display); font-weight: 700;
}
#welcome-screen h1 small { font-size: 15px; font-weight: 500; letter-spacing: 4px; text-transform: uppercase; color: #ffe2b8; opacity: .9; }
#welcome-screen h1 span {
    font-size: 58px; letter-spacing: 2px; line-height: 1.25; margin-top: -4px; padding-top: 6px;
    background: linear-gradient(#fff6d6, #ffb347 70%, #ff7a45);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 3px 0 rgba(90,30,40,0.55)) drop-shadow(0 6px 14px rgba(0,0,0,0.35));
}
#welcome-content { position: relative; display: flex; gap: 16px; width: 100%; flex: 1; min-height: 0; margin-bottom: 14px; }
#instructions, #welcome-highscore {
    background: rgba(14, 14, 40, 0.55);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 16px;
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    padding: 14px 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
#instructions { flex: 1.55; font-size: 13px; line-height: 1.45; overflow: auto; }
#instructions h3, #welcome-highscore h3 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 600; font-size: 16px; letter-spacing: .3px; }
#instructions h3 { color: #8fd3ff; }
#instructions p { margin: 0 0 8px; }
#instructions ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 7px; }
#instructions li { display: flex; gap: 10px; align-items: flex-start; }
#instructions li i {
    flex: none; font-style: normal; width: 26px; height: 26px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; font-size: 15px; background: rgba(255,255,255,0.12);
}

#welcome-highscore { flex: 1; overflow-y: auto; }
#welcome-highscore h3 { color: var(--key); text-align: center; }
#highscore-list { list-style: none; counter-reset: rank; padding: 0; margin: 0; font-size: 13px; }
#highscore-list li {
    counter-increment: rank; display: flex; align-items: center; gap: 8px; padding: 5px 4px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
#highscore-list li::before {
    content: counter(rank); flex: none; width: 20px; height: 20px; border-radius: 50%; text-align: center; line-height: 20px;
    font-size: 11px; font-weight: 800; background: rgba(255,255,255,0.14);
}
#highscore-list li:nth-child(1)::before { background: #ffd36b; color: #3a2a0a; }
#highscore-list li:nth-child(2)::before { background: #d5dbe0; color: #26303a; }
#highscore-list li:nth-child(3)::before { background: #e0a070; color: #3a210e; }
#highscore-list .hs-name { flex: 1; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#highscore-list .hs-days { font-weight: 800; color: var(--key); }
#highscore-list .hs-days small { font-weight: 600; color: var(--ink-dim); font-size: 11px; }
#highscore-list li.empty { display: block; counter-increment: none; color: var(--ink-dim); text-align: center; border: none; padding-top: 18px; }
#highscore-list li.empty::before { display: none; }

#start-game-btn {
    position: relative; font-size: 22px; padding: 14px 44px;
    background: linear-gradient(#5be092, #25a85c);
    box-shadow: 0 5px 0 #17753e, 0 10px 24px rgba(0,0,0,0.4);
    animation: breathe 2.4s ease-in-out infinite;
}
#start-game-btn:active { box-shadow: 0 1px 0 #17753e, 0 3px 8px rgba(0,0,0,0.4); }
@keyframes breathe { 50% { transform: scale(1.04); } }

/* ---------- Game over ---------- */
#game-over-screen {
    position: absolute; inset: 0; z-index: 10;
    display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
    background: radial-gradient(ellipse at center, rgba(30,4,8,0.80) 0%, rgba(4,2,8,0.96) 75%);
    animation: fadein .8s ease both;
    text-align: center; padding: 0 40px;
}
@keyframes fadein { from { opacity: 0; } }
#game-over-screen h1 {
    margin: 0 0 4px; font-family: var(--font-display); font-weight: 700; font-size: 52px; letter-spacing: 1px;
    background: linear-gradient(#ffb0a0, #ff3b3b 60%, #a8101c);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 0 18px rgba(255,40,40,0.45));
}
#death-reason { margin: 0 0 14px; max-width: 520px; font-size: 16px; line-height: 1.5; color: #e6d6d2; }
#submit-score-box { margin: 6px 0 0; display: none; gap: 10px; }
#player-name {
    width: 230px; padding: 10px 14px; font-size: 15px; font-family: var(--font-body); font-weight: 700;
    border-radius: 999px; border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.08); color: #fff;
}
#player-name::placeholder { color: #a89fa0; font-weight: 600; }
#submit-btn { font-size: 15px; padding: 10px 20px; background: linear-gradient(#5be092, #25a85c); box-shadow: 0 4px 0 #17753e, 0 8px 18px rgba(0,0,0,0.35); }
#submit-status { color: var(--key); margin: 6px 0; font-size: 14px; min-height: 20px; font-weight: 700; }
#restart-btn { margin-top: 8px; }

/* Intro: dölj spelets gränssnitt tills introt är klart */
#game-container.intro #ui-layer, #game-container.intro #vignette { visibility: hidden; }

/* Vinstläge */
#game-over-screen .win-title, #win-reason { display: none; }
#game-over-screen.won .win-title { display: inline; }
#game-over-screen.won .lose-title, #game-over-screen.won #death-reason { display: none; }
#game-over-screen.won #win-reason { display: block; margin: 0 0 14px; font-size: 18px; line-height: 1.5; color: #e6f3e6; }
#win-reason strong { color: var(--key); font-size: 24px; }
#game-over-screen.won { background: radial-gradient(ellipse at center, rgba(8,40,30,0.82) 0%, rgba(2,10,14,0.96) 75%); }
#game-over-screen.won h1 {
    font-size: 40px;
    background: linear-gradient(#fff3b0, #ffd36b 55%, #e8a02a);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 0 18px rgba(255,211,107,0.45));
}

/* Fråga vid färdig flotte */
#raft-dialog {
    position: absolute; inset: 0; z-index: 9;
    display: flex; justify-content: center; align-items: center;
    background: rgba(4,12,18,0.55);
}
.raft-box {
    background: rgba(14,26,36,0.95); border: 1px solid rgba(255,255,255,0.25); border-radius: 20px;
    padding: 24px 32px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.raft-box h2 { margin: 0 0 6px; font-family: var(--font-display); font-size: 26px; color: var(--key); }
.raft-box p { margin: 0 0 16px; font-size: 16px; }
.raft-buttons { display: flex; gap: 12px; justify-content: center; }
#raft-yes { background: linear-gradient(#5be092, #25a85c); box-shadow: 0 4px 0 #17753e, 0 8px 18px rgba(0,0,0,0.35); font-size: 16px; padding: 10px 18px; }
#raft-no { font-size: 16px; padding: 10px 18px; }

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
