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

:root {
    --bg: #ffffff;
    --text: #1a1a1b;
    --text-muted: #787c7e;
    --border: #d3d6da;
    --key-bg: #e2e5e9;
    --board-bg: #faf9f6;
    --grid-line: #e8e6e1;
    --cell-empty: transparent;
    --panel-bg: #f3f2ef;
    --overlay: rgba(255, 255, 255, 0.82);
    --accent: #1a1a1b;
}

[data-theme="dark"] {
    --bg: #121213;
    --text: #f8f8f8;
    --text-muted: #818384;
    --border: #3a3a3c;
    --key-bg: #2a2a2c;
    --board-bg: #17171a;
    --grid-line: #232326;
    --panel-bg: #1e1e1f;
    --overlay: rgba(10, 10, 12, 0.8);
    --accent: #f8f8f8;
}

html, body { height: 100%; }

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overflow-x: hidden;
}

.header {
    width: 100%;
    max-width: 520px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.title { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.15em; }
.header-right { display: flex; gap: 4px; }
.icon-btn {
    background: none; border: none; font-size: 1.1rem; color: var(--text-muted);
    cursor: pointer; width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--key-bg); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

.game {
    width: 100%;
    max-width: 520px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
    gap: 14px;
}

.play-area { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; justify-content: center; width: 100%; }

.board-wrap { position: relative; }

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(20, 1fr);
    gap: 1px;
    width: min(300px, 60vw);
    aspect-ratio: 10 / 20;
    background: var(--grid-line);
    border: 2px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.board .b {
    background: var(--board-bg);
}
.board .b.filled {
    border-radius: 2px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), inset 0 -3px 4px rgba(0, 0, 0, 0.18);
}

.sidebar { display: flex; flex-direction: column; gap: 8px; min-width: 96px; }
.panel { background: var(--panel-bg); border-radius: 8px; padding: 8px 10px; text-align: center; }
.panel-label { font-size: 0.68rem; color: var(--text-muted); letter-spacing: 0.05em; }
.panel-val { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.panel.small .panel-val { font-size: 0.95rem; }

.next {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 1px;
    width: 72px;
    aspect-ratio: 1;
    margin: 4px auto 0;
}
.next .b { background: transparent; border-radius: 2px; }
.next .b.filled { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25); }

.controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 340px;
}
.ctrl {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 14px 0;
    font-size: 1.3rem;
    cursor: pointer;
    font-family: inherit;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
.ctrl:active { background: var(--key-bg); transform: scale(0.96); }
.ctrl.wide { grid-column: span 4; font-size: 1rem; font-weight: 600; padding: 12px 0; }

.hint { font-size: 0.76rem; color: var(--text-muted); text-align: center; }

.btn {
    background: var(--accent); color: var(--bg); border: none;
    border-radius: 8px; padding: 10px 22px; font-size: 0.95rem;
    font-weight: 600; cursor: pointer; font-family: inherit;
}

.overlay-msg {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center;
    background: var(--overlay); border-radius: 6px;
}
.overlay-msg.show { display: flex; }
.overlay-inner { text-align: center; }
.overlay-inner p { font-size: 1.3rem; font-weight: 700; margin-bottom: 12px; }

/* PC 넓은 화면: 컨트롤 버튼은 있되 키보드가 주 조작 */
@media (min-width: 560px) {
    .controls { max-width: 300px; }
}
