html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button, label, .board-container, .launch-screen, .status-bar, .celebration-container {
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
body { overflow-x: auto; font-size: 18px; }
[hidden] { display: none !important; }
.launch-screen {
    width: 100%; max-width: 520px; margin: 0 auto; aspect-ratio: 2 / 3;
    min-height: 100vh; min-height: 100svh;
    position: relative; isolation: isolate; display: grid; align-items: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.launch-cover { position: absolute; inset: 0; z-index: -1; overflow: hidden; background: #8fcbf0; }
.launch-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center bottom; }
.cover-alternate { opacity: 0; }
.launch-screen.is-playing .cover-alternate { animation: cover-swap 1.4s step-end infinite; }
@keyframes cover-swap { 0% { opacity: 0; } 50% { opacity: 1; } }
.launch-content {
    position: absolute; inset: 0; width: 100%; text-align: center;
}
.launch-content h1 { position: absolute; top: 21%; left: 2px; right: 2px; margin: 0; }
.launch-content .title-logo { width: 100%; max-width: 480px; margin: 0 auto; }
.launch-content p {
    position: absolute; top: 34%; left: 12px; right: 12px; margin: 0;
    font-size: 18px; line-height: 1.6; color: #241b24; text-shadow: 0 1px 3px #fff; font-weight: 600;
}
.launch-difficulty {
    position: absolute; top: 49%; left: 50%; transform: translateX(-50%);
    width: calc(100% - 32px); max-width: 320px;
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
    border: 0; padding: 0; margin: 0; min-width: 0;
}
.launch-difficulty label { cursor: pointer; }
.launch-difficulty input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.launch-difficulty span {
    display: flex; align-items: center; justify-content: center; min-height: 46px;
    border: 2px solid rgba(75, 24, 48, 0.3); border-radius: 8px;
    background: rgba(255, 255, 255, 0.9); color: #4b1830; font-size: 18px; font-weight: 700;
}
.launch-difficulty input:checked + span { border-color: #8d2857; background: #ffcee0; }
.launch-difficulty input:focus-visible + span { outline: 2px solid #713b68; outline-offset: 3px; }
.start-game-btn {
    width: 100%; min-height: 54px; padding: 10px 24px; border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.5); background: var(--primary-pink);
    color: #4b1830; font-size: 22px; line-height: 30px; font-weight: 700;
    cursor: pointer; touch-action: manipulation;
}
.start-game-btn:hover { background: var(--secondary-pink); }
.start-game-btn:active { transform: translateY(1px); }
.launch-content .start-game-btn {
    position: absolute; top: calc(49% + 58px); left: 50%;
    width: calc(100% - 32px); max-width: 320px; transform: translateX(-50%);
}
.launch-content .start-game-btn:active { transform: translate(-50%, 1px); }
.app {
    width: 100%; max-width: 520px; margin: 0 auto;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.title-bar { width: 100%; margin-bottom: 12px; }
.title-bar h1 { font-size: 32px; line-height: 1.4; letter-spacing: 0; margin: 0; color: var(--text-dark); }
.title-logo { display: block; width: 100%; height: auto; }
.title-bar .title-logo { width: 86%; max-width: 360px; margin: 0 auto; }
.game-area {
    width: 100%; min-width: 0; max-width: none; padding: 0; margin: 0;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(190px, 1.45fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "current current" "difficulty difficulty" "target controls";
    gap: 12px; align-items: start;
}
.current-board-section, .target-board-section, .controls-panel {
    width: 100%; min-width: 0; max-width: none; margin: 0; order: initial;
    padding: 0; border: 0; border-radius: 0; box-shadow: none;
    background: none; backdrop-filter: none; overflow: visible; justify-self: stretch;
}
.current-board-section { grid-area: current; }
.target-board-section { grid-area: target; }
.current-board-section h2, .target-board-section h2 {
    width: 100%; font-size: 20px; line-height: 28px; margin-bottom: 8px;
}
.target-board-section h2 { margin: 8px 0 0; }
.board-container { border-radius: 8px; padding: 6px; gap: 2px; margin: 0; }
[data-board="current"], [data-board="target"] {
    width: 100%; height: auto; aspect-ratio: 1;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
}
.cell { min-width: 0; min-height: 0; border-radius: 4px; }
[data-board="target"] { padding: 4px; gap: 1px; }
[data-board="target"] .cell { border-radius: 2px; }
[data-board="target"] .paint-drop { animation: none; }
.difficulty-selector {
    grid-area: difficulty; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    min-width: 0; border: 0; padding: 0; margin: 0; gap: 4px;
}
.difficulty-selector label {
    min-height: 48px; display: grid; grid-template-columns: 20px auto;
    justify-content: center; align-content: center; padding: 6px 0;
    gap: 4px; font-size: 18px; font-weight: 700; line-height: 24px;
}
.difficulty-selector input { width: 20px; height: 20px; flex-shrink: 0; accent-color: #b43466; }
.controls-panel {
    grid-area: controls; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(48px, auto)) auto; gap: 8px;
    padding-top: 0;
}
.action-btn, .utility-btn, .solution-btn {
    min-width: 0; min-height: 56px; width: 100%; border-radius: 8px;
    padding: 8px 3px; font-size: 16px; line-height: 24px; letter-spacing: 0;
    flex-direction: row; flex-wrap: nowrap; gap: 3px; touch-action: manipulation; white-space: nowrap;
}
.action-btn i, .utility-btn i { flex-shrink: 0; }
.action-btn { color: #4b1830; }
.solution-btn { grid-column: 1 / -1; font-size: 16px; }
button:focus-visible, input:focus-visible { outline: 2px solid #713b68; outline-offset: 3px; }
.solution-panel { padding: 12px; border-radius: 8px; }
.solution-panel h3 { font-size: 20px; margin-bottom: 8px; }
.solution-steps li { padding: 8px; font-size: 18px; line-height: 1.6; }
.status-bar {
    gap: 8px; flex-wrap: wrap; padding: 12px 0; margin-top: 8px;
    border: 0; border-radius: 0; background: none; backdrop-filter: none; box-shadow: none;
    font-size: 16px; line-height: 1.6;
}
.move-counter { white-space: nowrap; }
.celebration-message { max-width: calc(100% - 32px); padding: 24px; border-radius: 8px; }
.celebration-message h2 { font-size: 28px; }
@media (prefers-reduced-motion: reduce) {
    .paint-drop { animation: none; }
    .action-btn, .utility-btn, .solution-btn { transition: none; }
}

/* 按视口高度自适应：棋盘始终保持满宽，矮屏上只压缩其他部分的间距和按钮高度，最下面的状态栏可以被挤出屏幕 */
@media (max-height: 860px) {
    .app { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .title-bar { margin-bottom: 8px; }
    .title-bar .title-logo { width: 70%; }
    .game-area { gap: 6px; align-items: stretch; }
    .current-board-section h2 { font-size: 18px; line-height: 24px; margin-bottom: 4px; }
    .difficulty-selector label { min-height: 32px; padding: 0; font-size: 16px; line-height: 20px; }
    .difficulty-selector input { width: 18px; height: 18px; }
    .difficulty-selector { justify-self: center; width: min(100%, 320px); }
    .target-board-section { align-self: end; }
    .controls-panel { align-self: stretch; grid-template-rows: repeat(4, minmax(48px, 1fr)); gap: 5px; }
    .action-btn, .utility-btn, .solution-btn { min-height: 48px; padding-block: 2px; font-size: 15px; line-height: 20px; }
    .status-bar { padding: 6px 0; margin-top: 2px; }
}
@media (max-height: 700px) {
    .title-bar .title-logo { width: 56%; }
    .title-bar { margin-bottom: 4px; }
    .difficulty-selector label { min-height: 28px; }
    .controls-panel { grid-template-rows: repeat(4, minmax(40px, 1fr)); gap: 4px; }
    .action-btn, .utility-btn, .solution-btn { min-height: 40px; font-size: 14px; }
}
