:root {
    --bg-top: #f7ead9;
    --bg-bottom: #e8ccb0;
    --card: rgba(255, 247, 237, 0.84);
    --line: rgba(70, 47, 28, 0.18);
    --ink: #2b1d13;
    --muted: #6f5744;
    --accent: #c9582d;
    --accent-strong: #86391d;
    --surface: #fff8ee;
    --surface-strong: #f4e5d2;
    --shadow: rgba(67, 35, 12, 0.16);
    --status-connected: #41a85f;
    --status-syncing: #d29a32;
    --status-info: #4a90e2;
    --status-error: #c9582d;
    --status-idle: #8c7b6a;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.75), transparent 30%),
        linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body {
    min-height: 100vh;
}

.app-shell {
    min-height: 100vh;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.hud-label,
.overlay-kicker {
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 12px;
    color: var(--muted);
}

.overlay-panel h2 {
    margin: 6px 0 0;
    font-size: clamp(28px, 3vw, 42px);
    line-height: 1;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.status-badge {
    display: flex;
    align-items: center;
    min-height: 54px;
    padding-right: 4px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--status-idle);
    box-shadow: 0 0 0 6px rgba(140, 123, 106, 0.18);
}

.status-dot[data-status="connected"] {
    background: var(--status-connected);
    box-shadow: 0 0 0 6px rgba(65, 168, 95, 0.18);
}

.status-dot[data-status="syncing"] {
    background: var(--status-syncing);
    box-shadow: 0 0 0 6px rgba(210, 154, 50, 0.18);
}

.status-dot[data-status="info"] {
    background: var(--status-info);
    box-shadow: 0 0 0 6px rgba(74, 144, 226, 0.18);
}

.status-dot[data-status="error"] {
    background: var(--status-error);
    box-shadow: 0 0 0 6px rgba(201, 88, 45, 0.18);
}

.hud {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.hud-chip {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px 16px;
    box-shadow: 0 14px 30px var(--shadow);
    backdrop-filter: blur(8px);
}

.hud-chip {
    min-width: 102px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stage-wrap {
    flex: 1;
    min-height: 0;
}

.stage-card {
    position: relative;
    border-radius: 28px;
    overflow: hidden;
    background: rgba(255, 250, 243, 0.88);
    border: 1px solid rgba(109, 67, 33, 0.18);
    box-shadow: 0 28px 60px var(--shadow);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 32 / 9;
    background: linear-gradient(180deg, #fff9f3, #f6ead7);
}

.overlay,
.rotate-mask {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    z-index: 3;
    background: linear-gradient(180deg, rgba(252, 244, 234, 0.82), rgba(237, 215, 188, 0.92));
}

.overlay[hidden],
.rotate-mask[hidden] {
    display: none;
}

.overlay-panel,
.rotate-panel {
    max-width: 420px;
    width: min(100%, 420px);
    padding: 24px;
    border-radius: 22px;
    background: rgba(255, 248, 238, 0.94);
    border: 1px solid var(--line);
    box-shadow: 0 18px 40px rgba(79, 46, 20, 0.18);
}

.overlay-panel p,
.rotate-panel p {
    margin: 8px 0 0;
    line-height: 1.5;
    color: var(--muted);
}

.overlay-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.action {
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

.action {
    color: var(--ink);
    background: var(--surface-strong);
}

.action.primary {
    color: #fff;
    background: linear-gradient(180deg, var(--accent), var(--accent-strong));
}

.action:active {
    transform: translateY(1px) scale(0.99);
}

@media (pointer: coarse) {
    .stage-card {
        touch-action: none;
    }
}

@media (max-width: 760px) {
    .app-shell {
        padding: 16px;
        gap: 16px;
    }

    .overlay-panel,
    .rotate-panel {
        padding: 18px;
    }
}
