@charset "UTF-8";
/**
 * Tetris-specific layout.
 *
 * Desktop balance:
 *   ┌─────────────────────────────────────────┐
 *   │ TETRIS    [SCORE][LINES][LEVEL][BEST]   │
 *   ├──────────────────┬──────────────────────┤
 *   │                  │  ┌────────────┐      │
 *   │                  │  │ NEXT (96x96)│      │
 *   │   BOARD          │  └────────────┘      │
 *   │   (height-cap    │                      │
 *   │    fits viewport)│  [START]  [PAUSE]    │
 *   │                  │                      │
 *   │                  │  ← → 移動            │
 *   │                  │  ↑   旋轉            │
 *   │                  │  ↓   加速            │
 *   │                  │  Space 直落          │
 *   │                  │  P   暫停            │
 *   └──────────────────┴──────────────────────┘
 *
 * Sidebar is fixed-width 220px (smaller than before — no more bloated
 * cards). All sections inside it use the same surface, divided by
 * subtle borders rather than separate cards. That stops the layout
 * looking like 3 floating boxes.
 */

.mgt {
    color: var(--mg-ink);
    font-family: var(--mg-body);
}

.mgt-stage {
    position: relative;
    display: flex;
    gap: 16px;
    align-items: stretch;
    justify-content: center;
}

.mgt-board {
    display: block;
    background: var(--mg-bg-3);
    border-radius: var(--mg-radius-sm);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* Sizing: take as much vertical room as we can without forcing the
       page to scroll. Reserve ~180px for the .mg-frame padding,
       .mg-header (title + stats), gap, and any touch hint. The min(...)
       clamp keeps the board from getting absurd on huge monitors. */
    height: min(calc(100vh - 180px), 720px);
    /* Floor so the board doesn't get tiny on very short windows
       (like a half-height browser snap). */
    min-height: 420px;
    width: auto;
    aspect-ratio: 1 / 2;
    flex: 0 0 auto;
}
.mg-theme-arcade .mgt-board {
    border: 1px solid var(--mg-line-strong);
}

/* -------------------------------------------------------------------
 * Sidebar — single contiguous card with sections inside.
 *
 * Width is just enough to comfortably fit "←→ 移動" lines + a Start
 * button. Anything wider wastes space (the previous 240px was visibly
 * empty on the right).
 * ------------------------------------------------------------------- */
.mgt-sidebar {
    flex: 0 0 200px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--mg-bg-2);
    border-radius: var(--mg-radius-sm);
    padding: 16px;
    /* Match the board's height so the right column doesn't have a
       trailing empty band below it. align-items: stretch on the
       parent does the heavy lifting; we just declare we'd like to
       fill that space. */
    align-self: stretch;
}
.mg-theme-arcade .mgt-sidebar {
    border: 1px solid var(--mg-line);
}

/* Next preview — small label + centred mini canvas */
.mgt-next {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--mg-line);
}
.mgt-next__label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--mg-ink-subtle);
    font-weight: 600;
    align-self: flex-start;
}
.mgt-next-canvas {
    display: block;
    background: var(--mg-bg-3);
    border-radius: var(--mg-radius-xs);
    width: 96px;
    height: 96px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Action buttons — full-width inside sidebar, stacked vertically */
.mgt-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--mg-line);
}
.mgt-actions .mg-btn {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
}

/* Keyboard reference — denser layout, no surrounding card */
.mgt-controls-help {
    /* No padding — sits flush within the sidebar's padding */
}
.mgt-keys {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}
.mgt-keys li {
    display: grid;
    grid-template-columns: 100px 1fr;
    align-items: center;
    gap: 8px;
    color: var(--mg-ink-muted);
    font-size: 12px;
    line-height: 1.3;
}
.mgt-keys__keys {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: flex-start;
}
.mgt-keys kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    font-family: var(--mg-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--mg-ink);
    background: var(--mg-bg-3);
    border-radius: var(--mg-radius-xs);
    box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

/* -------------------------------------------------------------------
 * Touch hint — visible only on coarse pointers.
 * ------------------------------------------------------------------- */
.mgt-touch {
    margin-top: 12px;
}
@media (any-pointer: fine) and (not (any-pointer: coarse)) {
    .mgt-touch { display: none !important; }
}
.mgt-touch-hint {
    margin: 0;
    text-align: center;
    font-size: 12px;
    color: var(--mg-ink-subtle);
    line-height: 1.4;
}

/* Default: canvas allows normal page scrolling + browser gestures.
   When the game starts, JS adds `is-playing` to the canvas which
   switches to `touch-action: none` so all touch goes to the game.
   When the game ends/pauses, the class is removed and the page is
   scrollable through the canvas again. */
.mgt-board {
    touch-action: pan-y;
    -webkit-user-select: none;
    user-select: none;
}
.mgt-board.is-playing {
    touch-action: none;
}

/* -------- Tablet / narrow desktop -------- */
@media (max-width: 720px) {
    .mgt-stage {
        gap: 12px;
    }
    .mgt-sidebar {
        flex: 0 0 180px;
        padding: 12px;
    }
}

/* -------- Mobile -------- */
@media (max-width: 560px) {
    .mgt-stage {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .mgt-board {
        /* Phones stack vertically: header on top, board, sidebar below.
           Reserve room for header (~110px), mobile sidebar (~120px),
           gestures hint + flash (~50px) = ~280px for chrome. */
        height: min(calc(100vh - 280px), 720px);
        min-height: 380px;
        max-width: 360px;
        margin: 0 auto;
        flex: 0 0 auto;
        /* Override base min-height on small viewports — phones can be
           shorter than 420px in landscape. */
    }
    @supports (height: 100dvh) {
        /* Use dvh on supported browsers — accounts for collapsing
           mobile address bar so the board doesn't get clipped when
           scrolling (Safari iOS, Chrome Android). */
        .mgt-board {
            height: min(calc(100dvh - 280px), 720px);
        }
    }
    .mgt-sidebar {
        flex: 1 1 auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
        padding: 12px;
    }
    /* Hide keyboard hints on touch — gestures replace them */
    .mgt-controls-help { display: none; }
    /* Next compacts — show inline next to actions */
    .mgt-next {
        flex: 0 0 auto;
        flex-direction: row;
        gap: 10px;
        padding-bottom: 0;
        border-bottom: 0;
        align-items: center;
    }
    .mgt-next__label { display: none; }
    .mgt-next-canvas {
        width: 56px;
        height: 56px;
    }
    .mgt-actions {
        flex: 1 1 auto;
        flex-direction: row;
        gap: 6px;
        padding-bottom: 0;
        border-bottom: 0;
    }
    .mgt-actions .mg-btn {
        flex: 1 1 0;
        padding: 8px 12px;
        font-size: 13px;
    }
    .mgt-touch-hint {
        font-size: 11px;
    }
}
