* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: #f4f7fc; color: #0b1a33; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
[hidden] { display: none !important; }
button:focus-visible, a:focus-visible { outline: 3px solid #8ec7ff; outline-offset: 3px; }
.gem-definitions { position: absolute; overflow: hidden; pointer-events: none; }
.tool-header { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 16px; flex-shrink: 0; min-height: 66px; padding: 10px 28px; background: #fff; border-bottom: 1px solid #e7edf5; }
.tool-plan { justify-self: start; display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 8px; font-size: .8rem; font-weight: 500; }
.tool-plan strong { font-size: .85rem; font-style: italic; font-weight: 800; }
.tool-plan.is-free { color: #16803d; background: #eaf8ef; }
.tool-title { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; font-size: 1.325rem; font-weight: 700; line-height: 1.4; }
.tool-title-icon { display: grid; place-items: center; width: 36px; height: 36px; color: #006acd; font-size: 1.5rem; }
.tool-title-icon > i { display: flex; align-items: center; justify-content: center; line-height: 1; }
.tool-open-link { display: inline-flex; align-items: center; gap: 6px; justify-self: end; color: #69798d; font-size: .9rem; text-decoration: none; white-space: nowrap; }
.tool-open-link:hover { color: #006acd; text-decoration: none; }
.game-main { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 26px; width: 100%; padding: 32px 24px 16px; }
.game-wrapper { display: flex; flex: 1 0 auto; align-items: center; justify-content: center; width: 100%; min-width: 0; }
.matching-layout { display: grid; grid-template-columns: minmax(0, 1.85fr) minmax(0, 1fr); align-items: start; gap: 24px; width: 100%; max-width: 1000px; }
.game-card { min-width: 0; padding: 24px; border: 1px solid #e5ebf3; border-radius: 24px; background: #fff; box-shadow: 0 12px 40px rgba(18, 61, 107, .06); }
.game-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.game-kicker { display: block; margin-bottom: 5px; color: #8895a7; font-size: .75rem; }
.game-heading h2 { margin: 0; color: #315d8d; font-size: 1.5rem; font-weight: 750; letter-spacing: 1px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px; border: 1px solid #dce5f0; border-radius: 9px; font-size: .8rem; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.button.primary { color: #fff; border-color: #006acd; background: #006acd; }
.button.primary:hover:not(:disabled) { background: #0059b3; }
.button.secondary { color: #69798d; background: #fff; }
.button.secondary:hover:not(:disabled) { color: #006acd; border-color: #c7ddf4; background: #f1f6ff; }
.scorecards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.best-hint { margin: 0 0 16px; color: #8895a7; font-size: .7rem; line-height: 1.7; }
.best-score-card { background: #eef6ff; }
.score-card { position: relative; padding: 12px 16px; min-width: 0; border: 1px solid #e6edf6; border-radius: 12px; background: #f8faff; }
.score-card > span:first-child { display: block; margin-bottom: 4px; color: #8895a7; font-size: .72rem; }
.score-card strong { color: #315d8d; font-size: 1.5rem; font-weight: 700; line-height: 1.4; font-variant-numeric: tabular-nums; }
.moves-card { background: #eef6ff; border-color: #d9e9fc; }
.moves-card strong { color: #006acd; }
.moves-card.is-low { background: #fff4e8; border-color: #f1dcc0; }
.moves-card.is-low strong { color: #ae7023; }
.score-gain { position: absolute; right: 10px; bottom: 12px; color: #21824c; font-size: .85rem; font-weight: 700; opacity: 0; pointer-events: none; }
.score-gain.is-showing { animation: score-rise .6s ease-out forwards; }
.goal-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: #8895a7; font-size: .75rem; }
.goal-heading strong { color: #536277; font-weight: 600; font-variant-numeric: tabular-nums; }
.goal-divider { color: #a0adbd; font-weight: 400; }
.goal-track { height: 6px; overflow: hidden; border-radius: 6px; margin-bottom: 18px; background: #edf2f8; }
.goal-track > div { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #78b9ee, #006acd); transition: width .25s ease; }
.board-wrap { position: relative; width: 100%; max-width: 520px; margin: 0 auto; }
.matching-board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); gap: 5px; width: 100%; aspect-ratio: 1; padding: 10px; overflow: hidden; border: 1px solid #d4e0f0; border-radius: 18px; background: linear-gradient(145deg, #edf4ff, #e7eef9); box-shadow: inset 0 2px 6px rgba(39, 75, 120, .05); touch-action: none; user-select: none; }
.gem-cell { display: block; position: relative; min-width: 0; min-height: 0; padding: 0; border: 1px solid rgba(255,255,255,.75); border-radius: 10px; color: inherit; background: rgba(255,255,255,.55); transition: background .15s, border-color .15s; -webkit-tap-highlight-color: transparent; }
.gem-cell:hover { background: rgba(255,255,255,.92); }
.board-row { display: contents; }
.gem-cell:disabled { opacity: 1; cursor: default; }
.gem-cell:focus-visible { z-index: 2; outline: 2px solid #006acd; outline-offset: 0; }
.gem-cell.is-selected { z-index: 1; border: 2px solid #348cdd; background: #fff; box-shadow: 0 0 0 2px rgba(52, 140, 221, .14); }
.gem-cell.is-hint { border-color: #e9b23e; background: #fff9df; animation: hint-glow .65s ease-in-out 3; }
.gem-piece { position: absolute; inset: 2px; pointer-events: none; transform-origin: center; will-change: transform, opacity; }
.gem-piece svg { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 3px 2px rgba(44, 55, 93, .16)); }
.gem-piece.is-moving { animation: gem-slide .24s cubic-bezier(.22,.7,.28,1) both; }
.gem-piece.is-clearing { z-index: 3; animation: gem-pop .22s ease-in both; }
.gem-piece.is-new { animation: gem-arrive .24s ease-out both; }
.combo-toast { position: absolute; top: 43%; left: 50%; z-index: 5; transform: translate(-50%, -50%); padding: 9px 18px; border: 1px solid rgba(255,255,255,.8); border-radius: 30px; color: #fff; background: rgba(43, 92, 148, .9); box-shadow: 0 6px 20px rgba(34, 68, 114, .15); font-size: 1.1rem; font-weight: 750; white-space: nowrap; opacity: 0; pointer-events: none; }
.combo-toast.is-showing { animation: combo-rise .6s ease-out both; }
.game-overlay { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; border: 1px solid #d4e0f0; border-radius: 18px; text-align: center; background: rgba(248, 251, 255, .96); backdrop-filter: blur(5px); }
.overlay-star { color: #e5b947; font-size: 4rem; line-height: 1; text-shadow: 0 3px 12px rgba(223, 182, 60, .15); }
.game-overlay h2 { margin: 0; color: #315d8d; font-size: 1.6rem; font-weight: 750; }
.game-overlay p { max-width: 330px; margin: 0; color: #69798d; font-size: .875rem; line-height: 1.9; }
.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }
.board-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.board-controls > span { color: #8895a7; font-size: .7rem; }
.board-controls > div { display: flex; gap: 8px; }
.small-button { min-height: 34px; padding: 6px 10px; font-size: .75rem; }
.game-status { min-height: 22px; margin: 14px 0 0; color: #69798d; font-size: .78rem; line-height: 1.8; }
.game-sidebar { display: flex; flex-direction: column; gap: 16px; min-width: 0; min-height: var(--sidebar-height, 0px); }
.info-card { min-width: 0; padding: 18px; border: 1px solid #d2dce9; border-radius: 22px; background: transparent; }
.info-card h2 { display: flex; align-items: center; gap: 7px; margin: 0 0 18px; color: #315d8d; font-size: .95rem; line-height: 1.5; font-weight: 600; }
.best-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.best-heading > span { color: #69798d; font-size: .8rem; }
.best-heading i { margin-right: 5px; color: #b78a26; }
.best-heading strong { color: #315d8d; font-size: 1.55rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.best-card > p { margin: 10px 0 0; color: #8895a7; font-size: .72rem; line-height: 1.7; }
.special-legend { display: flex; flex-direction: column; gap: 10px; }
.special-item { display: flex; align-items: center; gap: 13px; }
.legend-art { display: grid; place-items: center; flex-shrink: 0; width: 38px; height: 38px; border: 1px solid #e4eaf3; border-radius: 10px; background: rgba(255,255,255,.8); }
.legend-art svg { width: 38px; height: 38px; filter: drop-shadow(0 2px 1px rgba(44,55,93,.12)); }
.special-copy strong { display: block; margin-bottom: 3px; color: #536277; font-size: .8rem; font-weight: 600; }
.special-copy p { margin: 0; color: #8895a7; font-size: .72rem; line-height: 1.7; }
.gem-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 8px; }
.gem-legend-item { display: flex; flex-direction: column; align-items: center; gap: 6px; color: #69798d; font-size: .7rem; text-align: center; }
.gem-legend-item svg { width: 36px; height: 36px; filter: drop-shadow(0 2px 1px rgba(44,55,93,.12)); }
.panel-note { margin: 16px 0 0; color: #8895a7; font-size: .7rem; line-height: 1.8; }
.gems-card { margin-top: auto; }
.ranking-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ranking-heading h2 { margin: 0; font-size: 1.05rem; }
.ranking-heading h2 i { color: #c7a75d; }
.ranking-refresh { width: 30px; height: 30px; padding: 0; border: 1px solid #dce5f0; border-radius: 8px; color: #79929a; background: #fff; font-size: 21px; }
.ranking-labels { display: flex; justify-content: space-between; margin-top: 15px; padding: 0 4px 8px; border-bottom: 1px solid #e4eaf3; color: #93a3ab; font-size: .65rem; }
.leaderboard-panel { display: flex; flex-direction: column; flex: 1; min-height: 245px; background: #fff; }
/* Keep all six initial rows visible, including when the desktop sidebar is short. */
.leaderboard-scroll { flex: none; height: 216px; min-height: 216px; max-height: 216px; overflow-y: scroll; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #b3ced0 #f4f8f9; scrollbar-gutter: stable; }
.leaderboard-scroll::-webkit-scrollbar { width: 5px; }
.leaderboard-scroll::-webkit-scrollbar-thumb { background: #b3ced0; border-radius: 5px; }
.leaderboard { margin: 0; padding: 0; list-style: none; }
.rank-row { display: flex; align-items: center; gap: 8px; height: 36px; min-height: 36px; padding: 4px; border-bottom: 1px solid #eef2f5; }
.rank-row.is-me { background: #edf7f5; border-radius: 6px; }
.rank-number { flex: 0 0 20px; text-align: center; color: #94a6ae; font-size: .72rem; font-weight: 700; }
.rank-row:nth-child(1) .rank-number { color: #b28c37; }
.rank-row:nth-child(2) .rank-number { color: #79929f; }
.rank-row:nth-child(3) .rank-number { color: #b4856f; }
.rank-avatar { display: grid; place-items: center; flex: 0 0 24px; height: 24px; border-radius: 50%; color: #6d929f; background: #eaf2f5; font-size: .7rem; }
.rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .75rem; }
.rank-score { color: #456977; font-size: .8rem; font-variant-numeric: tabular-nums; }
.list-status { margin: 16px 4px; color: #90a2ab; font-size: .75rem; line-height: 1.8; text-align: center; }
.load-more { width: 100%; min-height: 32px; margin-top: 8px; padding: 6px; border: 1px solid #e0ebed; border-radius: 8px; color: #618391; background: #f7fafb; font-size: .72rem; }
.ranking-note { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid #e4eaf3; color: #93a5ac; font-size: .65rem; text-align: center; }
.score-save { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: #8895a7; font-size: .7rem; line-height: 1.8; }
.score-save:has(#scoreSaveStatus:empty) { display: none; }
.score-save button { padding: 0; border: 0; background: transparent; color: #006acd; font-size: inherit; }
.game-tips { flex-shrink: 0; width: 100%; max-width: 1000px; margin-top: auto; padding: 22px 4px 0; border-top: 1px solid #dfe7f1; color: #66758a; font-size: .8rem; line-height: 1.9; }
.game-tips > h2 { display: flex; align-items: center; gap: 7px; margin: 0 0 16px; color: #315d8d; font-size: .9rem; font-weight: 600; }
.tips-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.tips-grid h3 { margin: 0 0 7px; color: #536277; font-size: .8rem; font-weight: 600; }
.tips-grid p { margin: 0; }
.tips-bottom { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid #e7edf5; color: #8895a7; font-size: .72rem; }
@keyframes gem-slide { from { transform: translate(var(--from-x, 0px), var(--from-y, 0px)); } to { transform: translate(0,0); } }
@keyframes gem-pop { 0% { transform: scale(1); opacity: 1; } 35% { transform: scale(1.2); opacity: 1; filter: brightness(1.3); } 100% { transform: scale(.25) rotate(15deg); opacity: 0; } }
@keyframes gem-arrive { from { transform: scale(.55); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes hint-glow { 50% { box-shadow: 0 0 0 3px rgba(233,178,62,.3); background: #fff3bd; } }
@keyframes score-rise { 0% { transform: translateY(5px); opacity: 1; } 100% { transform: translateY(-24px); opacity: 0; } }
@keyframes combo-rise { 0% { transform: translate(-50%,-20%) scale(.8); opacity: 0; } 20%,65% { transform: translate(-50%,-50%) scale(1); opacity: 1; } 100% { transform: translate(-50%,-85%) scale(1.05); opacity: 0; } }
@media (max-width: 1000px) {
    .matching-layout { grid-template-columns: minmax(0, 1fr); max-width: 620px; gap: 20px; }
    .game-sidebar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 16px; min-height: 0; }
    .leaderboard-panel { grid-column: 1 / -1; }
    .gems-card { margin-top: 0; }
    .game-tips { max-width: 620px; }
    .tips-grid { grid-template-columns: 1fr; gap: 16px; }
}
@media (max-width: 767.98px) {
    .tool-header { padding: 8px 16px; gap: 10px; }
    .tool-plan { padding: 5px 8px; font-size: .72rem; }
    .tool-title { gap: 7px; font-size: 1.175rem; }
    .tool-title-icon { width: 32px; height: 32px; font-size: 1.3rem; }
    .tool-open-link { font-size: .8rem; }
    .game-main { padding: 24px 16px 16px; gap: 22px; }
}
@media (max-width: 575.98px) {
    .tool-header { grid-template-columns: minmax(0, 1fr) auto; }
    .tool-title { grid-column: 1 / -1; grid-row: 1; }
    .tool-plan { grid-column: 1; grid-row: 2; }
    .tool-open-link { grid-column: 2; grid-row: 2; }
    .game-main { padding: 20px 12px 16px; }
    .game-card { padding: 20px 12px 16px; border-radius: 22px; }
    .game-heading { margin: 0 4px 18px; }
    .game-heading h2 { font-size: 1.3rem; }
    .game-kicker { font-size: .68rem; }
    .scorecards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
    .score-card { padding: 10px 12px; }
    .score-card strong { font-size: 1.3rem; }
    .goal-heading { font-size: .7rem; }
    .matching-board { gap: 3px; padding: 6px; border-radius: 14px; }
    .gem-cell { border-radius: 7px; }
    .gem-piece { inset: 0; }
    .gem-piece svg { filter: drop-shadow(0 2px 1px rgba(44,55,93,.15)); }
    .board-controls { gap: 10px; margin-top: 14px; }
    .board-controls > span { width: 100%; text-align: center; }
    .board-controls > div { justify-content: center; width: 100%; }
    .game-status { padding: 0 3px; font-size: .73rem; }
    .game-sidebar { display: flex; align-items: stretch; gap: 16px; }
    .info-card { padding: 20px; border-radius: 20px; }
    .gem-legend { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
    .gem-legend-item { font-size: .65rem; }
    .gem-legend-item svg { width: 30px; height: 30px; }
    .game-overlay { gap: 10px; padding: 18px; border-radius: 14px; }
    .overlay-star { font-size: 3rem; }
    .game-overlay h2 { font-size: 1.3rem; }
    .game-overlay p { font-size: .8rem; }
    .combo-toast { padding: 7px 12px; font-size: .9rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } .combo-toast.is-showing { opacity: 1; } }
