.hitori-main { width: 100%; padding: 0 0 54px; }
.hitori-page-header { padding: 20px 22px; color: #fff; background: var(--color-brand); border-bottom: 4px solid var(--color-accent); }
.hitori-header-inner { width: min(1200px, 100%); margin: 0 auto; }
.hitori-header-inner h1 { margin: 0; color: #fff; font-size: clamp(1.7rem, 4vw, 2.5rem); }
.hitori-header-inner p { margin: 7px 0 0; color: #f3dfce; }
.hitori-page-header .back-link { display: inline-block; margin-bottom: 9px; color: #fff; font-size: .88rem; font-weight: 700; text-underline-offset: 3px; }

.board-section { width: min(760px, calc(100% - 40px)); margin: 22px auto 0; padding: 26px; text-align: center; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 14px; box-shadow: var(--shadow-card); }
.board-section > h2 { margin: 0 0 15px; }
.difficulty-panel { width: min(560px, 100%); margin: 0 auto 16px; padding: 14px 16px; background: #fffaf2; border: 1px solid var(--color-border); border-radius: 10px; }
.difficulty-panel h3 { margin: 0; font-size: 1rem; }
.difficulty-buttons, .game-options, .share-options { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; }
.difficulty-buttons { margin: 10px 0 7px; }
.game-options { width: min(100%, 620px); margin: 0 auto 18px; }
.share-options { width: min(100%, 620px); margin: -8px auto 18px; }
.difficulty-panel button, .game-options button, .share-options button { min-height: 44px; min-width: 112px; padding: 9px 12px; color: var(--color-ink); background: #fff; border: 1px solid var(--color-border); border-radius: 9px; font: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation; }
.difficulty-buttons button { flex: 1 1 120px; }
.difficulty-buttons button span { display: block; margin-top: 2px; color: var(--color-muted); font-size: .74rem; font-weight: 600; }
.difficulty-panel button:hover, .game-options button:hover, .share-options button:hover { background: #f7ead9; border-color: #c8a47f; }
.difficulty-buttons button.active { color: #fff; background: var(--color-brand-strong); border-color: var(--color-brand-strong); }
.difficulty-buttons button.active span { color: #f7ead9; }
button:disabled { cursor: default; opacity: .5; }
#status { min-height: 1.5em; margin: 0; color: var(--color-muted); font-size: .86rem; line-height: 1.5; }

.hitori-board { width: min(100%, 540px); aspect-ratio: 1; margin: 18px auto 0; display: grid; grid-template-columns: repeat(var(--grid-size, 5), minmax(0, 1fr)); grid-template-rows: repeat(var(--grid-size, 5), minmax(0, 1fr)); overflow: hidden; background: #fff; border: 3px solid var(--color-brand-strong); border-radius: 3px; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.hitori-cell { position: relative; min-width: 0; min-height: 0; width: auto; padding: 0; display: grid; place-items: center; color: var(--color-ink); background: #fff; border: 0; border-right: 1px solid #a9937e; border-bottom: 1px solid #a9937e; border-radius: 0; font: 750 clamp(.95rem, 5vw, 1.75rem)/1 Arial, sans-serif; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.hitori-cell.last-column { border-right: 0; }
.hitori-cell.last-row { border-bottom: 0; }
.hitori-cell::after { position: absolute; top: 4px; right: 5px; display: none; font: 900 clamp(.55rem, 1.8vw, .78rem)/1 Arial, sans-serif; }
.hitori-cell.shaded { color: #fff; background: #303842; text-decoration: line-through 2px #fff; }
.hitori-cell.shaded::after { display: block; content: "×"; color: #fff; }
.hitori-cell.confirmed { color: #173b28; background: #e6f4e9; box-shadow: inset 0 0 0 3px #4e8060; }
.hitori-cell.confirmed::after { display: block; content: "✓"; color: #23603b; }
.hitori-cell.selected { outline: 4px solid var(--color-accent); outline-offset: -4px; z-index: 1; }
.hitori-cell:focus-visible { outline: 4px solid var(--color-accent); outline-offset: -4px; z-index: 2; }
.hitori-cell.hinted { animation: hint-pulse 1s ease-in-out 2; box-shadow: inset 0 0 0 5px #c27a00; z-index: 1; }
.hitori-board.solved { box-shadow: 0 0 0 5px #4e8060, 0 8px 22px rgba(35, 96, 59, .25); }
.hitori-board.is-busy { opacity: .72; }
.puzzle-code { margin: 9px auto 0; color: var(--color-muted); font: 700 .78rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; }
#status[data-kind="error"] { color: #9c2f25; font-weight: 700; }
#status[data-kind="success"] { color: #23603b; font-weight: 800; }
#status[data-kind="hint"] { color: #765000; font-weight: 700; }
#status[data-kind="notice"] { color: #5d4a36; font-weight: 700; }
@keyframes hint-pulse { 50% { transform: scale(.92); background-color: #fff2bd; } }
.tap-help { margin: 14px auto 0; color: var(--color-muted); font-size: .92rem; line-height: 1.5; }

.state-key { width: min(100%, 540px); margin: 14px auto 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 16px; color: var(--color-muted); font-size: .84rem; }
.state-key > span { display: inline-flex; align-items: center; gap: 6px; }
.key-cell { position: relative; width: 30px; height: 30px; display: inline-grid; place-items: center; color: var(--color-ink); background: #fff; border: 1px solid #a9937e; border-radius: 3px; font-style: normal; font-weight: 800; }
.key-cell.shaded { color: #fff; background: #303842; text-decoration: line-through 1px #fff; }
.key-cell.shaded::after, .key-cell.confirmed::after { position: absolute; top: 1px; right: 2px; font-size: 9px; font-weight: 900; }
.key-cell.shaded::after { content: "×"; }
.key-cell.confirmed { color: #173b28; background: #e6f4e9; box-shadow: inset 0 0 0 2px #4e8060; }
.key-cell.confirmed::after { content: "✓"; color: #23603b; }

.rules-card { width: min(100%, 560px); margin: 20px auto 0; text-align: left; border: 1px solid var(--color-border); border-radius: 10px; background: #fff; }
.rules-card summary { padding: 13px 15px; font-weight: 800; cursor: pointer; }
.rules-content { padding: 0 16px 14px; line-height: 1.55; }
.rules-content p:first-child { margin-top: 0; }
.rules-content ul { padding-left: 22px; }
.rules-content li + li { margin-top: 7px; }
.phase-note { width: min(100%, 560px); margin: 16px auto 0; color: var(--color-muted); font-size: .8rem; line-height: 1.45; }

.code-dialog { width: min(430px, calc(100% - 28px)); max-height: calc(100dvh - 24px); padding: 22px; overflow: auto; color: var(--color-ink); background: #fffdf8; border: 2px solid var(--color-brand-strong); border-radius: 12px; box-shadow: 0 18px 55px rgba(45, 28, 17, .35); overscroll-behavior: contain; }
.code-dialog::backdrop { background: rgba(32, 24, 19, .58); }
.code-dialog h2 { margin: 0 0 8px; }
.code-dialog p { margin: 0 0 14px; }
.code-dialog label { display: block; margin-bottom: 6px; font-weight: 800; }
.code-dialog input { width: 100%; min-height: 46px; padding: 9px 11px; color: var(--color-ink); background: #fff; border: 1px solid #9f856d; border-radius: 7px; font: 700 1rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.code-dialog .dialog-error { min-height: 1.4em; margin: 8px 0 0; color: #9c2f25; font-size: .86rem; font-weight: 700; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dialog-actions button { min-height: 44px; padding: 8px 14px; color: var(--color-ink); background: #fff; border: 1px solid var(--color-border); border-radius: 8px; font: inherit; font-weight: 800; cursor: pointer; }

.celebration { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; overflow: hidden; background: rgba(43, 25, 14, .72); }
.celebration[hidden] { display: none; }
.celebration-card { position: relative; z-index: 2; width: min(430px, 100%); padding: 38px 28px 30px; text-align: center; background: #fffaf2; border: 4px solid var(--color-accent); border-radius: 22px; box-shadow: 0 28px 80px rgba(20, 10, 4, .45); animation: hooray-pop .55s cubic-bezier(.2, .85, .25, 1.25) both; }
.celebration-star { width: 70px; height: 70px; margin: -76px auto 12px; display: grid; place-items: center; color: #fff; background: var(--color-accent); border: 5px solid #fffaf2; border-radius: 50%; font-size: 2rem; box-shadow: 0 6px 18px rgba(65, 35, 10, .25); }
.celebration-kicker { margin: 0 0 4px; color: #23603b; font-size: .78rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.celebration-card h2 { margin: 0; color: var(--color-brand-strong); font-size: clamp(2.4rem, 10vw, 4rem); line-height: 1; }
.celebration-card p:last-of-type { margin: 12px 0 22px; font-size: 1.05rem; }
.celebration-card button { min-width: 130px; min-height: 44px; padding: 10px 18px; color: #fff; background: var(--color-brand); border: 1px solid var(--color-brand); border-radius: 9px; font: inherit; font-weight: 800; cursor: pointer; }
.confetti-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -12vh; left: var(--left); width: var(--width); height: var(--height); background: var(--color); border-radius: 2px; animation: confetti-fall var(--duration) linear var(--delay) forwards; }
.balloon { position: absolute; z-index: 1; bottom: -130px; width: 78px; height: 96px; background: var(--balloon-color); border-radius: 50% 50% 48% 48%; box-shadow: inset -12px -8px 0 rgba(0,0,0,.08), inset 12px 8px 0 rgba(255,255,255,.14); animation: balloon-rise 3.2s ease-out forwards; }
.balloon::before { content: ''; position: absolute; left: 32px; bottom: -10px; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 12px solid var(--balloon-color); }
.balloon::after { content: ''; position: absolute; top: 100%; left: 39px; width: 1px; height: 130px; background: rgba(255,255,255,.7); }
.balloon-left { left: 8%; --balloon-color: #d9553f; animation-delay: .1s; }
.balloon-right { right: 8%; --balloon-color: #e3a91b; animation-delay: .45s; }
@keyframes hooray-pop { from { opacity: 0; transform: translateY(24px) scale(.75); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes confetti-fall { from { transform: translate3d(0, -10vh, 0) rotate(0deg); } to { transform: translate3d(var(--drift), 120vh, 0) rotate(var(--turn)); } }
@keyframes balloon-rise { from { transform: translateY(0) rotate(-4deg); } to { transform: translateY(-92vh) rotate(6deg); } }

@media (max-width: 760px) { .hitori-page-header { padding: 14px; } }
@media (max-width: 600px) {
    .hitori-main { padding-bottom: 36px; }
    .board-section { width: calc(100% - 20px); padding: 18px 6px; }
    .difficulty-panel { padding: 12px 10px; }
    .difficulty-buttons { display: grid; grid-template-columns: repeat(3, 1fr); }
    .difficulty-buttons button { min-width: 0; padding-inline: 5px; }
    .game-options { display: grid; grid-template-columns: repeat(3, 1fr); }
    .game-options #check-puzzle { grid-column: span 2; }
    .share-options { display: grid; grid-template-columns: repeat(2, 1fr); }
    .game-options button, .share-options button { min-width: 0; width: 100%; padding-inline: 5px; }
    .hitori-cell { font-size: clamp(.88rem, 6vw, 1.45rem); }
    .hitori-board[data-size="9"] .hitori-cell { font-size: clamp(.8rem, 5vw, 1.2rem); }
    .hitori-cell::after { top: 2px; right: 3px; font-size: clamp(.48rem, 2.3vw, .68rem); }
}
@media (max-width: 350px) {
    .difficulty-buttons button, .game-options button, .share-options button { font-size: .84rem; }
    .state-key { gap: 8px; }
}
@media (prefers-contrast: more) {
    .hitori-cell { border-color: #34271e; }
    .hitori-cell.confirmed { box-shadow: inset 0 0 0 4px #155b2e; }
}
@media (prefers-reduced-motion: reduce) {
    .celebration-card { animation: none; }
    .confetti-layer, .balloon { display: none; }
}

@media print { body { display: none; } }
