/* ---------- Reset & base ---------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: #111;
    color: #eee;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    display: flex;
    justify-content: center;
    touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---------- Menu ---------- */
#menu-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    width: 100%;
    max-width: 500px;
    height: 100vh;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: #111;
}

#menu-screen h1 {
    font-size: 2.8rem;
    font-weight: 900;
    color: #ffeb3b;
    letter-spacing: 0.04em;
    text-shadow: 0 2px 16px rgba(255, 235, 59, 0.25);
}

#game-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 320px;
}

.game-card {
    background: #1e1e1e;
    border: 1px solid #2e2e2e;
    border-radius: 16px;
    padding: 22px 24px;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s, transform 0.1s, border-color 0.1s;
}

.game-card:active {
    background: #2a2a2a;
    transform: scale(0.97);
    border-color: #444;
}

.game-card-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #eee;
    margin-bottom: 4px;
}

.game-card-sub {
    font-size: 0.8rem;
    color: #777;
    letter-spacing: 0.04em;
}

/* ---------- Game screens ---------- */
.game-screen {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 500px;
    height: 100vh;
    height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ---------- HUD (shared) ---------- */
#hud, #gomoku-hud {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
    flex-shrink: 0;
}

.hud-item {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.hud-label {
    font-size: 0.65rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 2px;
}

#score, #lines {
    font-size: 1.35rem;
    font-weight: 700;
    color: #ffeb3b;
    font-variant-numeric: tabular-nums;
}

#lines {
    color: #4fc3f7;
}

/* push pause button to the far right */
#pause-btn { margin-left: auto; }

.icon-btn {
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: #eee;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:active { background: #444; }

.icon-btn-wide {
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: #eee;
    height: 40px;
    padding: 0 12px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}

.icon-btn-wide:active { background: #444; }

/* ---------- Tetris canvas ---------- */
#canvas-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    min-height: 0;
}

#tetris {
    display: block;
    background: #000;
    outline: 2px solid #444;
    outline-offset: -2px;
    border-radius: 4px;
    box-shadow: 0 0 30px rgba(255, 235, 59, 0.08);
    touch-action: none;
}

/* Pause / Game-over overlay */
#overlay, #gomoku-overlay {
    position: absolute;
    inset: 10px;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    border-radius: 4px;
    z-index: 5;
}

#overlay-text, #gomoku-overlay-text {
    font-size: 2rem;
    font-weight: 800;
    color: #ffeb3b;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
    letter-spacing: 0.05em;
    text-align: center;
}

#overlay-btn, #gomoku-overlay-btn {
    background: #ffeb3b;
    color: #111;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 12px 28px;
    cursor: pointer;
    min-height: 48px;
    min-width: 140px;
}

#overlay-btn:active, #gomoku-overlay-btn:active { transform: scale(0.97); }

/* ---------- Tetris controls ---------- */
#controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
    padding: 10px 12px 14px;
    flex-shrink: 0;
}

.ctrl-btn {
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: #eee;
    border-radius: 14px;
    font-size: 1.6rem;
    line-height: 1;
    padding: 16px 0;
    min-height: 58px;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.05s, transform 0.05s;
}

.ctrl-btn:active, .ctrl-btn.pressed {
    background: #4a4a4a;
    transform: scale(0.96);
}

.ctrl-btn[data-action="down"]     { grid-column: 1 / span 2; }
.ctrl-btn[data-action="hardDrop"] { grid-column: 3; background: #3a2a2a; border-color: #5a3a3a; }
.ctrl-btn[data-action="rotate"]   { background: #2a3a3a; border-color: #3a5a5a; }

/* ---------- Gomoku ---------- */
.gomoku-turn {
    flex: 1;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #eee;
}

#gomoku-canvas-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    min-height: 0;
}

#gomoku {
    display: block;
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
    touch-action: none;
    cursor: crosshair;
}

/* ---------- Landscape ---------- */
@media (orientation: landscape) and (max-height: 500px) {
    #controls { display: none; }
    #hud, #gomoku-hud { padding: 6px 10px; }
    #score, #lines { font-size: 1.1rem; }
}

/* ---------- Desktop ---------- */
@media (hover: hover) and (pointer: fine) and (min-width: 700px) {
    .game-screen { max-width: 420px; }
    #menu-screen { max-width: 420px; }
    .ctrl-btn { font-size: 1.4rem; min-height: 50px; }
    .game-card:hover { background: #252525; border-color: #3a3a3a; }
}
