:root {
    color-scheme: dark;
    --bg: #17120d;
    --bg-deep: #0e0b08;
    --panel: rgba(44, 32, 22, 0.9);
    --panel-strong: #34251a;
    --panel-edge: rgba(255, 232, 190, 0.14);
    --text: #fff8e9;
    --muted: #c9b99f;
    --gold: #f4bd58;
    --gold-bright: #ffd982;
    --green: #79b963;
    --red: #e46f55;
    --well-bg: #120d09;
    --well-grid: rgba(255, 240, 210, 0.06);
    --shadow: rgba(0, 0, 0, 0.38);
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f6e8c9;
    --bg-deep: #e7cf9f;
    --panel: rgba(255, 250, 235, 0.92);
    --panel-strong: #fffaf0;
    --panel-edge: rgba(86, 53, 28, 0.16);
    --text: #382417;
    --muted: #705c48;
    --well-bg: #2a1d12;
    --well-grid: rgba(255, 240, 210, 0.08);
    --shadow: rgba(78, 48, 26, 0.2);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-height: 100vh;
    margin: 0;
    padding: 22px 18px 82px;
    overflow-x: hidden;
    color: var(--text);
    background:
        radial-gradient(circle at 14% 12%, rgba(244, 189, 88, 0.13), transparent 28rem),
        radial-gradient(circle at 88% 78%, rgba(121, 185, 99, 0.1), transparent 30rem),
        linear-gradient(145deg, var(--bg), var(--bg-deep));
    font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    transition: color 180ms ease, background-color 180ms ease;
}

body::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    content: "";
    opacity: 0.22;
    pointer-events: none;
    background-image: radial-gradient(rgba(255,255,255,0.16) 0.7px, transparent 0.7px);
    background-size: 13px 13px;
    mask-image: linear-gradient(to bottom, black, transparent 86%);
}

button, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.game-shell { width: min(100%, 1000px); margin: 0 auto; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.potato-home-link,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--panel-edge);
    box-shadow: 0 8px 20px var(--shadow);
    backdrop-filter: blur(12px);
}

.potato-home-link {
    gap: 7px;
    padding: 9px 14px;
    border-radius: 999px;
    font-size: 0.84rem;
    font-weight: 800;
    text-decoration: none;
}

.toolbar { display: flex; gap: 8px; }

.icon-button {
    width: 42px;
    padding: 0;
    border-radius: 13px;
    cursor: pointer;
    font-size: 1.08rem;
}

.icon-button:hover,
.potato-home-link:hover { border-color: rgba(244, 189, 88, 0.55); transform: translateY(-1px); }

.hero { text-align: center; }

.eyebrow {
    margin: 0 0 4px;
    color: var(--gold);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(2.45rem, 9vw, 4.4rem);
    line-height: 0.98;
    letter-spacing: -0.065em;
    text-shadow: 0 5px 24px var(--shadow);
}

.subtitle {
    margin: 9px auto 18px;
    color: var(--muted);
    font-size: clamp(0.9rem, 3vw, 1rem);
}

/* ===== Play area ===== */
.play-area {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: clamp(12px, 3vw, 26px);
    width: 100%;
    margin: 0 auto;
}

.well-wrap {
    position: relative;
    flex: 0 0 auto;
}

.well-canvas {
    display: block;
    height: auto;
    background: var(--well-bg);
    border: 1px solid var(--panel-edge);
    border-radius: 14px;
    box-shadow: 0 16px 40px var(--shadow), inset 0 0 40px rgba(0, 0, 0, 0.45);
    touch-action: none;
}

.well-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    border-radius: 14px;
    background: rgba(10, 7, 4, 0.72);
    backdrop-filter: blur(4px);
    transition: opacity 180ms ease;
}
.well-overlay[hidden] { display: none; }

.overlay-card { text-align: center; max-width: 240px; }
.overlay-title { margin: 0 0 6px; font-size: 1.3rem; font-weight: 900; letter-spacing: -0.03em; }
.overlay-text { margin: 0 0 16px; color: var(--muted); font-size: 0.85rem; }

