body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: #1a1a1a;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

.game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    user-select: none;
    overflow: hidden;
    background-color: #060b14;
    background-image:
        /* aurora blobs — modern mesh-gradient feel */
        radial-gradient(60vmin 40vmin at 15% 20%, rgba(10, 200, 185, 0.18), transparent 70%),
        radial-gradient(55vmin 45vmin at 85% 10%, rgba(200, 170, 110, 0.14), transparent 70%),
        radial-gradient(70vmin 50vmin at 75% 95%, rgba(91, 140, 235, 0.16), transparent 70%),
        radial-gradient(50vmin 40vmin at 10% 90%, rgba(181, 139, 245, 0.10), transparent 70%),
        /* base */
        linear-gradient(180deg, #0b1522 0%, #060b14 60%, #03060b 100%);
}
/* Soft vignette on top for focus */
.game-container > .vignette {
    position: absolute; inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.55) 100%);
    z-index: 1;
}

/* Controls Bar — right-hand vertical rail */
.controls-bar {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    z-index: 200;
}
.controls-bar .control-btn {
    justify-content: flex-start;
}

.control-btn {
    background-color: rgba(0, 0, 0, 0.6);
    color: #c8aa6e;
    border: 1px solid #7a6b4c;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.control-btn:hover {
    background-color: #c8aa6e;
    color: #1e2328;
}
.btn-icon {
    vertical-align: text-bottom;
    margin-right: 5px;
}
.control-btn:hover .btn-icon use { stroke: #1e2328; }

/* Branding on start screen */
.wordmark {
    display: block;
    width: 100%;
    max-width: 420px;
    height: auto;
    margin: 0 auto 16px;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6));
}

/* Modal Styling */
.modal {
    display: none;
    position: fixed;
    z-index: 300;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal-content {
    background-color: #1e2328;
    color: #e0e0e0;
    margin: 10% auto;
    padding: 25px;
    border: 2px solid #c8aa6e;
    width: 80%;
    max-width: 600px;
    border-radius: 5px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.8);
    position: relative;
}

.modal-content h2 {
    color: #c8aa6e;
    margin-top: 0;
}

.modal-content h3 {
    color: #ffcc00;
}

.modal-content code {
    background: #111;
    padding: 2px 5px;
    border-radius: 3px;
    color: #ffcc00;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 15px;
}

.close-btn:hover,
.close-btn:focus {
    color: #c8aa6e;
    text-decoration: none;
}

/* Start Screen */
.start-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.85);
    color: #e0e0e0;
    padding: 30px;
    border: 2px solid #c8aa6e;
    text-align: center;
    z-index: 100;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    min-width: 400px;
}

.start-screen h2 {
    color: #c8aa6e;
    margin-top: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.settings-panel {
    background: rgba(0,0,0,0.5);
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}

.setting-item label {
    cursor: pointer;
}

.setting-item select {
    background: #111;
    color: #ffcc00;
    border: 2px solid #7a6b4c;
    padding: 10px 15px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 15px;
    cursor: pointer;
    min-width: 180px;
    outline: none;
}

.setting-item select:focus {
    border-color: #c8aa6e;
}

.setting-item input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    background-color: #111;
    border: 2px solid #7a6b4c;
    width: 24px;
    height: 24px;
    border-radius: 3px;
    display: inline-block;
    position: relative;
    cursor: pointer;
    margin: 0;
    transition: all 0.2s;
}

.setting-item input[type="checkbox"]:checked {
    background-color: #c8aa6e;
    border-color: #c8aa6e;
}

.setting-item input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 12px;
    border: solid #1e2328;
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
}

.start-screen ul {
    margin-bottom: 25px;
    line-height: 1.6;
}

.start-screen code {
    background: #333;
    padding: 2px 5px;
    border-radius: 3px;
    color: #ffcc00;
}

.start-screen button {
    background-color: #1e2328;
    color: #c8aa6e;
    border: 2px solid #c8aa6e;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.2s;
    width: 100%;
}

