@import url('https://fonts.googleapis.com/css2?family=Jua&family=Nunito:wght@600;700;800;900&display=swap');

:root {
    --ink: #4b4267;
    --muted: #817995;
    --purple: #836bd4;
    --purple-dark: #614aa9;
    --lavender: #eee9ff;
    --peach: #ffcfbd;
    --yellow: #ffe587;
    --mint: #bdebdc;
    --line: #d9d2ec;
    --box-line: #7967a8;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: 'Nunito', sans-serif;
    background:
        radial-gradient(circle at 10% 15%, rgba(255, 225, 151, .38), transparent 28%),
        radial-gradient(circle at 90% 30%, rgba(202, 186, 255, .42), transparent 30%),
        linear-gradient(155deg, #fffaf5 0%, #f3f0ff 55%, #eefaff 100%);
}

button { font: inherit; }

.site-nav {
    min-height: 66px;
    padding: 10px max(4vw, 18px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: rgba(255,255,255,.9);
    border-bottom: 1px solid rgba(93,72,150,.1);
    backdrop-filter: blur(12px);
}

.brand {
    color: var(--purple-dark);
    text-decoration: none;
    font: 400 clamp(21px, 2vw, 28px) 'Jua', sans-serif;
}

.nav-links { display: flex; align-items: center; gap: clamp(8px, 2vw, 26px); }
.nav-links a { padding: 8px 10px; color: #746d83; text-decoration: none; font-weight: 900; border-radius: 14px; }
.nav-links a.active { color: var(--purple-dark); background: var(--lavender); }

.page-shell { width: min(1120px, calc(100% - 28px)); margin: auto; padding: 44px 0 0; }
.game-heading { text-align: center; margin-bottom: 26px; }
.eyebrow { color: var(--purple); font-size: 12px; font-weight: 900; letter-spacing: .18em; }
.game-heading h1 { margin: 8px 0 7px; color: #594589; font: 400 clamp(38px, 5vw, 62px) 'Jua', sans-serif; }
.game-heading p { margin: 0; color: var(--muted); font-size: clamp(14px, 2vw, 18px); }

.game-card {
    position: relative;
    padding: clamp(16px, 3vw, 34px);
    overflow: hidden;
    border: 1px solid rgba(105,82,165,.12);
    border-radius: 34px;
    background: rgba(255,255,255,.88);
    box-shadow: 0 20px 50px rgba(72,54,116,.14);
}

.top-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.difficulty-picker { display: flex; padding: 5px; gap: 4px; border-radius: 18px; background: #f1edfb; }
.difficulty-picker button, .new-game-button {
    min-height: 42px; padding: 0 18px; border: 0; border-radius: 14px; color: #716687; background: transparent; font-weight: 900; cursor: pointer;
}
.difficulty-picker button.active { color: white; background: linear-gradient(135deg, #9a83e8, #7459ca); box-shadow: 0 5px 12px rgba(98,73,172,.23); }
.new-game-button { color: #6a4f1b; background: linear-gradient(180deg, #fff0ac, #ffda70); box-shadow: 0 4px 0 #dfb84d; }

.status-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-bottom: 20px; }
.status-grid div { padding: 10px; text-align: center; border-radius: 18px; background: linear-gradient(160deg, #f8f6ff, #efebfb); }
.status-grid span, .status-grid strong { display: block; }
.status-grid span { color: var(--muted); font-size: 11px; font-weight: 900; }
.status-grid strong { margin-top: 2px; color: #58467f; font-size: clamp(16px, 2.5vw, 23px); }
.status-grid b { color: #dd6f7c; }

.game-layout { display: grid; grid-template-columns: minmax(390px, 590px) minmax(230px, 310px); justify-content: center; align-items: start; gap: clamp(24px, 5vw, 60px); }
.board-column { min-width: 0; }
.sudoku-board {
    width: min(100%, 590px); aspect-ratio: 1; margin: auto; display: grid; grid-template-columns: repeat(9, 1fr); overflow: hidden;
    border: 4px solid var(--box-line); border-radius: 24px; background: white; box-shadow: 0 12px 30px rgba(74,56,120,.18); user-select: none;
}

.cell {
    position: relative; display: grid; place-items: center; min-width: 0; padding: 0; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
    color: #65538f; background: #fff; font-size: clamp(17px, 3.6vw, 32px); font-weight: 900; cursor: pointer; transition: background .12s, transform .12s;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.box-right { border-right: 3px solid var(--box-line); }
.cell.box-bottom { border-bottom: 3px solid var(--box-line); }
.cell.given { color: #4c4263; background: #fff; cursor: default; }
.cell.same-number { color: #4d368d; background: #c2afff; }
.cell.selected { z-index: 1; color: var(--purple-dark); background: #fff0b7; box-shadow: inset 0 0 0 3px #f2bd54; }
.cell.wrong { color: #d04f66; background: #ffe5e8; animation: wobble .28s ease; }
.cell.hint { background: #d9f6ec; animation: pop .35s ease; }
.cell.completed { animation: celebrate .45s ease both; animation-delay: calc(var(--order) * 12ms); }

.message { min-height: 24px; margin: 12px 0 0; text-align: center; color: var(--muted); font-size: 14px; font-weight: 800; }
.message.good { color: #2f9676; }
.message.bad { color: #cf586c; }

.control-panel { padding-top: 6px; }
.number-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.number-pad button {
    aspect-ratio: 1; border: 0; border-radius: 20px; color: #604c91; background: linear-gradient(160deg, #f0ebff, #ddd4fa); box-shadow: 0 5px 0 #c7b8ed; font-size: 27px; font-weight: 900; cursor: pointer;
}
.number-pad button:active, .tool-buttons button:active, .new-game-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #c7b8ed; }
.number-pad button.done { opacity: .32; pointer-events: none; }
.tool-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 19px; }
.tool-buttons button { min-height: 67px; padding: 7px 4px; border: 0; border-radius: 17px; color: #685a7f; background: #fff6f4; font-size: 11px; font-weight: 900; cursor: pointer; }
.tool-buttons span { display: block; margin-bottom: 4px; font-size: 21px; }
.tool-buttons b { color: var(--purple); }
.score-guide { margin-top: 19px; padding: 17px; border-radius: 20px; background: #fff8d9; }
.score-guide h2 { margin: 0 0 5px; font: 400 20px 'Jua', sans-serif; }
.score-guide p { margin: 0; color: #766c5c; font-size: 13px; line-height: 1.55; }

.game-overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(54,43,81,.58); backdrop-filter: blur(6px); }
.game-overlay[hidden] { display: none; }
.result-card { width: min(400px, 100%); padding: 34px 24px; text-align: center; border-radius: 30px; background: #fff; box-shadow: 0 25px 70px rgba(35,25,59,.35); }
.result-icon { font-size: 52px; }
.result-card h2 { margin: 8px 0; font: 400 34px 'Jua', sans-serif; }
.result-card p { margin: 0 0 10px; color: var(--muted); line-height: 1.6; }
.result-card > strong { display: block; margin: 8px 0 20px; color: var(--purple-dark); font-size: 30px; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.result-actions [hidden] { display: none; }
.ranking-overlay-button { min-height: 48px; padding: 0 24px; border: 0; border-radius: 17px; color: #fff; background: linear-gradient(135deg, #967ce9, #6547be); box-shadow: 0 5px 0 #49309c; font-weight: 900; cursor: pointer; }
.primary-button { min-height: 48px; padding: 0 28px; border: 0; border-radius: 17px; color: #594414; background: linear-gradient(180deg, #ffeca0, #ffd365); box-shadow: 0 5px 0 #d8ad44; font-weight: 900; cursor: pointer; }

.ranking-card {
    margin: 24px auto 0;
    padding: clamp(18px, 4vw, 30px);
    border: 1px solid rgba(113, 92, 165, .14);
    border-radius: 28px;
    background: rgba(255,255,255,.88);
    box-shadow: 0 16px 38px rgba(73,55,117,.11);
}
.ranking-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.ranking-header h2 { margin: 0; font: 400 clamp(24px, 3vw, 32px) 'Jua', sans-serif; }
.ranking-header button,
.ranking-submit button {
    min-height: 42px; padding: 0 16px; border: 0; border-radius: 14px; color: #5b4b25;
    background: linear-gradient(180deg, #fff1a7, #ffdb6f); box-shadow: 0 4px 0 #d9b24d; font-weight: 900; cursor: pointer;
}
.ranking-tabs { margin: 18px auto 0; padding: 5px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; border-radius: 17px; background: #f1edfb; }
.ranking-tabs button { min-height: 40px; border: 0; border-radius: 13px; color: #716687; background: transparent; font-weight: 900; cursor: pointer; }
.ranking-tabs button.active { color: #fff; background: linear-gradient(135deg, #9478e8, #6748c4); box-shadow: 0 4px 10px rgba(98,73,172,.25); }
.ranking-submit { margin-top: 16px; padding: 16px; border-radius: 20px; background: linear-gradient(135deg, #f2edff, #fff6d9); }
.ranking-submit[hidden] { display: none; }
.ranking-submit p { margin: 0 0 10px; text-align: center; }
.ranking-submit p strong { color: var(--purple-dark); font-size: 22px; }
.ranking-submit form { display: flex; align-items: center; justify-content: center; gap: 8px; }
.ranking-submit label { font-size: 13px; font-weight: 900; }
.ranking-submit input { width: min(220px, 42vw); min-height: 42px; padding: 0 13px; border: 2px solid #d8cff0; border-radius: 14px; outline: 0; color: var(--ink); background: #fff; font: 800 14px 'Nunito', sans-serif; }
.ranking-submit input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(131,107,212,.14); }
.ranking-status { margin: 18px 0 8px; text-align: center; color: var(--muted); font-size: 13px; font-weight: 800; }
.ranking-status.error { color: #c95468; }
.ranking-status.success { color: #328c70; }
.ranking-list { margin: 0; padding: 0; list-style: none; }
.ranking-item { min-height: 52px; padding: 9px 14px; display: grid; grid-template-columns: 46px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; border-bottom: 1px solid rgba(113,92,165,.1); }
.ranking-item:last-child { border-bottom: 0; }
.ranking-position { color: var(--purple-dark); font-size: 18px; font-weight: 900; }
.ranking-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 900; }
.ranking-score { color: #5b3eae; font-size: 17px; font-weight: 900; }
.ranking-detail { color: var(--muted); font-size: 11px; white-space: nowrap; }

.how-to-play { margin-top: 22px; padding: 20px 25px; display: flex; align-items: center; gap: 16px; border-radius: 24px; background: rgba(255,255,255,.74); }
.how-to-play > div { font-size: 35px; }
.how-to-play p { margin: 0; color: #696178; line-height: 1.65; }
.how-to-play strong { color: var(--ink); font: 400 21px 'Jua', sans-serif; }
.ad-container { width: 100%; min-height: 90px; margin: 26px auto 0; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 20px; background: rgba(255,255,255,.55); }
.adsbygoogle { width: 100%; }
footer { padding: 27px 15px 34px; text-align: center; color: #817a90; font-size: 13px; }
footer a { color: var(--purple-dark); }

@keyframes wobble { 25% { transform: translateX(-4px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }
@keyframes pop { 50% { transform: scale(1.12); } }
@keyframes celebrate { 50% { background: #fff0a6; transform: scale(.9) rotate(2deg); } }

@media (max-width: 780px) {
    .site-nav { min-height: 58px; padding: 8px 14px; align-items: flex-start; flex-direction: column; gap: 3px; }
    .nav-links { width: 100%; justify-content: space-between; }
    .nav-links a { padding: 6px 5px; font-size: 12px; }
    .page-shell { width: min(100% - 14px, 600px); padding-top: 26px; }
    .game-heading { margin-bottom: 18px; }
    .game-heading h1 { font-size: 40px; }
    .game-card { padding: 11px; border-radius: 24px; }
    .top-bar { align-items: stretch; }
    .difficulty-picker { flex: 1; }
    .difficulty-picker button { min-height: 38px; padding: 0 10px; font-size: 12px; }
    .new-game-button { min-height: 48px; padding: 0 13px; font-size: 12px; }
    .status-grid { margin-bottom: 12px; gap: 5px; }
    .status-grid div { padding: 7px 3px; border-radius: 13px; }
    .status-grid span { font-size: 9px; }
    .status-grid strong { font-size: 16px; }
    .game-layout { display: block; }
    .sudoku-board { border-width: 3px; border-radius: 17px; }
    .cell { font-size: clamp(18px, 7vw, 29px); }
    .control-panel { padding-top: 2px; }
    .number-pad { grid-template-columns: repeat(9, 1fr); gap: 4px; }
    .number-pad button { aspect-ratio: auto; min-height: 49px; border-radius: 12px; font-size: 19px; box-shadow: 0 4px 0 #c7b8ed; }
    .tool-buttons { margin-top: 12px; }
    .tool-buttons button { min-height: 55px; }
    .score-guide { display: none; }
    .message { margin-top: 8px; font-size: 12px; }
    .how-to-play { padding: 17px; align-items: flex-start; }
    .how-to-play > div { display: none; }
    .ranking-card { padding: 17px 12px; border-radius: 23px; }
    .ranking-submit form { display: grid; grid-template-columns: 1fr auto; }
    .ranking-submit label { grid-column: 1 / -1; }
    .ranking-submit input { width: 100%; }
    .ranking-item { padding: 9px 5px; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 6px; }
    .ranking-detail { display: none; }
}

@media (max-width: 390px) {
    .number-pad { gap: 3px; }
    .number-pad button { min-height: 44px; padding: 0; font-size: 17px; }
    .tool-buttons button { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
