:root {
  color-scheme: light;
  --ink: #233d38;
  --muted: #73817c;
  --green: #16745b;
  --green-dark: #105b47;
  --mint: #e9f5ee;
  --line: #e3e9e3;
  --paper: #ffffff;
  --orange: #d17a44;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #f7f8f2; }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse at 90% 10%, #e6f0df99, transparent 45%),
              radial-gradient(ellipse at 5% 70%, #f5eadb80, transparent 35%);
  pointer-events: none;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
button, input, textarea, label { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid #e3ab6a;
  outline-offset: 3px;
}
svg.icon { width: 19px; height: 19px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.svg-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
.shell { width: min(1240px, calc(100% - 80px)); margin-inline: auto; }
.has-game-menu { padding-left: 200px; }
.game-menu { position: fixed; inset: 0 auto 0 0; z-index: 10; width: 200px; padding: 28px 16px; overflow-y: auto; border-right: 1px solid var(--line); background: var(--paper); }
.game-menu-title { margin: 0 0 20px; padding: 8px 12px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
.game-menu-link { display: flex; align-items: center; gap: 10px; min-height: 46px; margin-bottom: 6px; padding: 8px 10px; border-left: 3px solid transparent; border-radius: 6px; color: var(--muted); font-size: 13px; font-weight: 650; line-height: 1.4; letter-spacing: 0; text-decoration: none; }
.game-menu-link:hover { color: var(--ink); background: #f3f7f1; }
.game-menu-link[aria-current="page"] { border-left-color: var(--green); color: var(--green-dark); background: var(--mint); }
.game-menu-link:focus-visible { outline: 3px solid #e3ab6a; outline-offset: 2px; }
.game-menu-mark { display: grid; place-items: center; width: 26px; height: 26px; flex-shrink: 0; color: var(--green); font: 700 16px Consolas, monospace; }
.game-menu-link > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.site-header { min-height: 93px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 12px); gap: 3px; padding: 10px; border-radius: 12px; background: var(--green); transform: rotate(-5deg); }
.brand-mark span { width: 12px; height: 12px; border: 1.4px solid #ffffff95; border-radius: 3px; }
.brand-mark span:last-child { background: #eaca8f; border-color: #eaca8f; }
.brand-name { font-size: 20px; font-weight: 750; letter-spacing: -.7px; }
.brand-tagline { display: block; margin-top: 3px; font-size: 10px; letter-spacing: 1.9px; color: var(--muted); font-weight: 600; }
.offline { display: flex; align-items: center; gap: 7px; color: #687b70; font-size: 12px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 16px; }
.language-picker { position: relative; font-size: 12px; }
.language-picker summary { display: flex; align-items: center; gap: 8px; width: 132px; min-height: 36px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); cursor: pointer; list-style: none; }
.language-picker summary::-webkit-details-marker { display: none; }
.language-flag { display: block; width: 24px; height: 16px; flex-shrink: 0; object-fit: contain; }
.language-options { position: absolute; z-index: 5; top: calc(100% + 6px); right: 0; width: 180px; max-width: calc(100vw - 32px); padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: 0 6px 18px #233d3814; }
.language-option { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px; border-radius: 4px; cursor: pointer; }
.language-option:hover { background: #f3f7f1; }
.language-option:has(input:checked) { color: var(--green-dark); background: var(--mint); }
.language-option input { width: 14px; height: 14px; margin: 0 0 0 auto; accent-color: var(--green); cursor: pointer; }
.offline::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #75a182; }
.intro { display: flex; justify-content: space-between; align-items: center; padding: 40px 0 32px; gap: 28px; }
.eyebrow { margin: 0 0 12px; color: var(--green); font-size: 10px; font-weight: 750; letter-spacing: 2px; }
h1 { margin: 0; font-size: clamp(29px, 3.2vw, 42px); line-height: 1.25; font-weight: 720; letter-spacing: -1.5px; }
h1 span { color: var(--green); }
h1 .headline-first { color: inherit; }
.intro p.description { max-width: 370px; font-size: 14px; line-height: 1.8; color: var(--muted); margin: 0; }
.workspace { display: grid; grid-template-columns: 326px minmax(0, 1fr); gap: 24px; align-items: start; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 5px 22px #233d3804; }
.settings { padding: 25px; }
.section-heading { display: flex; gap: 10px; align-items: center; margin-bottom: 25px; }
.section-heading .icon { color: var(--green); }
h2 { margin: 0; font-size: 17px; letter-spacing: -.35px; font-weight: 700; }
.field-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; margin-bottom: 12px; }
.step { font-size: 10px; color: #81948a; letter-spacing: .5px; }
.dimension-fields { display: grid; grid-template-columns: 1fr 18px 1fr; gap: 9px; align-items: end; }
.dimension-fields label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 7px; }
.multiply { color: #99a69f; text-align: center; padding-bottom: 12px; }
input[type="number"] { width: 100%; padding: 11px 12px; font-weight: 650; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; background: #fcfdfb; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.7; margin: 9px 0 0; }
.field-section + .field-section { margin-top: 24px; padding-top: 23px; border-top: 1px solid #edf0eb; }
.word-label { justify-content: space-between; }
.word-label > span { display: flex; gap: 8px; align-items: center; }
.word-count { color: var(--green); background: var(--mint); border-radius: 5px; padding: 3px 6px; font-size: 10px; font-weight: 600; }
textarea { width: 100%; min-height: 134px; resize: vertical; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fcfdfb; color: var(--ink); font-size: 13px; line-height: 1.9; }
textarea::placeholder { color: #9ba59f; }
fieldset { padding: 0; margin: 0; border: 0; min-width: 0; }
legend.field-title { padding: 0; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode { display: flex; align-items: center; gap: 7px; padding: 10px 8px; border: 1px solid var(--line); border-radius: 9px; color: #6c7972; font-size: 12px; cursor: pointer; transition: background .15s, border-color .15s; }
.mode > [data-i18n] { min-width: 0; overflow-wrap: anywhere; }
.mode:has(input:checked) { border-color: #b9d9c7; background: #f0f8f2; color: var(--green-dark); }
.mode input { accent-color: var(--green); margin: 0; width: 14px; height: 14px; flex-shrink: 0; cursor: pointer; }
.mode .direction { font-size: 17px; line-height: 1; margin-left: auto; color: #92a89a; }
.button { border: 0; border-radius: 10px; display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 42px; padding: 10px 15px; font-size: 12px; font-weight: 650; transition: background .15s, transform .15s; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { background: var(--green); color: white; }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.generate { width: 100%; margin-top: 24px; min-height: 47px; font-size: 13px; box-shadow: 0 4px 8px #16745b14; }
.button-secondary { background: white; border: 1px solid var(--line); color: var(--ink); }
.button-secondary:hover:not(:disabled) { background: #f3f7f1; border-color: #b9cdbf; }
.privacy-note { margin: 12px 0 0; text-align: center; font-size: 10px; color: #8a978f; }
.form-error { margin: 14px 0 0; border: 1px solid #f0d0bf; padding: 10px 12px; border-radius: 9px; background: #fff6ef; color: #a04e2c; font-size: 12px; line-height: 1.65; overflow-wrap: anywhere; }
.tip { display: flex; align-items: flex-start; gap: 10px; padding: 17px 19px; margin-top: 14px; color: #78836e; font-size: 11px; line-height: 1.8; }
.tip .icon { width: 17px; color: #a29968; margin-top: 2px; }
.tip p { margin: 0; }
.puzzle-panel { min-width: 0; overflow: hidden; }
.panel-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 21px 25px; border-bottom: 1px solid var(--line); }
.panel-heading { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.state-badge { font-size: 8px; font-weight: 700; letter-spacing: .7px; color: #8e998f; background: #f2f4ef; padding: 5px 7px; border-radius: 5px; }
.state-badge.active { background: var(--mint); color: var(--green); }
.print-button { min-height: 36px; padding: 8px 12px; white-space: nowrap; }
.print-button .icon { width: 16px; height: 16px; }
.empty-state { min-height: 610px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 35px; background: radial-gradient(ellipse at center, #f6f9f180, transparent 70%); }
.sample-wrap { position: relative; margin-bottom: 30px; }
.sample-grid { width: 235px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; transform: rotate(-7deg); padding: 18px; background: white; border: 1px solid var(--line); border-radius: 19px; box-shadow: 0 12px 35px #3155370b; }
.sample-grid span { display: grid; place-items: center; aspect-ratio: 1; border-radius: 6px; background: #f3f6f0; color: #acb8aa; font: 600 17px Consolas, monospace; }
.sample-grid .sample-found { color: var(--green); background: #daeddb; }
.sample-spark { position: absolute; right: -22px; top: -16px; color: #dba56a; font-size: 40px; }
.empty-state h3 { font-size: 22px; letter-spacing: -.6px; margin: 0 0 10px; font-weight: 650; }
.empty-state p { color: var(--muted); font-size: 13px; line-height: 1.8; max-width: 310px; margin: 0 0 24px; }
.empty-state .button { background: var(--mint); color: var(--green); }
.empty-state .button:hover { background: #dbeee0; }
.puzzle-content { padding: 23px 25px 24px; }
.paper-title { display: none; }
.puzzle-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; color: var(--muted); font-size: 11px; }
.meta-tag { color: #517360; font-size: 10px; background: #f2f6ef; padding: 4px 8px; border-radius: 5px; }
.board-frame { background: #f7f9f3; border: 1px solid #e5ebdf; padding: 17px; border-radius: 13px; }
.board-scroll { max-width: 100%; overflow: auto; padding: 3px; overscroll-behavior: contain; }
.letter-grid { display: grid; grid-template-columns: repeat(var(--cols), var(--cell-size)); width: max-content; gap: var(--grid-gap); margin-inline: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.grid-row { display: contents; }
.cell { display: grid; place-items: center; width: var(--cell-size); height: var(--cell-size); min-width: 0; padding: 0; border: 1px solid #e7ece1; border-radius: 6px; background: white; color: #3c5144; font-family: "Cascadia Code", Consolas, monospace; font-size: calc(var(--cell-size) * .45); line-height: 1; font-weight: 600; transition: background .1s; cursor: crosshair; }
.cell:hover { background: #eff4e9; }
.cell.is-found { background: #dbeee0; border-color: #c3dec9; color: #246b4b; }
.cell.is-selected { background: #f7dfb9; border-color: #e5bf85; color: #81501e; }
.cell.selection-start { box-shadow: inset 0 0 0 1px #bd8f46; }
.cell:focus-visible { position: relative; outline: 2px solid var(--green); outline-offset: 1px; z-index: 1; }
.selection-preview { display: flex; gap: 8px; align-items: center; justify-content: center; min-height: 36px; margin-top: 9px; color: #7e8d77; font-size: 11px; }
.selection-preview .icon { width: 15px; height: 15px; }
#selection-text { overflow-wrap: anywhere; text-align: center; }
.word-bank { margin-top: 23px; }
.word-bank-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 13px; }
.word-bank h3 { font-size: 11px; font-weight: 700; letter-spacing: 1px; margin: 0; }
#found-count { font-size: 11px; color: var(--muted); white-space: nowrap; }
#found-count strong { color: var(--green); }
.word-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.word-chip { display: flex; align-items: center; gap: 7px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; color: #677467; font-size: 11px; font-weight: 650; letter-spacing: .7px; transition: background .2s; }
.word-chip .word-text { overflow-wrap: anywhere; min-width: 0; }
.word-chip .word-check { width: 12px; height: 12px; border: 1px solid #d5dfd0; border-radius: 50%; flex-shrink: 0; }
.word-chip.found { color: var(--green); background: #edf7ef; border-color: #d1e7d6; }
.word-chip.found .word-text { text-decoration: line-through; text-decoration-color: #73a58b; }
.word-chip.found .word-check { background: var(--green); border-color: var(--green); position: relative; }
.word-chip.found .word-check::after { content: ""; position: absolute; left: 3px; top: 1px; width: 3px; height: 6px; border: solid white; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.game-footer { margin-top: 23px; padding-top: 17px; border-top: 1px solid var(--line); }
.progress-row { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 9px; }
#game-status { margin: 0; font-size: 11px; color: var(--muted); line-height: 1.6; overflow-wrap: anywhere; }
#game-status.success { color: var(--green); }
#game-status.warning { color: #a36b31; }
#progress-percent { font-size: 10px; font-weight: 700; color: var(--green); }
progress { display: block; appearance: none; -webkit-appearance: none; width: 100%; height: 5px; border: 0; border-radius: 4px; overflow: hidden; background: #edf2e9; color: var(--green); }
progress::-webkit-progress-bar { background: #edf2e9; border-radius: 4px; }
progress::-webkit-progress-value { background: #73a584; border-radius: 4px; transition: width .3s; }
progress::-moz-progress-bar { background: #73a584; border-radius: 4px; }
.keyboard-help { margin-top: 14px; color: #8a9685; font-size: 10px; line-height: 1.7; }
.keyboard-help summary { cursor: pointer; width: fit-content; }
.keyboard-help p { margin: 7px 0 0; }
.print-footer { display: none; }
.site-footer { display: flex; justify-content: space-between; gap: 16px; padding: 26px 0; color: #929d8c; font-size: 10px; letter-spacing: .15px; }
.site-footer span:last-child { color: #8b9a7c; }
noscript p { margin: 20px; padding: 20px; color: #9a3c23; background: #fff1e8; border-radius: 10px; }
@media (min-width: 1000px) { .settings-column { position: sticky; top: 22px; } }
@media (max-width: 1050px) {
  .shell { width: calc(100% - 44px); }
  .workspace { grid-template-columns: 296px minmax(0, 1fr); gap: 18px; }
  .settings { padding: 21px; }
  .panel-toolbar, .puzzle-content { padding: 20px; }
  .intro p.description { max-width: 300px; font-size: 12px; }
  .board-frame { padding: 11px; }
}
@media (max-width: 1000px) {
  .has-game-menu { padding-left: 0; }
  .game-menu { position: static; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .game-menu-title { display: none; }
  .game-menu-link { min-height: 48px; margin: 0; gap: 8px; font-size: 12px; }
  .game-menu-mark { width: 22px; }
}
@media (max-width: 760px) {
  .shell { width: calc(100% - 32px); }
  .site-header { min-height: 78px; }
  .site-header { flex-wrap: wrap; padding-block: 16px; gap: 12px; }
  .header-actions { margin-left: auto; }
  .header-actions .offline { display: none; }
  .brand-name { font-size: 18px; }
  .brand-tagline { font-size: 8px; letter-spacing: 1.4px; }
  .offline { font-size: 10px; }
  .intro { display: block; padding: 29px 0 24px; }
  .intro p.description { max-width: none; margin-top: 13px; font-size: 12px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .settings { padding: 22px; }
  .section-heading { margin-bottom: 20px; }
  .mode-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode .direction { display: none; }
  .mode { justify-content: center; }
  textarea { min-height: 100px; }
  .tip { padding: 10px 7px 0; margin-top: 0; }
  .empty-state { min-height: 430px; padding: 35px 20px; }
  .sample-grid { width: 200px; }
  .panel-toolbar { padding: 16px; }
  .puzzle-content { padding: 17px 13px; }
  .panel-heading { gap: 7px; }
  .panel-heading h2 { font-size: 15px; }
  .board-frame { padding: 7px; }
  .cell { border-radius: 4px; }
  .site-footer { font-size: 9px; flex-direction: column; align-items: center; gap: 6px; }
}
@media (max-width: 390px) {
  .offline { display: none; }
  .mode-grid { grid-template-columns: 1fr 1fr; }
  .mode .direction { display: block; }
  .state-badge { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; } }
@page { size: A4 portrait; margin: 10mm; }
@media print {
  :root { color-scheme: light; }
  html, body { width: auto; margin: 0 !important; padding: 0 !important; background: white !important; color: black; }
  body::before, .game-menu, .site-header, .intro, .settings-column, .site-footer, .panel-toolbar,
  .empty-state, .selection-preview, .game-footer, #found-count, .word-check, noscript { display: none !important; }
  .shell { width: 100%; margin: 0; }
  .workspace { display: block; }
  .puzzle-panel { border: 0; box-shadow: none; border-radius: 0; overflow: visible; }
  .puzzle-content { padding: 1cm; }
  .paper-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 6mm; border-bottom: .4mm solid black; padding-bottom: 3mm; margin-bottom: 3mm; }
  .paper-title h2 { font-size: 19pt; letter-spacing: -.4pt; }
  .paper-title p { margin: 2mm 0 0; font-size: 9pt; }
  .paper-name { font-size: 9pt; white-space: nowrap; padding-bottom: 1mm; }
  .puzzle-meta { font-size: 9pt; margin-bottom: 3mm; gap: 2mm; color: black; }
  .meta-tag { background: none; color: black; font-size: 8pt; padding: 0; }
  .meta-tag::before { content: "· "; }
  .board-frame { background: white; padding: 0; border: 0; border-radius: 0; break-inside: avoid; }
  .board-scroll { overflow: visible; max-width: none; padding: 0; }
  /* Disable native button printing and use explicit, dark, single-width borders. */
  .letter-grid { grid-template-columns: repeat(var(--cols), var(--print-cell)); gap: 0; border-top: .75pt solid #222; border-left: .75pt solid #222; margin: 0 auto; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .cell, .cell.is-found, .cell.is-selected, .cell:hover { appearance: none; -webkit-appearance: none; width: var(--print-cell); height: var(--print-cell); padding: 0; color: black !important; background: white !important; border: 0 !important; border-right: .75pt solid #222 !important; border-bottom: .75pt solid #222 !important; border-radius: 0; box-shadow: none !important; font-size: var(--print-font); font-weight: 600; outline: none !important; }
  .word-bank { margin-top: 4mm; break-inside: avoid; }
  .word-bank-heading { margin-bottom: 2mm; }
  .word-bank h3 { font-size: 9pt; letter-spacing: .5pt; }
  .word-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); column-gap: 2mm; row-gap: 1mm; }
  .word-chip, .word-chip.found { padding: 1mm 0; gap: 1mm; border: 0; border-radius: 0; color: black; background: white; font-family: "Cascadia Code", Consolas, monospace; font-size: var(--print-word-font, 9pt); line-height: 1.1; letter-spacing: 0; white-space: nowrap; }
  .word-chip::before { content: ""; width: 2mm; height: 2mm; border: .2mm solid #777; flex-shrink: 0; }
  .word-chip.found .word-text { text-decoration: none; }
  .word-chip .word-text { overflow-wrap: normal; }
  .print-footer { display: block; margin-top: 4mm; padding-top: 2mm; border-top: .2mm solid #aaa; font-size: 8pt; text-align: center; color: #444; }
}