.start-screen button:hover {
    background-color: #c8aa6e;
    color: #1e2328;
}

/* Top HUD (Clock & Score) */
.top-hud {
    position: absolute;
    top: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 15px 20px 0;
    box-sizing: border-box;
    pointer-events: none;
    align-items: flex-start;
}

.left-hud {
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    margin-left: 15px;
    margin-top: 19px; /* nudge ~0.5cm down from the viewport top */
}

.right-hud {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    margin-right: 15px;
    margin-top: 19px;
    pointer-events: none;
}
#gameClock {
    font-size: 14px;
    color: #ffffff;
    background-color: rgba(0, 0, 0, 0.7);
    border: 2px solid #5a5a5a;
    border-radius: 3px;
    padding: 2px 6px;
    font-weight: bold;
    font-family: monospace;
    text-shadow: 1px 1px 1px black;
}
.session-timer {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    width: 25vw;
    max-width: 320px;
    min-width: 120px;
    height: 6px;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.55);
    z-index: 150;
    pointer-events: none;
}
.session-timer-fill {
    height: 100%;
    width: 100%;
    background: #5bc0eb;
    box-shadow: 0 0 10px rgba(91,192,235,0.55);
    transition: width 0.25s linear, background 0.2s, box-shadow 0.2s;
}
.session-timer.warn  .session-timer-fill {
    background: #ffcc00;
    box-shadow: 0 0 10px rgba(255,204,0,0.55);
}
.session-timer.danger .session-timer-fill {
    background: #ff4f6d;
    box-shadow: 0 0 12px rgba(255,79,109,0.7);
    animation: sessPulse 1s ease-in-out infinite;
}
@keyframes sessPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.55; }
}
.session-timer-label {
    color: #a09b8c;
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-family: Arial, sans-serif;
}
.session-timer span:last-child {
    color: #5bc0eb;
    font-size: 16px;
    font-variant-numeric: tabular-nums;
}
.session-timer.warn span:last-child { color: #ffcc00; }
.session-timer.danger span:last-child { color: #ff4f6d; animation: sessPulse 1s ease-in-out infinite; }
@keyframes sessPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.55; }
}

