:root {
  color-scheme: light;
  --paper: #f8f6f0;
  --white: #fffdf8;
  --ink: #20352d;
  --muted: #64736a;
  --line: #dedfd4;
  --green: #2b503f;
  --green-pale: #e8eee4;
  --rust: #b94a2d;
  --rust-hover: #9e3b24;
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); }
body.is-playing { overflow: hidden; overscroll-behavior: none; }
button { touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible { outline: 3px solid #d98440; outline-offset: 3px; }
button:disabled { cursor: default; opacity: .65; }
svg { width: 20px; height: 20px; display: block; flex-shrink: 0; }
.shell { width: min(1200px, calc(100% - 64px)); margin-inline: auto; }
.site-header { border-bottom: 1px solid #e6e5dc; background: var(--white); }
.header-inner {
  min-height: 76px; padding-top: env(safe-area-inset-top); display: grid;
  grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; justify-self: start; padding: 0; border: 0; background: none; font: bold 32px/.95 var(--serif); letter-spacing: -.08em; }
.brand-mark { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 12px; background: var(--rust); color: white; margin-right: 10px; }
.brand-point { color: var(--rust); }
.navigation { display: flex; align-items: center; gap: 4px; }
.navigation button { border: 0; background: none; border-radius: 8px; padding: 10px 15px; color: var(--muted); font-weight: 650; font-size: .9rem; white-space: nowrap; }
.navigation button:hover, .navigation button[aria-current="page"] { background: var(--green-pale); color: var(--green); }
.button, .icon-button { min-height: 42px; display: inline-flex; gap: 8px; justify-content: center; align-items: center; border-radius: 9px; font-size: .9rem; font-weight: 700; }
.button { padding: 9px 14px; border: 1px solid transparent; }
.button-outline, .icon-button { border: 1px solid var(--line); background: var(--white); }
.button-outline:hover, .icon-button:hover, .button-outline[aria-pressed="true"] { background: var(--green-pale); }
.button-primary { background: var(--rust); color: white; }
.button-primary:hover { background: var(--rust-hover); }
.import-button { justify-self: end; white-space: nowrap; }
.icon-button { width: 42px; padding: 0; flex: none; }
.catalog { padding-block: 34px 40px; }
.hero { position: relative; display: grid; align-items: center; min-height: 365px; overflow: hidden; border-radius: 19px; color: #fffdf8; background: #193832; isolation: isolate; }
.hero-image { position: absolute; z-index: -2; inset: 0 0 0 auto; width: 86%; height: 100%; object-fit: cover; object-position: center 47%; }
.hero::after { content: ""; position: absolute; z-index: -1; inset: 0; background: linear-gradient(90deg, #193832 1%, #193832f5 22%, #19383295 47%, #19383200 79%); }
.hero-content { padding: 36px 0 36px clamp(24px, 5vw, 64px); }
.hero-category { display: inline-flex; gap: 7px; align-items: center; color: #f5e6bf; font-size: .87rem; font-weight: 650; }
.hero-category svg { width: 18px; height: 18px; }
.hero h1 { margin: 16px 0 12px; font: normal clamp(2.6rem, 5.3vw, 4.65rem)/.97 var(--serif); letter-spacing: -.065em; }
.hero p { margin: 0 0 23px; color: #f4eee1; font-size: 1rem; }
.hero-button { min-height: 46px; padding-inline: 16px; }
.gallery-section { margin-top: 37px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.section-heading h2, .saved-view h1, .empty-state h2 { font: normal 2.45rem/.98 var(--serif); letter-spacing: -.055em; margin: 0; }
.filters { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.filters button, .edge-filter { border: 1px solid var(--line); background: var(--white); font-size: .86rem; font-weight: 650; padding: 8px 11px; border-radius: 999px; white-space: nowrap; }
.filters button:hover, .filters button[aria-pressed="true"], .edge-filter[aria-pressed="true"] { color: white; background: var(--green); border-color: var(--green); }
.gallery { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 17px; }
.card { position: relative; overflow: hidden; display: block; width: 100%; text-align: left; padding: 0; border: 1px solid var(--line); border-radius: 13px; background: var(--white); transition: transform .18s, box-shadow .18s; }
.card:hover { transform: translateY(-3px); box-shadow: 0 10px 22px #20352d16; }
.card img { display: block; width: 100%; aspect-ratio: 1.58; object-fit: cover; background: var(--green-pale); }
.card-body { padding: 12px 13px 15px; }
.category-label { color: var(--green); font-size: .79rem; font-weight: 700; }
.card-title { display: block; margin-top: 4px; font: bold 1.13rem/1.12 var(--serif); letter-spacing: -.02em; }
.saved-view { padding-block: 42px; }
.saved-view h1 { margin-bottom: 23px; }
.empty-state { text-align: center; border: 1px dashed var(--line); border-radius: 15px; padding: 50px 18px; }
.empty-state .brand-mark { margin: 0 0 16px; }
.empty-state h2 { font-size: 2rem; }
.empty-state p { color: var(--muted); margin: 12px 0 20px; }
.ad-slot { display: grid; place-items: center; font-size: .72rem; color: #657369; border-top: 1px solid var(--line); background: #f0efe8; }
.home-ad { min-height: 67px; padding-bottom: env(safe-area-inset-bottom); }

.play { height: 100vh; height: 100dvh; width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.game-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); background: var(--white); border-bottom: 1px solid var(--line); }
.game-identity, .game-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.game-identity { flex: 1; overflow: hidden; }
.game-actions { flex-shrink: 0; }
.game-title { min-width: 0; }
.game-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: bold clamp(1.05rem, 2.8vw, 1.39rem)/1.12 var(--serif); letter-spacing: -.035em; margin: 0 0 3px; }
.progress-label { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: .78rem; white-space: nowrap; }
.mini-progress { background: #e6e7dc; height: 5px; width: 68px; border-radius: 999px; overflow: hidden; }
.mini-progress span { height: 100%; display: block; background: var(--green); width: 0; transition: width .16s; }
.game-table { min-height: 0; min-width: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
.game-table[data-layout="side"] { grid-template-columns: minmax(0, 1fr) clamp(112px, 19vw, 245px); grid-template-rows: minmax(0, 1fr); }
.surface { position: relative; min-width: 0; min-height: 0; overflow: hidden; isolation: isolate; background: #e9eee5; background-image: radial-gradient(#8a9e884a 1px, transparent 1px); background-size: 15px 15px; }
#board { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#board:active { cursor: grabbing; }
#board:focus-visible { outline-offset: -3px; }
.board-note { position: absolute; left: 50%; top: 11px; transform: translateX(-50%); pointer-events: none; text-align: center; width: max-content; max-width: calc(100% - 22px); padding: 6px 12px; background: #fffdf8ed; border: 1px solid var(--line); border-radius: 14px; font-size: .78rem; }
.board-note:empty { display: none; }
.zoom-buttons, .elapsed { position: absolute; bottom: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--white); display: flex; align-items: center; box-shadow: 0 2px 6px #20352d0f; }
.zoom-buttons { left: 12px; }
.zoom-buttons button { border: 0; background: transparent; border-radius: 7px; }
.zoom-buttons button:hover { background: var(--green-pale); }
.zoom-buttons #fit { min-width: 53px; min-height: 42px; padding: 0 5px; font-size: .78rem; font-weight: 700; }
.elapsed { right: 12px; min-height: 42px; gap: 6px; padding: 0 9px; font-size: .78rem; font-variant-numeric: tabular-nums; }
.elapsed svg { width: 16px; height: 16px; }
.reference-photo { position: absolute; top: 12px; right: 12px; width: min(42%, 288px); pointer-events: none; box-shadow: 0 4px 18px #20352d28; border-radius: 8px; overflow: hidden; border: 3px solid var(--white); background: var(--white); }
.reference-photo img { width: 100%; max-height: 38vh; object-fit: contain; display: block; }
.tray { background: var(--white); border-top: 1px solid var(--line); min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.tray-header { padding: 6px 13px 4px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tray-header > div { display: flex; align-items: baseline; gap: 8px; }
.tray-header h2 { font: bold 1.03rem var(--serif); margin: 0; }
#tray-count { color: var(--muted); white-space: nowrap; font-size: .77rem; }
.edge-filter { display: flex; gap: 4px; align-items: center; min-height: 34px; padding-block: 5px; }
.edge-filter svg { width: 15px; height: 15px; }
.tray-list { display: flex; align-items: flex-start; gap: 6px; padding: 5px 13px 7px; min-height: 84px; overflow: auto hidden; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #b9c5b7 transparent; touch-action: pan-x; }
.tray-piece { width: 70px; height: 70px; flex: 0 0 70px; position: relative; border: 1px solid #e5e7db; border-radius: 9px; background: #f4f4eb; padding: 0; display: grid; place-items: center; user-select: none; touch-action: pan-x; cursor: grab; }
.tray-piece:hover { background: var(--green-pale); }
.tray-piece[aria-pressed="true"] { border-color: var(--rust); background: #f6e8d9; }
.tray-piece.is-dragging { opacity: .3; }
.tray-piece canvas { width: 62px; height: 62px; pointer-events: none; }
.tray-empty { margin: 14px 13px 22px; color: var(--muted); }
[data-layout="side"] .tray { border-top: 0; border-left: 1px solid var(--line); }
[data-layout="side"] .tray-header { flex-wrap: wrap; }
[data-layout="side"] .tray-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); align-content: start; justify-items: center; flex: 1; overflow: hidden auto; padding: 6px; touch-action: pan-y; }
[data-layout="side"] .tray-piece { width: 64px; height: 66px; touch-action: pan-y; }
.game-ad { min-height: calc(44px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
.drag-ghost { position: fixed; z-index: 20; pointer-events: none; width: 74px; height: 74px; transform: translate(-50%, -50%); }

.dialog { padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--white); color: var(--ink); overflow: auto; width: min(460px, calc(100% - 28px)); max-height: calc(100% - 24px); box-shadow: 0 14px 55px #14281f47; }
.dialog::backdrop { background: #10251caa; }
.dialog-photo { display: block; width: 100%; height: min(27vh, 204px); object-fit: cover; }
.dialog-close { position: absolute; top: 10px; right: 10px; }
.dialog-body { padding: 19px 23px 23px; }
.dialog-body h2 { margin: 4px 0 8px; font: normal 2.2rem/1 var(--serif); letter-spacing: -.055em; }
.dialog-body p { color: var(--muted); margin: 10px 0 14px; }
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.size-button { border: 1px solid var(--line); background: var(--paper); min-height: 45px; border-radius: 8px; font-weight: 650; }
.size-button[aria-pressed="true"] { border-color: var(--green); background: var(--green); color: white; }
.dialog-start { margin-top: 15px; width: 100%; min-height: 46px; }
.toast { z-index: 25; position: fixed; bottom: calc(59px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); color: white; background: var(--ink); padding: 10px 15px; box-shadow: 0 4px 15px #20352d24; border-radius: 9px; font-size: .88rem; }

@media (max-width: 940px) {
  .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .shell { width: calc(100% - 28px); }
  .header-inner { min-height: 65px; gap: 5px; }
  .brand { font-size: 25px; }
  .brand-mark { width: 31px; height: 31px; margin-right: 6px; border-radius: 9px; }
  .navigation button { padding: 9px 8px; font-size: .8rem; }
  .import-button { padding: 0; width: 38px; min-height: 38px; }
  .import-label { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
  .catalog { padding-block: 15px 24px; }
  .hero { border-radius: 14px; min-height: 315px; }
  .hero-content { align-self: end; padding: 24px 18px; }
  .hero-image { width: 100%; object-position: 54% 50%; }
  .hero::after { background: linear-gradient(25deg, #15342efa 9%, #193832bd 39%, #19383222 79%); }
  .hero h1 { font-size: clamp(2.35rem, 9.2vw, 3.65rem); margin-block: 9px; }
  .hero p { margin-bottom: 15px; font-size: .9rem; }
  .gallery-section { margin-top: 24px; }
  .section-heading { gap: 12px; margin-bottom: 13px; }
  .section-heading h2 { font-size: 2rem; }
  .filters { flex-wrap: nowrap; overflow-x: auto; padding: 2px 2px 4px; max-width: 100%; scrollbar-width: none; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card-body { padding: 8px 9px 11px; }
  .card-title { font-size: 1.03rem; }
  .game-header { gap: 7px; padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
  .game-identity, .game-actions { gap: 5px; }
  .game-header .icon-button, .game-header .button { width: 39px; min-height: 41px; padding: 0; }
  .tool-button > span:last-child { display: none; }
  .mini-progress { width: 37px; }
  .zoom-buttons { left: 7px; bottom: 7px; }
  .elapsed { right: 7px; bottom: 7px; }
  [data-layout="side"] .tray-header > div { display: block; }
  [data-layout="side"] .board-note { white-space: normal; width: max-content; }
}
@media (max-height: 510px) and (orientation: landscape) {
  .game-ad { min-height: calc(24px + env(safe-area-inset-bottom)); }
  .game-header { padding-block: calc(4px + env(safe-area-inset-top)) 4px; }
  .board-note { top: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::after { transition-duration: 0s !important; }
}
/* Mobile comfort and a quieter, more spacious visual rhythm. */
.home-footer { padding: 8px 20px 30px; text-align: center; color: var(--green); font: italic 1.15rem var(--serif); }
.home-footer span { display: inline-block; margin-top: 8px; color: var(--muted); font: .78rem var(--sans); }
.resume-latest { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; border: 1px solid #d5dfd1; background: #eaf0e5; border-radius: 16px; padding: 12px; margin-bottom: 18px; }
.resume-latest img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; }
.resume-latest > span:first-of-type { flex: 1; min-width: 0; }
.resume-latest strong { display: block; font-size: .92rem; margin-bottom: 4px; }
.resume-latest span span { display: block; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.resume-latest > span:last-child { font-size: 1.6rem; padding: 5px; }
.tray-paging { margin-left: auto; gap: 4px !important; }
.tray-paging .icon-button { min-height: 36px; width: 36px; font-size: 1.5rem; line-height: 1; }
.tray-paging .icon-button:disabled { opacity: .3; }
.game-table { padding-bottom: env(safe-area-inset-bottom); background: var(--white); }
.help-body { padding-top: 35px; }
.help-body h2 { padding-right: 20px; }
.help-steps { padding-left: 22px; color: var(--muted); font-size: .94rem; line-height: 1.6; }
.help-steps li { padding-left: 5px; margin-block: 15px; }
.help-steps strong { color: var(--ink); }
.dialog-body .difficulty-note { font-size: .8rem; line-height: 1.5; margin-top: 0; }
.sizes { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.size-button { min-height: 48px; }
@media (max-width: 700px) {
  .header-inner { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding-top: calc(14px + env(safe-area-inset-top)); }
  .brand { font-size: 30px; letter-spacing: -.06em; }
  .brand-mark { width: 36px; height: 36px; border-radius: 12px; margin-right: 8px; }
  .navigation { grid-row: 2; grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 12px; background: #eeeee5; border-radius: 13px; }
  .navigation button { min-height: 44px; font-size: .9rem; border-radius: 10px; }
  .navigation button[aria-current="page"] { background: var(--white); box-shadow: 0 2px 6px #20352d0d; }
  .import-button { grid-column: 2; grid-row: 1; width: auto; padding: 10px 12px; min-height: 44px; border-radius: 12px; font-size: .82rem; }
  .import-label { position: static; width: auto; height: auto; clip-path: none; overflow: visible; }
  .hero { min-height: 300px; border-radius: 20px; }
  .hero-content { padding: 25px 22px; }
  .hero h1 { font-size: clamp(2.4rem, 10.2vw, 3.65rem); line-height: 1.02; letter-spacing: -.055em; }
  .hero p { line-height: 1.5; max-width: 240px; }
  .hero-button { min-height: 48px; border-radius: 12px; }
  .section-heading { display: block; }
  .section-heading h2 { margin-bottom: 16px; }
  .filters { padding-bottom: 10px; gap: 8px; }
  .filters button { min-height: 44px; padding-inline: 14px; }
  .gallery { gap: 12px; }
  .card { border-radius: 16px; }
  .card img { aspect-ratio: 1.15; }
  .card-body { padding: 11px 11px 14px; }
  .card-title { font-size: 1.08rem; line-height: 1.22; }
  .category-label { font-size: .74rem; }
  .game-header { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
  .game-identity { width: 100%; gap: 10px; }
  .game-title { flex: 1; }
  .game-title h1 { font-size: 1.12rem; }
  .game-actions { display: flex; gap: 6px; }
  .game-header .icon-button, .game-header .button { min-height: 44px; width: 44px; border-radius: 11px; }
  .game-actions .tool-button { flex: 1; width: auto; gap: 7px; padding-inline: 8px; font-size: .8rem; }
  .tool-button > span:last-child { display: inline; }
  .mini-progress { width: 64px; }
  .progress-label { margin-top: 5px; }
  .tray { box-shadow: 0 -4px 16px #20352d08; }
  .tray-header { padding: 9px 10px 4px; }
  .tray-header > div { gap: 6px; }
  .tray-header h2 { font-size: .95rem; }
  #tray-count { font-size: .7rem; }
  .edge-filter { min-height: 44px; padding-inline: 10px; font-size: .78rem; }
  .tray-list { padding: 7px 10px 12px; gap: 8px; min-height: 99px; }
  .tray-piece { width: 76px; height: 76px; flex-basis: 76px; border-radius: 13px; }
  .tray-piece canvas { width: 68px; height: 68px; }
  .tray-piece[aria-pressed="true"] { border: 2px solid var(--rust); box-shadow: 0 0 0 2px #b94a2d22; }
  .zoom-buttons .icon-button { min-height: 44px; width: 44px; }
  .elapsed { min-height: 44px; }
  .dialog { max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); border-radius: 22px; }
  .dialog-body { padding: 20px; }
  .dialog-photo { height: min(24dvh, 190px); }
  .dialog-body h2 { font-size: 1.9rem; line-height: 1.1; }
  .dialog-close { min-height: 44px; width: 44px; border-radius: 50%; }
  .help-body { padding-top: 40px; }
  .toast { bottom: calc(18px + env(safe-area-inset-bottom)); width: max-content; text-align: center; }
}
@media (max-height: 510px) and (orientation: landscape) {
  .game-header { display: flex; gap: 12px; padding-block: 4px; }
  .game-actions .tool-button { flex: none; width: 44px; }
  .game-actions .tool-button > span:last-child { display: none; }
  .tray-list { min-height: 76px; padding-block: 3px; }
  .tray-piece { width: 60px; height: 60px; flex-basis: 60px; }
  .tray-piece canvas { width: 54px; height: 54px; }
  .tray-header { padding-block: 3px; }
  .tray-paging .icon-button, .edge-filter { min-height: 32px; }
  .board-note { font-size: .7rem; padding-block: 4px; }
}
[data-layout="side"] .tray-header > div:first-child { flex-wrap: wrap; width: 100%; gap: 3px 8px; min-width: 0; }
[data-layout="side"] #tray-count { white-space: normal; }
[data-layout="side"] .tray-paging { margin-left: 0; }
@media (max-width: 380px) {
  .tray-header > div:first-child { flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
}
