:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #263a30;
  background: #f7f4eb;
  font-size: 100%;
  --cream: #f7f4eb;
  --white: #fffdf7;
  --green: #173d30;
  --dark: #122b22;
  --muted: #56675d;
  --line: #dcded0;
  --gold: #efc576;
  --max: 1200px;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #956017; outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#app { min-height: 100dvh; display: flex; flex-direction: column; background: var(--cream); }
#app.expanded { position: fixed; inset: 0; z-index: 5; overflow: auto; }
#app:fullscreen { width: 100%; height: 100%; overflow: auto; }
header { background: #fbf9f1; border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); flex: 0 0 auto; z-index: 2; }
.topbar { max-width: var(--max); margin: auto; min-height: 72px; padding: 8px max(22px, env(safe-area-inset-right)) 8px max(22px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 24px; }
.brand, .lang, .top-catalog, .shop, .button, .back-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; min-width: 44px;
  text-align: center; text-decoration: none; font-weight: 650; line-height: 1.2;
}
.brand { color: var(--dark); font-weight: 820; font-size: .92rem; letter-spacing: .115em; text-align: left; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--green); color: var(--gold); }
.brand-mark svg { width: 19px; height: 19px; }
.brand-dot { color: #a06e30; }
.top-catalog { color: var(--muted); font-size: .9rem; }
.top-catalog svg { display: none; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 13px; margin-left: auto; }
.lang { color: #3b5347; padding: 0 8px; font-size: .83rem; }
.lang svg, .shop svg { width: 17px; height: 17px; flex: 0 0 auto; }
.shop { color: white; background: var(--green); border-radius: 8px; padding: 0 14px; font-size: .86rem; }
.shop:hover, .primary:hover { background: #245745; }
.shop-narrow { display: none; }
.container { width: min(var(--max), 100%); margin-inline: auto; padding-inline: max(22px, env(safe-area-inset-left), env(safe-area-inset-right)); }
.catalog-page { padding-top: 34px; }
.hero { display: grid; grid-template-columns: minmax(0, 0.87fr) minmax(0, 1.13fr); border-radius: 20px; background: #183e31; color: #fff7e7; min-height: 390px; }
.hero-empty { grid-template-columns: 1fr; min-height: 300px; }
.hero-text { display: flex; flex-direction: column; align-items: start; justify-content: center; padding: clamp(24px, 5vw, 67px); }
h1, h2, h3, p { margin: 0; }
.hero h1, .gallery h2, .detail-copy h1, .state-page h1 { font-family: Georgia, "Palatino Linotype", serif; font-weight: 500; letter-spacing: -.055em; text-wrap: balance; }
.hero h1 { font-size: clamp(2.65rem, 5.4vw, 5.6rem); max-width: 8.8ch; line-height: .98; }
.hero-empty h1 { max-width: 100%; }
.hero p { margin: 20px 0 24px; max-width: 36ch; color: #e5ecdc; line-height: 1.58; }
.hero-art { display: grid; place-items: center; padding: 15px; border-radius: 0 20px 20px 0; background: #102b23; }
.hero-art img { width: 100%; max-height: 490px; height: auto; object-fit: contain; border-radius: 10px; }
.button { border: 1px solid transparent; color: var(--green); border-radius: 8px; padding: 9px 15px; cursor: pointer; background: var(--white); }
.button:disabled { cursor: default; opacity: .52; }
.button svg { flex-shrink: 0; width: 19px; height: 19px; }
.hero-button { background: var(--gold); color: #253327; }
.hero-button:hover { background: #ffe0a0; }
.primary { background: var(--green); color: white; }
.secondary { border-color: #bcc9b8; background: transparent; color: var(--green); }
.secondary:not(:disabled):hover { background: #e8efe2; }
.gallery { padding-block: 38px 12px; scroll-margin-top: 12px; }
.gallery h2 { font-size: clamp(2rem, 4vw, 3.55rem); margin-bottom: 18px; color: var(--dark); }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 13px; background: var(--white); }
.card-image { display: grid; place-items: center; aspect-ratio: 4/3; background: #e3e8dc; border-radius: 12px 12px 0 0; }
.card-image img { max-height: 100%; width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.card-info { flex: 1; display: flex; flex-direction: column; gap: 9px; padding: 16px; }
.card-info h3 { font-family: Georgia, serif; font-size: 1.46rem; font-weight: 500; color: var(--dark); }
.card-info p, footer p { line-height: 1.45; color: var(--muted); }
.card-info .button { align-self: start; margin-top: auto; }
.resume { display: flex; justify-content: space-between; align-items: center; gap: 13px; background: #e7eddf; padding: 15px; margin-top: 18px; border-radius: 10px; }
.resume p { margin-top: 5px; color: var(--muted); }
.previous-address { margin-top: .6rem; }
.previous-address a { display: inline-flex; align-items: center; min-height: 44px; text-underline-offset: .18em; }
footer { padding: 24px 0 max(24px, env(safe-area-inset-bottom)); margin-top: 24px; border-top: 1px solid var(--line); display: flex; gap: 15px; justify-content: space-between; flex-wrap: wrap; color: var(--muted); font-size: .87rem; }
footer span { font-weight: 750; letter-spacing: .11em; }
.detail-page, .state-page { padding-top: clamp(16px, 3vw, 38px); }
.back-link { color: var(--muted); padding-inline: 5px; }
.back-link:hover, .top-catalog:hover, .lang:hover { color: var(--green); text-decoration: underline; }
.detail-layout { display: grid; align-items: center; grid-template-columns: minmax(0, 1.36fr) minmax(0, 1fr); gap: clamp(18px, 4vw, 53px); margin-block: 15px 28px; }
.detail-art { display: grid; place-items: center; padding: 12px; border-radius: 16px; background: #e3e8dc; }
.detail-art img { border-radius: 7px; width: auto; height: auto; max-height: min(64dvh, 620px); object-fit: contain; }
.detail-copy h1, .state-page h1 { font-size: clamp(2.5rem, 5vw, 5.2rem); line-height: 1; color: var(--dark); }
.detail-copy p, .state-page p { line-height: 1.55; color: var(--muted); margin-block: 14px; }
.detail-copy h2 { margin: 28px 0 10px; font-size: 1.2rem; }
.levels { display: grid; gap: 8px; }
.level { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px; border: 1px solid #bcc9b8; border-radius: 8px; padding: 7px 14px; text-decoration: none; background: var(--white); }
.level strong { font-size: 1.3rem; }
.level:hover { background: #e7efde; }
.level-action { font-size: .9rem; font-weight: 720; color: var(--green); }
.detail-copy .detail-note { font-size: .87rem; margin-block-end: 0; }
.state-page .back-link { margin-top: 12px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.completion-mark { width: 48px; height: 48px; border-radius: 50%; background: #e5eddb; display: grid; place-items: center; margin-bottom: 14px; }
.game-page { min-height: 0; display: flex; flex-direction: column; flex: 1; width: min(1600px, 100%); margin-inline: auto; padding: 0 max(18px, env(safe-area-inset-left), env(safe-area-inset-right)) max(13px, env(safe-area-inset-bottom)); }
.game-info { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 71px; padding: 8px 1px; }
.game-meta { display: flex; align-items: center; gap: 8px; min-width: 0; }
.game-meta h1 { font-family: Georgia, serif; line-height: 1.17; color: var(--dark); font-size: clamp(1.2rem, 3vw, 2rem); font-weight: 500; }
.game-meta span, #save-status { font-size: .83rem; color: var(--muted); }
#save-status[data-state="saveError"], #save-status[data-state="conflict"] { color: #8d3422; font-weight: 650; }
.game-progress { flex: 0 1 330px; min-width: 117px; text-align: right; }
.game-progress > div { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.game-progress strong { min-width: 3.3ch; font-variant-numeric: tabular-nums; }
progress { flex: 0 1 200px; min-width: 55px; height: 8px; border: 0; border-radius: 8px; appearance: none; accent-color: var(--green); background: #dce5d7; }
progress::-webkit-progress-bar { background: #dce5d7; border-radius: 10px; }
progress::-webkit-progress-value { background: #336b53; border-radius: 10px; }
progress::-moz-progress-bar { background: #336b53; border-radius: 10px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 5px; padding: 5px; background: #e8ebdf; border: 1px solid #d7dece; border-radius: 10px 10px 0 0; }
.toolbar-set { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.icon-button { padding: 0; }
.tool { font-size: .88rem; padding: 7px 11px; }
.toolbar .button { background: transparent; }
.toolbar .button:hover, .toolbar button[aria-pressed="true"], .toolbar button[aria-expanded="true"] { background: #cbdcca; border-color: #a8bda7; }
.play-area { position: relative; display: grid; flex: 1 0 min(70dvh, 540px); min-height: 250px; overflow: hidden; background: #a5b4a5; border: 1px solid #91a493; border-top: 0; border-radius: 0 0 10px 10px; }
.play-area[data-surface="linen"] { background: #e4d6bc; border-color: #c8b898; }
.play-area[data-surface="slate"] { background: #4d5d62; border-color: #526378; }
#board { position: absolute; width: 100%; height: 100%; inset: 0; display: block; touch-action: none; cursor: grab; }
#board.panning, #board:active { cursor: grabbing; }
#board:focus-visible { outline: 3px solid #704204; outline-offset: -4px; }
#timer-display, #hidden-count, #tray-target { position: absolute; color: var(--dark); font-size: .85rem; font-weight: 700; border-radius: 7px; padding: 6px 9px; background: #fffdf0; box-shadow: 0 1px 5px #2336; pointer-events: none; }
#timer-display { top: 8px; left: 8px; font-variant-numeric: tabular-nums; }
#hidden-count { top: 8px; right: 8px; }
#tray-target { display: flex; align-items: center; gap: 7px; left: 8px; bottom: 8px; min-height: 44px; pointer-events: auto; }
.tray-dock { margin-top: 7px; padding: 8px; background: #e8ebdf; border-radius: 8px; border: 1px solid #d2d9ca; }
.tray-head { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.tray-pieces { display: flex; gap: 6px; padding: 4px; overflow-x: auto; }
.tray-piece { flex: 0 0 auto; cursor: grab; touch-action: none; border: 1px solid #c4d2c3; border-radius: 6px; background: #f6f7ec; padding: 0; }
.tray-piece canvas { width: 68px; height: 52px; display: block; }
#tray-empty { color: var(--muted); font-size: .9rem; }
dialog { max-width: min(92vw, 460px); max-height: 90dvh; min-width: min(300px, 92vw); padding: 15px; border: 1px solid #d5dfd0; border-radius: 14px; background: var(--white); color: var(--dark); box-shadow: 0 18px 65px #152b2350; }
dialog::backdrop { background: #102b23a8; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.dialog-head h2 { font-family: Georgia, serif; font-weight: 500; font-size: 1.6rem; }
.dialog-actions { display: flex; gap: 7px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
#reference-dialog { max-width: min(90vw, 900px); }
.reference-art img { width: auto; height: auto; max-width: min(80vw, 850px); max-height: 72dvh; border-radius: 6px; }
.settings-list { display: grid; gap: 10px; }
.settings-list label { min-height: 44px; display: flex; align-items: center; gap: 7px; }
.settings-list input { width: 21px; height: 21px; accent-color: var(--green); }
.settings-list select { min-height: 44px; padding: 5px 9px; background: #edf2e9; border: 1px solid #bac8b6; border-radius: 7px; }
.settings-list p { line-height: 1.45; }
@media (max-width: 790px) {
  .hero { min-height: 315px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { min-height: 61px; gap: 8px; }
  .game-page { padding-inline: max(9px, env(safe-area-inset-left), env(safe-area-inset-right)); }
  .game-info { min-height: 59px; }
}
@media (max-width: 590px) {
  .container { padding-inline: max(13px, env(safe-area-inset-left), env(safe-area-inset-right)); }
  .topbar { padding-inline: max(9px, env(safe-area-inset-left), env(safe-area-inset-right)); gap: 4px; }
  .brand { font-size: .71rem; letter-spacing: .065em; gap: 5px; min-width: 0; }
  .brand-mark { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 7px; }
  .brand-mark svg { width: 16px; height: 16px; }
  .top-catalog svg { display: block; }
  .top-catalog span, .shop-wide, .lang svg { display: none; }
  .shop-narrow { display: inline; }
  .top-actions { gap: 2px; }
  .shop { padding: 6px 8px; gap: 5px; }
  .shop svg:first-child { display: none; }
  .shop svg:last-child { width: 13px; }
  .catalog-page { padding-top: 14px; }
  .hero { grid-template-columns: 1fr; border-radius: 13px; }
  .hero-text { padding: 25px 21px; }
  .hero h1 { max-width: none; }
  .hero p { margin: 12px 0 14px; }
  .hero-art { border-radius: 0 0 13px 13px; padding: 9px; }
  .gallery { padding-top: 24px; }
  .cards, .detail-layout { grid-template-columns: 1fr; }
  .detail-layout { gap: 19px; }
  .detail-art img { max-height: 45dvh; }
  .detail-copy h2 { margin-top: 18px; }
  .game-meta { gap: 2px; }
  .game-progress { flex: 0 1 138px; }
  .toolbar { padding: 3px; }
  .toolbar-set { gap: 1px; }
  .tool { padding-inline: 6px; }
  .tool svg { width: 16px; height: 16px; }
  .play-area { flex: 1 0 min(55dvh, 480px); min-height: 195px; }
}
@media (max-width: 350px) {
  .tool { font-size: .78rem; gap: 4px; }
  .game-meta .back-link { display: none; }
}
@media (orientation: landscape) and (max-height: 530px) {
  .topbar { min-height: 50px; padding-block: 3px; }
  .game-info { min-height: 47px; }
  .game-meta h1 { font-size: 1.25rem; }
  .play-area { min-height: 135px; flex-basis: 40dvh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
.brand-logo { display: block; width: 152px; height: auto; }
@media (max-width: 590px) { .brand-logo { width: min(116px, 30vw); } }
.detail-copy .credit { font-size: .86rem; }
header { position: sticky; top: 0; }
.game-meta > div, .game-progress { min-width: 0; }
.game-meta h1, .game-progress #save-status { overflow-wrap: anywhere; }
@media (max-width: 350px) {
  .game-info { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .game-progress { display: grid; grid-template-columns: minmax(83px, .6fr) minmax(0, 1fr); align-items: center; gap: 8px; }
  .game-progress > div { justify-content: flex-start; }
}
.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  color: var(--green);
}
.language-switch svg { width: 17px; height: 17px; flex: 0 0 auto; }
.language-switch select {
  min-height: 44px;
  color: var(--green);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px 7px;
  font-size: .88rem;
  font-weight: 650;
  min-width: 44px;
}
.language-switch select:hover { border-color: #a8bda7; }
.piece-count { font-weight: 690; color: #345b48; }
.legacy-games { margin: 22px 0; }
.legacy-games h2 { font-family: Georgia, serif; font-weight: 500; }
.legacy-games ul { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 7px; }
@media (max-width: 590px) {
  .language-switch svg { display: none; }
  .language-switch select { max-width: min(31vw, 103px); padding-inline: 2px; }
  .topbar .brand-logo { width: min(109px, 28vw); }
  .topbar .shop { font-size: min(.86rem, 5.3vw); }
  .topbar .shop svg:last-child { flex: 0 0 12px; }
  .level { overflow-wrap: anywhere; }
}
.quick-help {
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: space-between;
  padding: 3px 8px 3px 13px;
  border-inline: 1px solid #d6decc;
  background: #f4f3e7;
}
.quick-help p { font-size: .89rem; line-height: 1.38; }
.quick-help .button { flex: 0 0 auto; background: transparent; }
.reference-pin {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: clamp(182px, 23%, 278px);
  padding: 3px;
  border: 1px solid #617966;
  border-radius: 8px;
  color: var(--green);
  background: #f7f6ec;
  box-shadow: 0 4px 12px #14241934;
}
.reference-pin > div { display: flex; justify-content: space-between; }
.reference-pin img { display: block; width: 100%; height: auto; max-height: 26vh; object-fit: contain; border-radius: 4px; }
.reference-pin .button { background: transparent; }
.reference-pin .button:hover { background: #dce7d8; }
.pin-grip { cursor: move; touch-action: none; }
.pin-action { margin-top: 6px; }
#tray-selected:empty { display: none; }
#tray-selected { font-size: .85rem; }
.tray-piece[aria-pressed="true"] { outline: 3px solid #785019; outline-offset: -3px; }
.pagination { display: flex; align-items: center; gap: 8px; }
@media (max-height: 520px) {
  .quick-help { padding-block: 0; }
  .reference-pin img { max-height: 31vh; }
}
.catalog-filters {
  display: grid;
  align-items: end;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 10px;
}
.catalog-filters label { min-width: 0; display: grid; gap: 4px; color: #304939; font-size: .86rem; font-weight: 650; }
.catalog-filters input, .catalog-filters select {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: 6px 8px;
  color: var(--green);
  background: var(--white);
  border: 1px solid #a7baa6;
  border-radius: 7px;
}
.catalog-filters button { min-height: 44px; }
#catalog-count { color: #48624f; font-size: .9rem; margin: 0 0 14px; }
#catalog-pagination { justify-content: center; margin-top: 18px; }
.started-games > summary { min-height: 44px; cursor: pointer; padding-block: 12px; font-weight: 660; }
@media (max-width: 680px) {
  .catalog-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .catalog-filters label:first-child { grid-column: 1 / -1; }
}
