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

html {
    background: radial-gradient(ellipse at top, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
    min-height: 100%;
    /* Scroll lock without killing background */
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: 'Arial Black', 'Arial', sans-serif;
    background: transparent;   /* gradient lives on html now */
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px 12px;
    overflow: hidden;
    overscroll-behavior: none;
}

/* ── Canvas ── */
#particleCanvas {
    position: fixed; inset: 0;
    pointer-events: none; z-index: 800;
}

/* ── Wrapper ── */
.game-wrapper {
    display: flex; flex-direction: column;
    align-items: center; gap: 16px; width: 100%;
}

/* ── Header ── */
header {
    position: relative; width: 100%;
    display: flex; align-items: center; justify-content: center;
}

.logo { display: flex; align-items: center; gap: 8px;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5)); }

.logo-connect { font-size: 26px; font-weight:900; color:#fff;
    letter-spacing:2px; text-shadow: 2px 2px 0 #e63946; }
.logo-four    { font-size: 52px; font-weight:900; color:#e63946;
    line-height:1; text-shadow: 3px 3px 0 #c1121f; }
.logo-spin    { font-size: 26px; font-weight:900; color:#ffd700;
    letter-spacing:3px; text-shadow: 2px 2px 0 #c99500; }

.header-btns {
    position: absolute; right: 0;
    display: flex; gap: 8px;
}

.icon-btn {
    width: 34px; height: 34px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1); color: #fff;
    font-size: 16px; font-weight:900; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.22);
    border-color: rgba(255,255,255,0.6); transform: scale(1.1); }

/* ── HUD ── */
.hud {
    display: flex; align-items: center; justify-content: center;
    gap: 20px; width: 100%; max-width: 620px;
}

.center-hud {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
}

.player-tag {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 14px; padding: 10px 14px; flex: 1;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
    min-width: 0;
}
.player-tag.right { justify-content: flex-end; }
.player-tag.active {
    border-color: rgba(255,255,255,0.55);
    background: rgba(255,255,255,0.16);
    box-shadow: 0 0 22px rgba(255,255,255,0.12);
}
/* Colored left border for active player */
.player-tag#player1Tag.active { border-left: 4px solid #ff4444; }
.player-tag#player2Tag.active { border-right: 4px solid #ffcc00; }

.tag-disc {
    width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
    box-shadow: inset -3px -3px 6px rgba(0,0,0,0.35),
                inset 2px 2px 5px rgba(255,255,255,0.25);
}
.tag-disc.red    { background: radial-gradient(circle at 35% 35%, #ff6b6b, #c1121f); }
.tag-disc.yellow { background: radial-gradient(circle at 35% 35%, #ffe566, #f0a500); }

.tag-info { display:flex; flex-direction:column; min-width:0; }

.tag-name {
    font-size: 11px; color: rgba(255,255,255,0.65);
    text-transform: uppercase; letter-spacing: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 100px;
    cursor: pointer; border-bottom: 1px dashed transparent;
    transition: border-color 0.2s;
}
.tag-name:hover { border-color: rgba(255,255,255,0.4); }

.tag-score { font-size: 26px; font-weight:900; color:#fff; line-height:1; }

/* ── Dice ── */
.dice-area { display:flex; flex-direction:column; align-items:center; gap:3px; }
.dice-label { font-size:9px; color:rgba(255,255,255,0.5); letter-spacing:2px; }

.dice-box {
    width: 60px; height: 60px; background:#fff; border-radius:12px;
    display:flex; align-items:center; justify-content:center;
    box-shadow: 0 6px 16px rgba(0,0,0,0.4), inset 0 1px 3px rgba(255,255,255,0.8);
    transition: background 0.3s;
}
.dice-box span { font-size:32px; font-weight:900; color:#222; line-height:1; }

.dice-box.is-odd { background: #ffd700; animation: diceBounce 0.4s ease; }
.dice-box.is-odd span { color:#7a4f00; }

@keyframes diceBounce {
    0%,100% { transform:scale(1); }
    40%     { transform:scale(1.28) rotate(-8deg); }
    70%     { transform:scale(0.95) rotate(4deg); }
}

.dice-note {
    font-size:10px; font-weight:bold; color:#ffd700;
    letter-spacing:1px; min-height:14px; text-align:center;
}

.move-counter {
    font-size:11px; color:rgba(255,255,255,0.45); letter-spacing:1px;
}
.move-counter span { color:rgba(255,255,255,0.75); font-weight:bold; }

/* ── Timer bar ── */
.timer-bar-wrap {
    width: 100%; max-width: 620px;
    height: 8px; background: rgba(255,255,255,0.12);
    border-radius: 4px; position: relative; overflow: hidden;
}
.timer-bar {
    height: 100%; width: 100%;
    background: linear-gradient(90deg, #4ade80, #ffd700);
    border-radius: 4px;
    transition: width 1s linear, background 1s linear;
    transform-origin: left;
}
.timer-bar.danger { background: linear-gradient(90deg, #f87171, #ff4444); }
.timer-label {
    position: absolute; right: -28px; top: 50%;
    transform: translateY(-50%);
    font-size: 10px; color: rgba(255,255,255,0.6);
    font-weight: bold;
}

/* ── Board frame ── */
.board-frame {
    background: linear-gradient(160deg, #f7b731 0%, #e67e00 100%);
    border-radius: 22px; padding: 18px 18px 24px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5),
        inset 0 3px 6px rgba(255,255,255,0.3),
        inset 0 -4px 8px rgba(0,0,0,0.25);
    display: inline-block;
    transform-origin: top center;
    /* Both scale and tilt are applied via custom props — no conflict */
    transform: scale(var(--board-scale, 1)) rotate(var(--board-tilt, 0deg));
    transition: transform 0.2s ease;
}
.board-frame.idle-pulse { animation: idleBreath 3s ease-in-out infinite; }

@keyframes idleBreath {
    0%,100% { transform: scale(var(--board-scale, 1)) rotate(var(--board-tilt, 0deg)) translateY(0); }
    50%     { transform: scale(var(--board-scale, 1)) rotate(var(--board-tilt, 0deg)) translateY(-3px); }
}

/* ── Board ── */
.board { display:flex; flex-direction:row; gap:10px; width:fit-content; }

/* ── Column ── */
.column {
    display: flex; flex-direction: column; gap: 8px;
    background: linear-gradient(160deg, #1565c0 0%, #0d47a1 100%);
    border-radius: 12px; padding: 10px 8px 14px;
    position: relative;
    box-shadow: inset 0 3px 6px rgba(255,255,255,0.15),
        inset 0 -3px 6px rgba(0,0,0,0.3), 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    transform-style: preserve-3d;
    transform-origin: center center;
    transition: filter 0.15s, background 0.15s;
}

/* Whole-column hover highlight */
.column:not(.col-full):hover {
    filter: brightness(1.2);
    background: linear-gradient(160deg, #1e7fe0 0%, #1455c0 100%);
}

/* Column full — lock it */
.column.col-full {
    cursor: not-allowed;
    opacity: 0.55;
    filter: grayscale(40%);
}
.column.col-full::before {
    content: '🔒';
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 22px; z-index: 20;
    pointer-events: none;
}

.column::after {
    content: '↺';
    position: absolute; bottom: -2px; left: 50%;
    transform: translateX(-50%);
    font-size: 13px; color: rgba(255,255,255,0.35);
    pointer-events: none; transition: color 0.2s;
}
.column:not(.col-full):hover::after { color: #ffd700; }
.column.col-full::after { display: none; }

/* ── Spin animation ── */
.column.do-spin {
    animation: colFlip 0.75s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes colFlip {
    0%   { transform: rotateX(0deg)   scaleX(1); }
    25%  { transform: rotateX(90deg)  scaleX(0.55); }
    50%  { transform: rotateX(180deg) scaleX(1); }
    75%  { transform: rotateX(270deg) scaleX(0.55); }
    100% { transform: rotateX(360deg) scaleX(1); }
}
.column.do-spin .disc { filter: blur(0.5px) brightness(1.3); }

/* ── Spin axis ── */
.spin-axis {
    position: relative; height: 0;
    margin: 2px -8px; width: calc(100% + 16px);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; overflow: visible;
}
.spin-axis::before {
    content: ''; position: absolute;
    left: 0; right: 0; top: 50%; height: 3px;
    background: linear-gradient(90deg,
        transparent 0%, rgba(255,215,0,0.35) 10%,
        rgba(255,215,0,0.85) 30%, #ffd700 50%,
        rgba(255,215,0,0.85) 70%, rgba(255,215,0,0.35) 90%,
        transparent 100%);
    transform: translateY(-50%);
}
.column.do-spin .spin-axis::before {
    background: linear-gradient(90deg,
        transparent 0%, rgba(255,255,255,0.5) 15%,
        #fff 50%, rgba(255,255,255,0.5) 85%, transparent 100%);
    box-shadow: 0 0 14px rgba(255,215,0,0.9);
}
.spin-axis-label {
    position: relative; z-index: 2;
    background: #0d47a1; border: 2px solid rgba(255,215,0,0.7);
    color: #ffd700; font-size: 8px; font-weight:900;
    letter-spacing:1px; padding: 2px 5px; border-radius:6px;
    white-space:nowrap; text-shadow:0 1px 3px rgba(0,0,0,0.6);
    box-shadow: 0 0 8px rgba(255,215,0,0.3); line-height:1.3;
}

/* Board size picker */
.board-size-btns {
    display: flex; gap: 8px;
}
.board-size-btn {
    flex: 1; background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.7); padding: 10px 6px;
    border-radius: 12px; cursor: pointer;
    font-size: 12px; font-weight: bold; text-align: center;
    line-height: 1.4; transition: all 0.2s; font-family: inherit;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.board-size-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.board-size-btn.active { background: rgba(255,215,0,0.2); border-color: #ffd700; color: #ffd700; }
.bsb-icon {
    font-size: 8px; line-height: 1.5; letter-spacing: 1px;
    color: currentColor; opacity: 0.8;
}
.bsb-label { font-size: 12px; font-weight: 900; }
.board-size-btn small { font-size: 10px; font-weight: normal; opacity: 0.7; }

/* Win length picker */
.winlen-btns { display: flex; gap: 8px; }
.winlen-btn {
    flex: 1; background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.7); padding: 10px 4px;
    border-radius: 12px; cursor: pointer;
    font-size: 13px; font-weight: bold; text-align: center;
    line-height: 1.3; transition: all 0.2s; font-family: inherit;
}
.winlen-btn small { font-size: 10px; font-weight: normal; }
.winlen-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.winlen-btn.active { background: rgba(255,215,0,0.2); border-color: #ffd700; color: #ffd700; }

/* Dynamic cell size via CSS variable */
.cell {
    width: var(--cell-size, 68px);
    height: var(--cell-size, 68px); border-radius: 50%; position:relative;
    background: radial-gradient(circle at 40% 30%, #1a5fb4, #0a2d6e);
    box-shadow: inset 0 4px 10px rgba(0,0,0,0.55),
        inset 0 -2px 4px rgba(255,255,255,0.08), 0 2px 4px rgba(0,0,0,0.4);
    transition: box-shadow 0.15s;
    overflow: hidden;
}
.cell:hover { box-shadow: inset 0 4px 10px rgba(0,0,0,0.55),
    inset 0 -2px 4px rgba(255,255,255,0.08), 0 0 16px rgba(255,255,255,0.22); }

/* Ghost hover */
.cell.ghost::after {
    content:''; position:absolute; inset:6%;
    border-radius:50%; pointer-events:none; z-index:3;
}
.cell.ghost.red::after    { background:radial-gradient(circle at 38% 35%,#ff7b7b,#c1121f 70%); opacity:0.4; }
.cell.ghost.yellow::after { background:radial-gradient(circle at 38% 35%,#ffe97a,#e07b00 70%); opacity:0.4; }

/* ── Discs ── */
.disc {
    position:absolute; inset:6%; border-radius:50%; z-index:2;
    animation: discPop 0.25s cubic-bezier(0.34,1.56,0.64,1);
    transition: opacity 0.5s, filter 0.5s;
}
.disc.no-anim { animation:none; }
.disc::after {
    content:''; position:absolute; top:12%; left:14%;
    width:38%; height:34%;
    background:radial-gradient(ellipse at center,rgba(255,255,255,0.55) 0%,transparent 80%);
    border-radius:50%;
}
.disc.red    { background:radial-gradient(circle at 38% 35%,#ff7b7b,#c1121f 70%);
    box-shadow: inset -3px -3px 8px rgba(0,0,0,0.3), 0 3px 10px rgba(193,18,31,0.5); }
.disc.yellow { background:radial-gradient(circle at 38% 35%,#ffe97a,#e07b00 70%);
    box-shadow: inset -3px -3px 8px rgba(0,0,0,0.2), 0 3px 10px rgba(224,123,0,0.5); }

@keyframes discPop {
    from { transform:scale(0.4); opacity:0.5; }
    to   { transform:scale(1);   opacity:1; }
}

.disc.loser  { opacity:0.15; filter:grayscale(85%) brightness(0.5); }
.disc.winner { animation:winGlow 0.55s ease-in-out infinite alternate; z-index:5; }
@keyframes winGlow {
    from { box-shadow:0 0 10px 2px rgba(255,215,0,0.6); transform:scale(1); }
    to   { box-shadow:0 0 32px 9px rgba(255,215,0,1);   transform:scale(1.14); }
}

/* ── Bottom bar ── */
.bottom-bar {
    display:flex; align-items:center; gap:16px;
    flex-wrap:wrap; justify-content:center;
}
.turn-info {
    font-size:17px; font-weight:bold; color:rgba(255,255,255,0.85);
    letter-spacing:1px; min-width:130px; text-align:center;
}

#resetBtn, #undoBtn {
    background:rgba(255,255,255,0.1); border:2px solid rgba(255,255,255,0.22);
    color:#fff; padding:9px 20px; font-size:14px; font-weight:bold;
    border-radius:50px; cursor:pointer; letter-spacing:0.5px;
    transition:background 0.2s,border-color 0.2s,transform 0.1s,opacity 0.2s;
}
#resetBtn:hover { background:rgba(255,255,255,0.2); border-color:rgba(255,255,255,0.45); }
#resetBtn:active,#undoBtn:active { transform:scale(0.97); }
#undoBtn:disabled { opacity:0.3; cursor:not-allowed; pointer-events:none; }
#undoBtn:not(:disabled):hover { background:rgba(255,193,7,0.2); border-color:rgba(255,193,7,0.5); }

/* ── Spin flash ── */
.spin-flash {
    position:fixed; inset:0; display:flex; align-items:center;
    justify-content:center; pointer-events:none; z-index:900; opacity:0;
}
.spin-flash.show { animation:flashIn 0.9s ease forwards; }
@keyframes flashIn {
    0%   { opacity:0; transform:scale(0.4) rotate(-25deg); }
    30%  { opacity:1; transform:scale(1.15) rotate(3deg); }
    60%  { opacity:1; transform:scale(1) rotate(0deg); }
    100% { opacity:0; transform:scale(0.7) rotate(12deg); }
}
.spin-flash-inner {
    background:linear-gradient(135deg,#ffd700,#ffec6e); color:#7a4f00;
    font-size:60px; font-weight:900; padding:28px 56px; border-radius:24px;
    box-shadow:0 12px 50px rgba(0,0,0,0.5),0 0 60px rgba(255,215,0,0.4);
    text-align:center; letter-spacing:6px;
    display:flex; flex-direction:column; align-items:center; gap:6px;
}
.spin-flash-icon { font-size:68px; animation:spinIcon 0.9s linear; }
@keyframes spinIcon { from{transform:rotate(0deg)} to{transform:rotate(720deg)} }

/* ── Toast ── */
.toast {
    position: fixed; bottom: 110px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30,30,60,0.95); color: #fff;
    padding: 10px 24px; border-radius: 50px;
    font-size: 14px; font-weight: bold; letter-spacing: 0.5px;
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 820; opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Win banner ── */
.win-banner {
    position:fixed; bottom:-220px; left:50%; transform:translateX(-50%);
    z-index:850; transition:bottom 0.55s cubic-bezier(0.34,1.4,0.64,1);
    width:min(500px,92vw);
}
.win-banner.show { bottom:32px; }
.win-banner-inner {
    background:linear-gradient(135deg,#1565c0,#0d47a1);
    border:4px solid #ffd700; border-radius:24px; padding:26px 36px;
    box-shadow:0 16px 60px rgba(0,0,0,0.6),0 0 50px rgba(255,215,0,0.15);
    display:flex; align-items:center; gap:18px; justify-content:center;
}
.win-emoji { font-size:50px; flex-shrink:0; }
.win-title { font-size:34px; font-weight:900; color:#fff;
    text-shadow:2px 2px 0 rgba(0,0,0,0.3); white-space:nowrap; }
.win-actions { display:flex; flex-direction:column; gap:8px; }
#playAgainBtn {
    background:#ffd700; color:#7a4f00; border:none;
    padding:11px 26px; font-size:15px; font-weight:900;
    border-radius:50px; cursor:pointer;
    box-shadow:0 4px 14px rgba(0,0,0,0.3);
    transition:transform 0.15s,box-shadow 0.15s; white-space:nowrap;
}
#playAgainBtn:hover { transform:translateY(-2px); box-shadow:0 8px 22px rgba(0,0,0,0.4); }

/* ── Modals ── */
.modal-backdrop {
    position:fixed; inset:0; background:rgba(0,0,0,0.75);
    z-index:980; display:flex; align-items:center; justify-content:center;
    padding:20px; opacity:0; pointer-events:none; transition:opacity 0.25s;
}
.modal-backdrop.show { opacity:1; pointer-events:all; }

.modal {
    background:linear-gradient(150deg,#1e3c72,#1565c0);
    border:3px solid rgba(255,215,0,0.5); border-radius:24px;
    padding:34px 38px; max-width:480px; width:100%; position:relative;
    box-shadow:0 20px 70px rgba(0,0,0,0.6);
    animation:modalIn 0.3s cubic-bezier(0.34,1.3,0.64,1);
    max-height: 90vh; overflow-y: auto;
}
@keyframes modalIn {
    from { transform:scale(0.85) translateY(20px); opacity:0; }
    to   { transform:scale(1) translateY(0);       opacity:1; }
}

.modal-close {
    position:absolute; top:14px; right:16px;
    background:rgba(255,255,255,0.12); border:none; color:#fff;
    font-size:17px; width:30px; height:30px; border-radius:50%;
    cursor:pointer; display:flex; align-items:center; justify-content:center;
    transition:background 0.2s;
}
.modal-close:hover { background:rgba(255,255,255,0.25); }

.modal-title {
    font-size:24px; font-weight:900; color:#ffd700;
    text-align:center; margin-bottom:24px; letter-spacing:1px;
}

/* Rules */
.rules-steps { display:flex; flex-direction:column; gap:14px; }
.rule-step {
    display:flex; align-items:flex-start; gap:12px;
    background:rgba(255,255,255,0.07); border-radius:12px;
    padding:12px 14px; border:1px solid rgba(255,255,255,0.1);
}
.rule-icon { font-size:24px; flex-shrink:0; width:34px; text-align:center; line-height:1.3; }
.rule-text { font-size:13px; color:rgba(255,255,255,0.88); line-height:1.5; }
.rule-text strong { display:block; color:#fff; font-size:14px; margin-bottom:2px; }

/* Settings */
.settings-modal { max-width: 420px; }

.settings-group {
    margin-bottom: 22px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 22px;
}
.settings-group:last-of-type { border-bottom: none; }
.settings-label {
    font-size: 11px; color: rgba(255,255,255,0.6);
    text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 12px;
}

/* Name inputs */
.name-inputs { display:flex; flex-direction:column; gap:10px; }
.name-input-wrap { display:flex; align-items:center; gap:10px; }
.name-disc {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink:0;
    box-shadow: inset -2px -2px 4px rgba(0,0,0,0.3);
}
.name-disc.red    { background:radial-gradient(circle at 35% 35%,#ff6b6b,#c1121f); }
.name-disc.yellow { background:radial-gradient(circle at 35% 35%,#ffe566,#f0a500); }

.name-input-wrap input {
    flex:1; background:rgba(255,255,255,0.1); border:2px solid rgba(255,255,255,0.2);
    border-radius:10px; padding:8px 14px; color:#fff; font-size:15px; font-weight:bold;
    outline:none; transition:border-color 0.2s;
    font-family: inherit;
}
.name-input-wrap input::placeholder { color:rgba(255,255,255,0.3); }
.name-input-wrap input:focus { border-color:rgba(255,215,0,0.6); }

/* Freq buttons */
.freq-btns { display:flex; gap:8px; }
.freq-btn {
    flex:1; background:rgba(255,255,255,0.08); border:2px solid rgba(255,255,255,0.18);
    color:rgba(255,255,255,0.7); padding:10px 4px; border-radius:12px;
    cursor:pointer; font-size:13px; font-weight:bold; text-align:center;
    line-height:1.3; transition:all 0.2s; font-family:inherit;
}
.freq-btn small { font-size:11px; font-weight:normal; }
.freq-btn:hover { background:rgba(255,255,255,0.15); color:#fff; }
.freq-btn.active {
    background:rgba(255,215,0,0.2); border-color:#ffd700;
    color:#ffd700;
}

/* Toggle */
.toggle-wrap {
    display:flex; align-items:center; gap:12px; cursor:pointer; user-select:none;
}
.toggle-wrap input { display:none; }
.toggle-slider {
    width:44px; height:24px; border-radius:12px; background:rgba(255,255,255,0.15);
    border:2px solid rgba(255,255,255,0.2); position:relative; transition:background 0.2s;
    flex-shrink:0;
}
.toggle-slider::after {
    content:''; position:absolute; top:2px; left:2px;
    width:16px; height:16px; border-radius:50%; background:#fff;
    transition:transform 0.2s; box-shadow:0 2px 4px rgba(0,0,0,0.3);
}
.toggle-wrap input:checked + .toggle-slider { background:#ffd700; border-color:#ffd700; }
.toggle-wrap input:checked + .toggle-slider::after { transform:translateX(20px); }
.toggle-label { font-size:14px; color:rgba(255,255,255,0.85); }

/* Timer secs */
.timer-setting { display:flex; flex-direction:column; gap:12px; }
.timer-secs-wrap {
    display:flex; align-items:center; gap:12px; flex-wrap:wrap;
    font-size:13px; color:rgba(255,255,255,0.7);
    opacity:0.4; pointer-events:none; transition:opacity 0.2s;
}
.timer-secs-wrap.enabled { opacity:1; pointer-events:all; }
.secs-btns { display:flex; gap:6px; }
.secs-btn {
    background:rgba(255,255,255,0.08); border:2px solid rgba(255,255,255,0.18);
    color:rgba(255,255,255,0.7); padding:6px 14px; border-radius:10px;
    cursor:pointer; font-size:13px; font-weight:bold; font-family:inherit;
    transition:all 0.2s;
}
.secs-btn:hover { background:rgba(255,255,255,0.15); color:#fff; }
.secs-btn.active { background:rgba(255,215,0,0.2); border-color:#ffd700; color:#ffd700; }

.settings-save {
    width:100%; background:#ffd700; color:#7a4f00; border:none;
    padding:13px; font-size:16px; font-weight:900; border-radius:14px;
    cursor:pointer; letter-spacing:0.5px; margin-top:6px;
    box-shadow:0 4px 16px rgba(0,0,0,0.3);
    transition:transform 0.15s,box-shadow 0.15s; font-family:inherit;
}
.settings-save:hover { transform:translateY(-2px); box-shadow:0 8px 24px rgba(0,0,0,0.4); }
.settings-save:active { transform:scale(0.98); }

/* ── iOS safe area ── */
.win-banner { padding-bottom: env(safe-area-inset-bottom, 0px); }
body { padding-bottom: env(safe-area-inset-bottom, 0px); }

/* ── Install prompt ── */
.install-prompt {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 50%; transform: translateX(-50%) translateY(120px);
    width: min(420px, 92vw);
    z-index: 860;
    transition: transform 0.5s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.4s;
    opacity: 0; pointer-events: none;
}
.install-prompt.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1; pointer-events: all;
}
.install-prompt-inner {
    background: linear-gradient(135deg, #1e3c72, #1565c0);
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 18px;
    padding: 14px 18px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.install-icon { font-size: 28px; flex-shrink: 0; }
.install-text {
    flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.install-text strong { font-size: 14px; color: #fff; }
.install-text span   { font-size: 12px; color: rgba(255,255,255,0.6); }
.install-actions { display: flex; gap: 8px; flex-shrink: 0; }
#installAccept {
    background: #ffd700; color: #7a4f00; border: none;
    padding: 8px 16px; font-size: 13px; font-weight: 900;
    border-radius: 50px; cursor: pointer;
    transition: transform 0.15s;
}
#installAccept:hover { transform: scale(1.05); }
#installDismiss {
    background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.7); width: 32px; height: 32px;
    border-radius: 50%; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
#installDismiss:hover { background: rgba(255,255,255,0.2); }

/* ══════════════════════════════════════════════════════
   MOBILE & RESPONSIVE
   ══════════════════════════════════════════════════════ */

/* ── Touch UX ── */
* { -webkit-tap-highlight-color: transparent; }
button, .cell, .column { touch-action: manipulation; }

/* ── Portrait: landscape-left is transparent — children flow normally ── */
.landscape-left {
    display: contents;
}

/* ── Portrait ≤ 600px ── */
@media (max-width: 600px) {
    body { padding: 10px 8px; }
    .game-wrapper { gap: 10px; }

    /* Header */
    .logo-four    { font-size: 36px; }
    .logo-connect, .logo-spin { font-size: 16px; }

    /* HUD */
    .hud { gap: 8px; }
    .player-tag { padding: 8px 10px; gap: 8px; }
    .tag-disc   { width: 32px; height: 32px; }
    .tag-name   { font-size: 10px; max-width: 70px; }
    .tag-score  { font-size: 20px; }
    .dice-box   { width: 50px; height: 50px; }
    .dice-box span { font-size: 26px; }

    /* Board */
    .board-frame { padding: 10px 10px 16px; border-radius: 16px; }
    .board  { gap: 6px; }
    .column { padding: 6px 5px 10px; gap: 5px; }
    .cell   { width: 46px; height: 46px; }
    .spin-axis { margin: 2px -5px; width: calc(100% + 10px); }
    .spin-axis-label { font-size: 7px; padding: 1px 3px; }

    /* Bottom */
    .bottom-bar { gap: 8px; }
    .turn-info  { font-size: 14px; min-width: 100px; }
    #resetBtn, #undoBtn { padding: 8px 14px; font-size: 13px; }

    /* Win banner */
    .win-banner { width: 96vw; }
    .win-banner.show { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
    .win-banner-inner { flex-direction: column; gap: 8px; padding: 14px 16px; }
    .win-title  { font-size: 22px; }
    .win-emoji  { font-size: 40px; }

    /* Overlays */
    .spin-flash-inner { font-size: 34px; padding: 16px 28px; }
    .spin-flash-icon  { font-size: 50px; }
    .modal { padding: 20px 14px; border-radius: 16px; }
    .modal-title { font-size: 20px; margin-bottom: 18px; }
    .freq-btns, .board-size-btns { flex-wrap: wrap; }
    .freq-btn, .board-size-btn   { min-width: calc(50% - 4px); }
}

/* ── Portrait ≤ 380px (very small phones) ── */
@media (max-width: 380px) {
    body { padding: 8px 6px; }
    .game-wrapper { gap: 7px; }
    .logo-four    { font-size: 28px; }
    .logo-connect, .logo-spin { font-size: 13px; }
    .player-tag { padding: 6px 8px; }
    .tag-disc   { width: 26px; height: 26px; }
    .tag-score  { font-size: 18px; }
    .dice-box   { width: 44px; height: 44px; }
    .dice-box span { font-size: 22px; }
    .cell       { width: 40px; height: 40px; }
    .board-frame { padding: 8px 8px 12px; }
}

/* ── Landscape phone (max-height ≤ 500px) ───────────────────────────────────
   Side-by-side: controls left, board right.
   landscape-left becomes a real flex column in this mode.            ── */
@media (orientation: landscape) and (max-height: 500px) {
    html, body { height: 100dvh; }

    body {
        padding: 6px 8px;
        align-items: stretch;
    }

    .game-wrapper {
        flex-direction: row;
        align-items: stretch;
        gap: 10px;
        width: 100%;
        height: 100%;
    }

    /* Controls sidebar */
    .landscape-left {
        display: flex;           /* override display:contents */
        flex-direction: column;
        justify-content: space-between;
        gap: 4px;
        flex-shrink: 0;
        width: 155px;
        padding: 4px 0;
    }

    /* Header in sidebar */
    header {
        flex-direction: column;
        align-items: center;
        gap: 2px;
    }
    .header-btns {
        position: static;
        justify-content: center;
    }
    .logo { gap: 4px; }
    .logo-four    { font-size: 26px; }
    .logo-connect, .logo-spin { font-size: 12px; }

    /* HUD stacks vertically */
    .hud {
        flex-direction: column;
        gap: 4px;
        max-width: none;
        width: 100%;
    }
    .player-tag        { width: 100%; padding: 6px 8px; flex: none; }
    .player-tag.right  { justify-content: flex-start; }
    .tag-disc  { width: 28px; height: 28px; }
    .tag-score { font-size: 16px; }
    .tag-name  { font-size: 9px; max-width: 80px; }

    .center-hud {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 8px;
        width: 100%;
    }
    .dice-box        { width: 38px; height: 38px; }
    .dice-box span   { font-size: 20px; }
    .dice-area       { gap: 1px; }
    .dice-label      { font-size: 7px; }
    .dice-note       { font-size: 8px; min-height: 11px; }
    .move-counter    { font-size: 9px; }

    .timer-bar-wrap  { width: 100%; max-width: none; }

    /* Bottom bar stacks vertically */
    .bottom-bar {
        flex-direction: column;
        gap: 4px;
        align-items: stretch;
        width: 100%;
    }
    .turn-info { font-size: 12px; min-width: auto; }
    #resetBtn, #undoBtn {
        padding: 6px 10px; font-size: 11px;
        width: 100%; text-align: center;
    }

    /* Board fills remaining space */
    .board-outer {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
        overflow: hidden;
    }

    .board-frame {
        transform-origin: center center;
        padding: 8px 8px 12px;
        border-radius: 12px;
    }
    .board  { gap: 4px; }
    .column { padding: 5px 4px 8px; gap: 4px; }
    .cell   { width: 36px; height: 36px; }
    .spin-axis       { margin: 1px -4px; width: calc(100% + 8px); }
    .spin-axis-label { font-size: 5px; padding: 1px 2px; }

    /* Win banner */
    .win-banner { width: 96vw; }
    .win-banner.show { bottom: 6px; }
    .win-banner-inner { padding: 10px 16px; gap: 10px; }
    .win-title  { font-size: 20px; }
    .win-emoji  { font-size: 32px; }
    #playAgainBtn { padding: 8px 18px; font-size: 13px; }

    /* Flash + modals */
    .spin-flash-inner { font-size: 28px; padding: 12px 22px; }
    .spin-flash-icon  { font-size: 38px; }
    .modal { max-height: 88dvh; overflow-y: auto; padding: 16px 12px; }
}