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

:root {
    --bg: #ffffff;
    --text: #1a1a1b;
    --text-muted: #787c7e;
    --border: #d3d6da;
    --key-bg: #e2e5e9;
    --panel-bg: #f3f2ef;
    --floor: #faf6ee;
    --wall: #8d7b68;
    --goal-dot: #d9a73e;
    --overlay: rgba(255, 255, 255, 0.85);
    --accent: #1a1a1b;
}

[data-theme="dark"] {
    --bg: #121213;
    --text: #f8f8f8;
    --text-muted: #818384;
    --border: #3a3a3c;
    --key-bg: #2a2a2c;
    --panel-bg: #1e1e1f;
    --floor: #24211c;
    --wall: #4a4038;
    --goal-dot: #b58a2e;
    --overlay: rgba(10, 10, 12, 0.82);
    --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: 12px 12px calc(14px + env(safe-area-inset-bottom));
    gap: 12px;
}

.topbar {
    width: 100%;
    max-width: 420px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}
.level-label { font-weight: 700; }
.moves { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.mini-btn {
    background: var(--panel-bg); border: 1px solid var(--border); color: var(--text);
    border-radius: 8px; padding: 6px 10px; font-size: 0.78rem; font-weight: 600;
    cursor: pointer; font-family: inherit;
}
.mini-btn:active { background: var(--key-bg); }
.mini-btn:disabled { opacity: 0.35; }

.board-wrap { position: relative; }

.board {
    display: grid;
    gap: 2px;
    background: var(--border);
    border: 3px solid var(--wall);
    border-radius: 10px;
    padding: 2px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
.c {
    width: var(--cell);
    height: var(--cell);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--cell) * 0.62);
    background: var(--floor);
    border-radius: 4px;
    line-height: 1;
}
.c.wall { background: var(--wall); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18), inset 0 2px 0 rgba(255,255,255,0.12); }
.c.void { background: transparent; }
.c.goal::before { content: ''; width: 34%; height: 34%; border: 3px solid var(--goal-dot); border-radius: 50%; }
.c.goal { position: relative; }
.c.goal > span { position: absolute; }
.c.boxgoal { background: #d3f0d0; }
[data-theme="dark"] .c.boxgoal { background: #1f3a22; }

.controls {
    display: grid;
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: 48px 48px;
    gap: 6px;
    justify-content: center;
}
.ctrl {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    font-size: 1.1rem;
    cursor: pointer;
    font-family: inherit;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
.ctrl:active { background: var(--key-bg); transform: scale(0.95); }

.levels { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 420px; }
.lv {
    width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--panel-bg); color: var(--text); font-family: inherit;
    font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.lv.cur { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.lv.done { border-color: #6aaa64; color: #6aaa64; }
.lv:disabled { opacity: 0.3; cursor: default; }

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

.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: 8px; z-index: 5;
}
.overlay-msg.show { display: flex; }
.overlay-inner { text-align: center; padding: 12px; }
.overlay-inner p { font-size: 1.15rem; font-weight: 700; margin-bottom: 12px; white-space: pre-line; }
