:root {
    /* Palette: gray, light blue, blue */
    --gray-900: #171b22;
    --gray-800: #1f2530;
    --gray-700: #2b3341;
    --gray-600: #3a4657;
    --gray-400: #8a94a6;
    --gray-200: #c7cfdd;

    --blue-deep: #0b2a4a;
    --blue: #1b6ca8;
    --blue-mid: #2a86c7;
    --lightblue: #7ec8e3;
    --lightblue-soft: #a8d8ea;

    --danger: #d9534f;
    --ok: #4bbf9a;

    --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
    --radius: 16px;
    --font: "Segoe UI", "SF Pro Display", system-ui, -apple-system, Roboto, sans-serif;
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    color: var(--gray-200);
    background: var(--gray-900);
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ===================== SCREENS ===================== */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fade 0.35s ease;
}
.screen.is-active { display: flex; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.overlay-screen {
    background: rgba(9, 14, 22, 0.72);
    backdrop-filter: blur(6px);
    z-index: 30;
}

/* ===================== BUTTONS ===================== */
.btn {
    appearance: none;
    border: 1px solid var(--gray-600);
    background: linear-gradient(180deg, var(--gray-700), var(--gray-800));
    color: var(--gray-200);
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 14px 22px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    width: 100%;
}
.btn:hover { transform: translateY(-2px); border-color: var(--lightblue); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(180deg, var(--blue-mid), var(--blue));
    border-color: var(--blue);
    color: #fff;
    box-shadow: 0 6px 22px rgba(27, 108, 168, 0.4);
}
.btn-primary:hover { border-color: var(--lightblue); box-shadow: 0 8px 28px rgba(42, 134, 199, 0.55); }

.btn-ghost { background: transparent; }
.btn-danger {
    background: linear-gradient(180deg, #c9504c, #a83c39);
    border-color: #a83c39;
    color: #fff;
}

.icon-btn {
    appearance: none;
    border: 1px solid var(--gray-600);
    background: rgba(31, 37, 48, 0.85);
    color: var(--lightblue);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s ease, border-color 0.2s ease;
}
.icon-btn:hover { transform: translateY(-2px); border-color: var(--lightblue); }

/* ===================== SPLASH ===================== */
#screen-splash {
    background:
        radial-gradient(1000px 600px at 50% -10%, rgba(126, 200, 227, 0.12), transparent 60%),
        linear-gradient(180deg, var(--blue-deep), var(--gray-900) 80%);
}
.splash-inner { text-align: center; width: min(90vw, 420px); }

.splash-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.sub-icon {
    position: relative;
    width: 140px;
    height: 90px;
    animation: floaty 3s ease-in-out infinite;
}
@keyframes floaty { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }
.sub-body {
    position: absolute;
    left: 10px; top: 25px;
    width: 110px; height: 46px;
    border-radius: 40px;
    background: linear-gradient(180deg, var(--lightblue), var(--blue));
    box-shadow: inset 0 -6px 14px rgba(0,0,0,0.25);
}
.sub-window {
    position: absolute;
    left: 30px; top: 38px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--gray-900);
    border: 3px solid var(--lightblue-soft);
}
.sub-fin {
    position: absolute;
    left: 58px; top: 8px;
    width: 26px; height: 22px;
    border-radius: 6px 6px 0 0;
    background: var(--blue);
}
.bubble {
    position: absolute;
    right: -6px;
    border-radius: 50%;
    background: rgba(168, 216, 234, 0.7);
    animation: rise 2.4s linear infinite;
}
.bubble.b1 { width: 8px; height: 8px; top: 30px; animation-delay: 0s; }
.bubble.b2 { width: 6px; height: 6px; top: 40px; animation-delay: 0.7s; }
.bubble.b3 { width: 5px; height: 5px; top: 50px; animation-delay: 1.3s; }
@keyframes rise { 0% { transform: translate(0,0); opacity: 0.9; } 100% { transform: translate(50px,-40px); opacity: 0; } }

.splash-title {
    font-size: 44px;
    letter-spacing: 8px;
    color: #fff;
    text-shadow: 0 2px 20px rgba(126,200,227,0.4);
}
.splash-subtitle { color: var(--gray-400); margin: 6px 0 30px; letter-spacing: 2px; }

.loader-track {
    width: 100%;
    height: 10px;
    background: var(--gray-700);
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--gray-600);
}
.loader-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--blue), var(--lightblue));
    border-radius: 20px;
    transition: width 0.2s ease;
}
.loader-percent { margin-top: 10px; font-weight: 700; color: var(--lightblue); }
.loader-status { margin-top: 4px; color: var(--gray-400); font-size: 13px; min-height: 18px; }

/* ===================== MENU ===================== */
#screen-menu { overflow: hidden; }
.menu-bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(800px 500px at 20% 0%, rgba(126,200,227,0.14), transparent 60%),
        radial-gradient(900px 600px at 100% 100%, rgba(27,108,168,0.25), transparent 60%),
        linear-gradient(180deg, var(--blue-deep), var(--gray-900));
}
.menu-bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(2px 2px at 30% 40%, rgba(168,216,234,0.5), transparent),
        radial-gradient(2px 2px at 70% 60%, rgba(168,216,234,0.35), transparent),
        radial-gradient(1.5px 1.5px at 50% 80%, rgba(168,216,234,0.4), transparent),
        radial-gradient(1.5px 1.5px at 85% 25%, rgba(168,216,234,0.3), transparent);
    animation: drift 12s linear infinite;
}
@keyframes drift { from { transform: translateY(0); } to { transform: translateY(-30px); } }

