:root {
    --bg: #1a1a2e;
    --card: #16213e;
    --accent: #e94560;
    --primary: #3949ab;
    --text: #fff;
    --cell-closed: #2a3f6f;
    --cell-open: #0f1b30;
    --cell-border: #1e2d50;
    --flag-color: #e94560;
    --mine-color: #e53935;
    --num1: #64b5f6; --num2: #81c784; --num3: #ef9a9a; --num4: #ce93d8;
    --num5: #ffcc80; --num6: #80deea; --num7: #f48fb1; --num8: #bcaaa4;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', sans-serif; user-select: none; }

body {
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
    touch-action: manipulation;
}

.app-container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 8px;
    padding: 10px;
    overflow: hidden;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }
h1 { font-size: 1.8rem; color: var(--accent); }

.global-hub-btn {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; background: rgba(255,255,255,0.1);
    border-radius: 8px; text-decoration: none; font-size: 1.5rem;
    border: 1px solid rgba(255,255,255,0.2); transition: 0.2s;
}
.global-hub-btn:active { transform: scale(0.9); }

select {
    background: var(--card); color: #fff;
    padding: 6px 10px; border-radius: 6px;
    border: 1px solid var(--accent); font-size: 0.95rem; outline: none;
    touch-action: manipulation;
}

.controls-bar { flex-shrink: 0; }

.preset-tabs {
    display: flex;
    gap: 6px;
    width: 100%;
}

.preset-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: var(--card);
    color: #aaa;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.2s;
    touch-action: manipulation;
}
.preset-btn.active { background: var(--primary); color: #fff; }
.preset-btn:active { transform: scale(0.97); }

.custom-panel {
    background: var(--card);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.custom-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.custom-row label { min-width: 55px; font-size: 0.9rem; color: #aaa; }
.custom-row input[type=range] { flex: 1; accent-color: var(--primary); touch-action: manipulation; }
.custom-row span { min-width: 30px; text-align: right; font-weight: bold; }

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 1rem;
    font-weight: bold;
    flex-shrink: 0;
    gap: 8px;
}

.action-btns {
    display: flex;
    gap: 6px;
    flex: 1;
    justify-content: center;
}

.btn {
    padding: 9px 12px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
    touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: #2c3e6b; }
.btn.secondary.active { background: var(--accent); }
.btn.danger { background: #e53935; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Board scroll - only the board scrolls, not the page */
.board-scroll-outer {
    flex: 1;
    overflow: hidden;
    border-radius: 10px;
    background: var(--card);
    position: relative;
    min-height: 0;
}

.board-scroll-inner {
    width: 100%;
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: none;
    padding: 6px;
    box-sizing: border-box;
    cursor: grab;
}
.board-scroll-inner.panning { cursor: grabbing; }

.mine-board {
    display: inline-grid;
    /* all sizing set by JS inline style */
}

.mine-cell {
    /* width/height/font-size set by JS inline style — square guaranteed */
    border-radius: 3px;
    background: var(--cell-closed);
    border: 1px solid rgba(255,255,255,0.07);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.1s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}
.mine-cell:active { opacity: 0.75; }

.mine-cell.open {
    background: var(--cell-open);
    border-color: var(--cell-border);
    cursor: default;
}
.mine-cell.open:active { transform: none; }

.mine-cell.flagged::after {
    content: '🚩';
    font-size: inherit;
}
.mine-cell.mine-hit {
    background: var(--mine-color) !important;
}
.mine-cell.mine-revealed {
    background: #2a1a1a;
    border-color: #5a2a2a;
}
.mine-cell.mine-revealed::after {
    content: '💣';
    font-size: inherit;
}

.num-1 { color: var(--num1); }
.num-2 { color: var(--num2); }
.num-3 { color: var(--num3); }
.num-4 { color: var(--num4); }
.num-5 { color: var(--num5); }
.num-6 { color: var(--num6); }
.num-7 { color: var(--num7); }
.num-8 { color: var(--num8); }

/* Modals */
.modal {
    display: none;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    z-index: 100;
    justify-content: center; align-items: center;
    padding: 1rem;
}
.modal-content {
    background: var(--card);
    padding: 24px;
    border-radius: 14px;
    max-width: 360px;
    width: 100%;
    text-align: center;
}
.modal-content h2 { font-size: 1.7rem; color: var(--accent); margin-bottom: 0.7rem; }
.modal-content p { opacity: 0.85; margin-bottom: 0.5rem; line-height: 1.5; }
.modal-btns { display: flex; gap: 10px; margin-top: 1rem; }
.modal-btns .btn { flex: 1; }

/* desktop-only visibility handled by JS */
@media (max-width: 480px) {
    .status-bar { font-size: 0.85rem; }
    .action-btns { gap: 4px; }
    .btn { padding: 7px 8px; font-size: 0.8rem; }
}
