*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --base-cell-size: 26px; /* 기본 크기 상수 */
    --cell-size: 26px;      /* 줌 레벨에 따라 변하는 크기 */
    --filled-color: #2c3e50;
    --x-color: #e74c3c;
    --preview-fill: rgba(44, 62, 80, 0.6);
    --preview-cross: rgba(231, 76, 60, 0.6);
    --preview-erase: rgba(255, 0, 0, 0.2);
    --hint-bg: #f8f9fa;
    --hint-done-bg: #d1d5db;
    --border-light: #e0e0e0;
    --border-heavy: #555555;
    --toolbar-height: 70px;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    margin: 0; padding: 0;
    background-color: #f0f2f5;
    overflow: hidden;
    display: flex; flex-direction: column; 
    height: 100vh;
    height: 100dvh;
    user-select: none; -webkit-user-select: none;
}

header {
    background: white; padding: 0 12px; height: 45px; flex-shrink: 0;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid #ddd; z-index: 100;
}

/* 제목 말줄임 처리 개선 */
.header-left { 
    display: flex; align-items: center; gap: 8px; 
    overflow: hidden; flex: 1; min-width: 0; margin-right: 8px;
}
.title { 
    font-weight: bold; font-size: 1rem; color: #333; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    flex: 1; /* 남은 공간 모두 차지 */
}

.btn-group { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
    width: 32px; height: 32px; border: 1px solid #ddd; background: white;
    border-radius: 4px; font-size: 1.1rem; cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    padding: 0; flex-shrink: 0;
}
.icon-btn:disabled { opacity: 0.3; }

.chk-btn {
    background: #2c3e50; color: white; border: none; padding: 0 12px;
    height: 32px; border-radius: 4px; font-weight: bold; font-size: 0.85rem; cursor: pointer;
    white-space: nowrap; flex-shrink: 0;
}

.game-viewport {
    flex: 1; overflow: auto; position: relative; background: #e9ecef;
    touch-action: pan-x pan-y; cursor: grab; display: flex;
    -webkit-overflow-scrolling: touch;
}
.game-viewport.locked { touch-action: none; cursor: crosshair; }

.game-board {
    display: grid; background: white; margin: auto;
    border-top: 1px solid var(--border-light);
    border-left: 1px solid var(--border-light);
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    transform-origin: top left; /* 확대 축소 기준점 */
}

.hint, .cell {
    display: flex; justify-content: center; align-items: center;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

.hint { background-color: var(--hint-bg); font-size: 11px; color: #444; font-weight: 500; line-height: 1; transition: background-color 0.2s; }

.hint.col {
    position: sticky; top: 0; z-index: 10;
    flex-direction: column; justify-content: flex-end; 
    padding-bottom: 2px;
    border-bottom: 2px solid var(--border-heavy); 
}
.hint.row {
    position: sticky; left: 0; z-index: 10;
    flex-direction: row; justify-content: flex-end; align-items: center;
    padding-right: 4px;
    border-right: 2px solid var(--border-heavy);
}

.corner {
    position: sticky; top: 0; left: 0; z-index: 20;
    background: #ddd; 
    border-right: 2px solid var(--border-heavy);
    border-bottom: 2px solid var(--border-heavy);
}

.hint.completed { background-color: var(--hint-done-bg); }
.hint.completed .hint-span { color: #888; opacity: 0.7; }

.hint-span { margin: 0 1px; padding: 2px; cursor: pointer; display: inline-block;} 
.hint-span.checked { text-decoration: line-through; color: #ccc; opacity: 0.6; }

.cell { font-size: calc(var(--cell-size) * 0.6); position: relative; } /* 폰트 크기도 셀 크기에 비례 */
.cell.filled { background-color: var(--filled-color); border-color: var(--border-light); }
.cell.crossed { color: var(--x-color); font-weight: 900; }
.cell.crossed::after { content: "×"; }

.thick-r { border-right: 2px solid var(--border-heavy) !important; }
.thick-b { border-bottom: 2px solid var(--border-heavy) !important; }

.cell-coord {
    position: absolute; bottom: 1px; right: 1px;
    font-size: 8px; color: #999; font-family: monospace;
    pointer-events: none; line-height: 1; z-index: 5;
    transform: scale(0.8); transform-origin: bottom right;
}
.cell.filled .cell-coord { color: rgba(255,255,255,0.4); }

.cell.preview-f { background-color: var(--preview-fill); }
.cell.preview-x { color: var(--preview-cross); }
.cell.preview-x::after { content: "×"; }
.cell.preview-erase { background-color: var(--preview-erase); }

.toolbar {
    height: auto;
    min-height: var(--toolbar-height);
    background: white; border-top: 1px solid #ddd;
    display: flex; justify-content: space-around; align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: 5px;
    flex-shrink: 0;
    z-index: 101;
}
.tool-btn {
    flex: 1; height: 60px; border: none; background: transparent;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    gap: 4px; color: #888; cursor: pointer;
    outline: none; -webkit-tap-highlight-color: transparent;
}
.tool-btn.active { color: #2c3e50; font-weight: bold; background-color: #f8f9fa; border-radius: 8px; }
.tool-icon { font-size: 1.4rem; }

#drag-tooltip {
    position: fixed; 
    background-color: rgba(33, 37, 41, 0.95); 
    color: white;
    padding: 6px 12px; 
    border-radius: 8px; 
    font-size: 0.8rem; 
    font-family: monospace;
    pointer-events: none; z-index: 1000; display: none;
    transform: translate(-50%, -130%); 
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    text-align: center;
    white-space: pre-wrap;
    line-height: 1.4;
    border: 1px solid rgba(255,255,255,0.2);
}
.tooltip-accent { color: #f1c40f; font-weight: bold; font-size: 1rem; }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); z-index: 2000;
    display: none; justify-content: center; align-items: center;
    backdrop-filter: blur(2px);
}
.modal-box {
    background: white; padding: 24px; border-radius: 12px;
    width: 80%; max-width: 320px; text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    animation: popIn 0.3s ease-out;
}
@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.modal-msg { margin-bottom: 20px; font-size: 1.1rem; color: #333; line-height: 1.5; font-weight: 500;}
.modal-btn {
    background: #2c3e50; color: white; border: none;
    padding: 12px 30px; border-radius: 6px; font-weight: bold;
    cursor: pointer; font-size: 1rem;
    transition: background 0.2s;
}
.modal-btn:active { background: #1a252f; }