.menu-inner {
    position: relative;
    text-align: center;
    width: min(90vw, 380px);
    z-index: 1;
}
.menu-title {
    font-size: 52px;
    letter-spacing: 10px;
    color: #fff;
    text-shadow: 0 4px 30px rgba(126,200,227,0.4);
}
.menu-tagline { color: var(--gray-400); margin: 8px 0 34px; }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; }
.menu-hint { margin-top: 26px; color: var(--gray-400); font-size: 13px; }
.menu-hint b { color: var(--lightblue); }

/* ===================== GAME SCREEN ===================== */
#screen-game { display: none; background: var(--gray-900); }
#screen-game.is-active { display: block; }
#gameCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    outline: none;
}

.hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px;
    gap: 10px;
    pointer-events: none;
    z-index: 5;
}
.hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: 8px; }
.hud-right { display: flex; gap: 8px; }

.hud-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(23, 27, 34, 0.78);
    border: 1px solid var(--gray-600);
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    backdrop-filter: blur(4px);
}
.hud-chip b { color: var(--lightblue); }
.hud-ico { color: var(--lightblue); }

.hud-center { flex: 1; display: flex; justify-content: center; }
.hull-wrap {
    background: rgba(23,27,34,0.78);
    border: 1px solid var(--gray-600);
    padding: 8px 12px;
    border-radius: 12px;
    backdrop-filter: blur(4px);
    min-width: 200px;
}
.hull-label { font-size: 11px; color: var(--gray-400); letter-spacing: 1px; text-transform: uppercase; }
.hull-track {
    margin-top: 5px;
    height: 10px;
    background: var(--gray-700);
    border-radius: 8px;
    overflow: hidden;
}
.hull-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--ok), var(--lightblue));
    transition: width 0.25s ease, background 0.25s ease;
}

.toast {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(27, 108, 168, 0.92);
    color: #fff;
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 6;
    box-shadow: var(--shadow);
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===================== PANELS (overlay) ===================== */
.panel {
    background: linear-gradient(180deg, var(--gray-800), var(--gray-900));
    border: 1px solid var(--gray-600);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 26px;
    width: min(92vw, 420px);
    max-height: 90vh;
    overflow: auto;
}
.panel-wide { width: min(94vw, 720px); }
.panel h2 { color: #fff; letter-spacing: 1px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { margin: 0; }
.panel-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

/* ===================== COLLECTION ===================== */
.collection-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.collection-list { display: flex; flex-direction: column; gap: 8px; max-height: 56vh; overflow: auto; }
.collection-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--gray-600);
    border-radius: 12px;
    background: var(--gray-800);
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.1s ease;
}
.collection-item:hover { border-color: var(--lightblue); transform: translateX(2px); }
.collection-item.selected { border-color: var(--lightblue); background: rgba(27,108,168,0.18); }
.ci-icon {
    width: 42px; height: 42px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    background: var(--gray-700);
    flex: 0 0 auto;
}
.ci-info { display: flex; flex-direction: column; }
.ci-name { font-weight: 600; color: #fff; }
.ci-count { font-size: 12px; color: var(--gray-400); }

.collection-detail {
    border: 1px dashed var(--gray-600);
    border-radius: 12px;
    padding: 16px;
    min-height: 200px;
}
.detail-placeholder { color: var(--gray-400); font-size: 14px; }
.detail-icon { font-size: 46px; text-align: center; margin-bottom: 10px; }
.detail-name { color: #fff; font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 12px; }
.detail-section { margin-bottom: 12px; }
.detail-section h4 { color: var(--lightblue); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.detail-section p { color: var(--gray-200); font-size: 14px; line-height: 1.5; }

.empty-state { color: var(--gray-400); text-align: center; padding: 40px 0; font-size: 15px; }

/* ===================== RESULTS ===================== */
.results-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.result-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 14px;
    background: var(--gray-800);
    border: 1px solid var(--gray-700);
    border-radius: 10px;
}
.result-row span { color: var(--gray-400); }
.result-row b { color: #fff; font-size: 18px; }
.result-total { background: rgba(27,108,168,0.2); border-color: var(--blue); }
.result-total b { color: var(--lightblue); font-size: 22px; }

/* ===================== RULES ===================== */
.rules-body { display: flex; flex-direction: column; gap: 18px; }
.rules-block h3 { color: var(--lightblue); margin-bottom: 6px; font-size: 16px; }
.rules-block p { color: var(--gray-200); line-height: 1.55; font-size: 14px; }
.keys { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 6px 0 10px; }
.key-row { display: flex; gap: 6px; }
.key {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    background: var(--gray-700);
    border: 1px solid var(--gray-600);
    border-bottom-width: 3px;
    border-radius: 8px;
    font-weight: 700;
    color: #fff;
}
.pin {
    display: inline-block;
    width: 22px; text-align: center;
    font-weight: 700;
}
.pin.sample { color: var(--lightblue); }
.pin.peace { color: var(--ok); }
.pin.danger { color: var(--danger); }
.pin.rock { color: var(--gray-400); }

/* ===================== SETTINGS ===================== */
.settings-body { display: flex; flex-direction: column; gap: 14px; }
.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    background: var(--gray-800);
    border: 1px solid var(--gray-700);
    border-radius: 12px;
    cursor: pointer;
    color: #fff;
    font-weight: 600;
}
.switch { position: relative; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; inset: 0;
    background: var(--gray-600);
    border-radius: 20px;
    transition: background 0.2s ease;
}
.slider::before {
    content: "";
    position: absolute;
    height: 22px; width: 22px;
    left: 3px; top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
}
.switch input:checked + .slider { background: var(--blue); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 560px) {
    .collection-layout { grid-template-columns: 1fr; }
    .hull-wrap { min-width: 130px; }
    .hud-chip { font-size: 12px; padding: 6px 9px; }
    .menu-title { font-size: 40px; }
    .splash-title { font-size: 36px; }
}