/* Results modal footer */
.results-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 22px;
}
.results-new-best {
    color: #c8aa6e;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-size: 13px;
    text-shadow: 0 0 10px rgba(200,170,110,0.5);
}
.results-btn {
    background: linear-gradient(180deg, #c8aa6e 0%, #a08548 100%);
    color: #0a1016;
    border: none;
    padding: 10px 24px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 3px;
    font-size: 14px;
    margin-left: auto;
}
.results-btn:hover { filter: brightness(1.15); }

.score-board, .rank-board {
    font-size: 16px;
    color: #e0e0e0;
    background: linear-gradient(90deg, rgba(30,35,40,0.92) 0%, rgba(20,24,28,0.85) 100%);
    border-left: 4px solid #c8aa6e;
    border-radius: 0 5px 5px 0;
    padding: 12px 20px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    box-shadow: 0 3px 14px rgba(0,0,0,0.55);
    letter-spacing: 0.05em;
    min-width: 240px;
}
.score-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
}
.score-row + .score-row { margin-top: 4px; }
.score-label {
    color: #a09b8c;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}
.score-num {
    color: #c8aa6e;
    font-size: 34px;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 12px rgba(200,170,110,0.5);
    display: inline-block;
    transition: transform 0.15s;
    line-height: 1;
}
.score-num.score-pulse {
    animation: scorePulse 0.45s ease-out;
}
@keyframes scorePulse {
    0%   { transform: scale(1);    color: #c8aa6e; }
    30%  { transform: scale(1.25); color: #fff0c8; text-shadow: 0 0 18px #c8aa6e; }
    100% { transform: scale(1);    color: #c8aa6e; }
}
.score-next {
    color: #55ff88;
    font-size: 15px;
    font-weight: bold;
    margin-left: auto;
    opacity: 0.9;
}
.score-best span, .score-best .score-label { color: #a09b8c; }
.score-best #scoreBest {
    color: #5bc0eb;
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}

/* Rank badge */
.rank-board { --rank-color: #7a7a7a; border-left-color: var(--rank-color); }
.rank-badge {
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.2s;
}
.rank-icon {
    font-size: 40px;
    color: var(--rank-color);
    text-shadow: 0 0 14px var(--rank-color);
    line-height: 1;
}
.rank-tier {
    color: var(--rank-color);
    font-size: 20px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
}
.rank-streak {
    color: #a09b8c;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.rank-streak span {
    color: #c8aa6e;
    font-size: 17px;
    margin-left: 4px;
}
.rank-badge.streak-break {
    animation: streakBreak 0.55s ease-out;
}
@keyframes streakBreak {
    0%   { transform: translateX(0) rotate(0);     filter: none; }
    15%  { transform: translateX(-6px) rotate(-2deg); filter: hue-rotate(-30deg) brightness(1.4); }
    30%  { transform: translateX(6px)  rotate(2deg);  }
    45%  { transform: translateX(-4px) rotate(-1deg); }
    60%  { transform: translateX(4px)  rotate(1deg);  }
    100% { transform: translateX(0)    rotate(0);     filter: none; }
}

/* Flash tracker — pending flashes with countdown bar */
.flash-tracker {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
    pointer-events: none;
}
.flash-card {
    background: linear-gradient(90deg, rgba(30,35,40,0.92), rgba(20,24,28,0.85));
    border-left: 3px solid #5bc0eb;
    border-radius: 0 4px 4px 0;
    padding: 6px 10px;
    min-width: 180px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    animation: flashCardIn 0.2s ease-out;
}
@keyframes flashCardIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}
.flash-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}
.flash-card-role {
    color: #ffcc00;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.1em;
}
.flash-card-time {
    color: #e0e0e0;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.flash-card-bar {
    height: 4px;
    background: rgba(0,0,0,0.6);
    border-radius: 2px;
    overflow: hidden;
}
.flash-card-fill {
    height: 100%;
    background: linear-gradient(90deg, #5bc0eb, #c8aa6e);
    transition: width 0.4s linear;
}
.flash-card.urgent {
    border-left-color: #ff4f6d;
    animation: flashCardPulse 0.8s ease-in-out infinite;
}
.flash-card.urgent .flash-card-fill {
    background: linear-gradient(90deg, #ff4f6d, #ffcc00);
}
.flash-card.urgent .flash-card-time { color: #ff6b82; }
@keyframes flashCardPulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.5); }
    50%      { box-shadow: 0 2px 14px rgba(255,79,109,0.5); }
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 20px;
}
.stat-box {
    background: linear-gradient(180deg, rgba(30,40,55,0.85) 0%, rgba(10,15,22,0.9) 100%);
    border: 1px solid #7a6b4c;
    padding: 15px;
    text-align: center;
    border-radius: 4px;
    box-shadow: inset 0 0 18px rgba(10, 120, 180, 0.12), 0 1px 0 rgba(200,170,110,0.15);
    position: relative;
}
.stat-box::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 4px;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(200,170,110,0.25), transparent 40%, transparent 60%, rgba(200,170,110,0.25));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    padding: 1px;
}
.stat-label {
    color: #a09b8c;
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.stat-value {
    color: #c8aa6e;
    font-size: 26px;
    font-weight: bold;
    text-shadow: 0 0 8px rgba(200,170,110,0.35);
}
.stat-chart-wrap {
    margin-top: 22px;
    padding: 14px;
    background: linear-gradient(180deg, rgba(10,15,22,0.9), rgba(20,30,45,0.7));
    border: 1px solid #7a6b4c;
    border-radius: 4px;
}
.stat-chart-wrap h3 {
    margin: 0 0 10px 0;
    color: #c8aa6e;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
#statChart {
    width: 100%;
    height: 120px;
    display: block;
}
.stat-chart-empty {
    color: #7a6b4c;
    font-size: 13px;
    text-align: center;
    padding: 24px 0;
    display: none;
}

/* Miss toast — matches score/rank card visual language */
.miss-toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    background: linear-gradient(90deg, rgba(30,35,40,0.92) 0%, rgba(20,24,28,0.85) 100%);
    border-left: 4px solid #c85a6e;
    border-radius: 0 5px 5px 0;
    box-shadow: 0 3px 14px rgba(0,0,0,0.55);
    text-shadow: 1px 1px 2px black;
    min-width: 240px;
    z-index: 1500;
    pointer-events: none;
    opacity: 0;
    animation: missIn 0.22s ease-out forwards;
}
.miss-toast.leaving { animation: missOut 0.28s ease-in forwards; }
@keyframes missIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes missOut {
    to { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}
.miss-toast-icon {
    color: #c85a6e;
    font-size: 26px;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 0 10px rgba(200,90,110,0.45);
}
.miss-toast-title {
    color: #c85a6e;
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}
.miss-toast-sub {
    color: #a09b8c;
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 0.03em;
    margin-top: 2px;
}
.miss-toast-sub b { color: #c8aa6e; font-weight: bold; }

/* Floating Gamification Text */
.floating-text {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    letter-spacing: 0.04em;
    font-weight: bold;
    pointer-events: none;
    z-index: 1000;
    animation: floatUp 1.5s ease-out forwards;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.8), -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

@keyframes floatUp {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    10% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}

/* Notifications */
.notification-area {
    position: absolute;
    top: 150px;
    right: 50px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: none;
}

.flash-notification {
    background-color: rgba(0, 0, 0, 0.75);
    border-left: 5px solid #ffcc00;
    color: white;
    padding: 15px 25px;
    font-size: 20px;
    font-weight: bold;
    animation: fadein 0.3s, fadeout 0.5s 6s forwards;
    text-shadow: 1px 1px 2px black;
    box-shadow: 2px 2px 10px rgba(0,0,0,0.5);
}

.flash-notification .role {
    color: #ffcc00;
}

@keyframes fadein {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

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

/* Chat HUD */
.chat-hud {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 450px;
    height: 280px;
    display: flex;
    flex-direction: column;
    pointer-events: none;
}

.chat-hud.active {
    background-color: rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.chat-history {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    margin-bottom: 5px;
    padding: 5px;
    scrollbar-width: thin;
    scrollbar-color: #888 transparent;
    pointer-events: auto; /* allow scrolling & selection */
}

.chat-history::-webkit-scrollbar {
    width: 6px;
}
.chat-history::-webkit-scrollbar-thumb {
    background-color: #888;
}

.chat-message {
    color: #f1f1f1;
    font-size: 15px;
    margin: 2px 0;
    line-height: 1.4;
    text-shadow: 1px 1px 1px #000;
    word-wrap: break-word;
    user-select: text; /* allow text selection */
}

.chat-message-all {
    color: #ff9900;
}

.chat-message-text {
    color: #ffffff;
}

.chat-input-container {
    display: none;
    background-color: rgba(0, 0, 0, 0.65);
    border: 1px solid #7a6b4c;
    padding: 6px 10px;
    align-items: center;
}

.chat-hud.active .chat-input-container {
    display: flex;
}

.chat-prefix {
    color: #ff9900;
    font-size: 15px;
    margin-right: 4px;
    text-shadow: 1px 1px 1px #000;
    white-space: pre;
}

.chat-input {
    background: transparent;
    border: none;
    outline: none;
    color: #ffffff;
    font-size: 15px;
    flex-grow: 1;
    text-shadow: 1px 1px 1px #000;
    font-family: Arial, sans-serif;
    caret-color: #ffffff;
}