/* ===== Sidebar ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: clamp(120px, 30vw, 168px);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-edge);
    border-radius: 15px;
    box-shadow: 0 12px 28px var(--shadow);
}

.panel-label {
    display: block;
    padding: 9px 12px 4px;
    color: var(--muted);
    font-size: 0.62rem;
    font-weight: 850;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.next-canvas {
    display: block;
    width: calc(100% - 16px);
    height: auto;
    margin: 0 8px 10px;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.22);
}

.stat-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
}

.stat { position: relative; padding: 9px 8px 10px; text-align: center; }
.stat-label { display: block; margin-bottom: 1px; color: var(--muted); font-size: 0.6rem; font-weight: 850; letter-spacing: 0.1em; text-transform: uppercase; }
.stat-value { display: block; font-size: clamp(1rem, 4vw, 1.2rem); font-variant-numeric: tabular-nums; font-weight: 900; }
.stat-value.is-bump { animation: stat-pop 240ms ease-out; }

.game-status {
    min-height: 24px;
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
    text-align: center;
}
.game-status strong { color: var(--gold-bright); }

/* ===== Actions ===== */
.game-actions {
    display: flex;
    justify-content: center;
    gap: 9px;
    margin-top: 18px;
}

.action-button {
    min-height: 44px;
    padding: 10px 18px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--panel-edge);
    border-radius: 13px;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 850;
    box-shadow: 0 8px 20px var(--shadow);
}
.action-button:hover:not(:disabled) { border-color: rgba(244, 189, 88, 0.52); transform: translateY(-1px); }
.action-button:disabled { opacity: 0.45; cursor: default; }
.action-button.primary { color: #382313; background: linear-gradient(145deg, var(--gold-bright), var(--gold)); border-color: transparent; }

/* ===== Touch controls ===== */
.touch-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: min(100%, 460px);
    margin: 16px auto 0;
}
.touch-controls[hidden] { display: none; }

.touch-btn {
    min-height: 56px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--panel-edge);
    border-radius: 14px;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 800;
    box-shadow: 0 8px 18px var(--shadow);
    user-select: none;
    touch-action: manipulation;
}
.touch-btn:active { background: var(--panel-strong); transform: translateY(1px); }
.touch-btn.wide { grid-column: span 4; font-size: 1rem; }

.cloud-status { min-height: 20px; margin: 12px 0 0; color: var(--muted); font-size: 0.72rem; text-align: center; }

/* ===== Result dialog ===== */
.result-dialog {
    width: min(92vw, 430px);
    padding: 0;
    color: var(--text);
    background: transparent;
    border: 0;
}
.result-dialog::backdrop { background: rgba(12, 8, 5, 0.76); backdrop-filter: blur(7px); }
.result-card {
    position: relative;
    overflow: hidden;
    padding: 30px 26px 24px;
    text-align: center;
    background: linear-gradient(145deg, var(--panel-strong), var(--bg));
    border: 1px solid rgba(244, 189, 88, 0.3);
    border-radius: 26px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.55);
}
.result-card::before { position: absolute; inset: -40% -20% auto; height: 180px; content: ""; background: radial-gradient(circle, rgba(244,189,88,0.22), transparent 70%); }
.result-kicker { position: relative; margin: 0 0 5px; color: var(--gold); font-size: 0.72rem; font-weight: 900; letter-spacing: 0.17em; text-transform: uppercase; }
.result-card h2 { position: relative; margin: 0 0 4px; font-size: 2.2rem; letter-spacing: -0.05em; }
.result-summary { position: relative; margin: 6px 0 16px; color: var(--muted); }
.result-summary strong { color: var(--gold-bright); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 19px; padding: 12px 8px; background: rgba(0,0,0,0.16); border-radius: 15px; }
.result-grid strong { display: block; font-size: 1.12rem; font-variant-numeric: tabular-nums; }
.result-grid span { color: var(--muted); font-size: 0.63rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.result-actions { display: flex; justify-content: center; gap: 8px; }

.potato-game-legal { opacity: 0.48 !important; }

@keyframes stat-pop { 50% { transform: scale(1.22); color: var(--gold-bright); } }

@media (max-width: 620px) {
    body { padding: 14px 12px 80px; }
    .topbar { margin-bottom: 14px; }
    .potato-home-link { min-height: 39px; padding: 8px 12px; font-size: 0.76rem; }
    .icon-button { width: 39px; min-height: 39px; }
    h1 { font-size: clamp(2.1rem, 11vw, 3rem); }
    .subtitle { margin-bottom: 12px; }

    /* Stack the info strip above a full-width well so nothing gets clipped. */
    .play-area { flex-direction: column; align-items: center; gap: 10px; }
    .sidebar { order: -1; flex-direction: row; width: 100%; max-width: 420px; align-items: stretch; gap: 9px; }
    .next-panel { flex: 0 0 auto; width: 96px; }
    .next-canvas { height: 56px; }
    .stat-panel { flex: 1; grid-template-columns: repeat(4, 1fr); align-content: center; }
    .game-status { display: none; }

    .game-actions { margin-top: 14px; }
    .action-button { min-height: 42px; padding: 9px 15px; }
}

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