:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #202124;
  --muted: #77736b;
  --line: #d9d3c8;
  --accent: #2f5d50;
  --accent-dark: #23483e;
  --bad: #b54b45;
  --shadow: 0 14px 40px rgba(50,45,35,.10);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; cursor: pointer; }
.app { width: min(920px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 48px; }
.topbar { display:flex; align-items:center; justify-content:space-between; gap:20px; margin-bottom:28px; }
.eyebrow { color:var(--accent); font-size:12px; font-weight:800; letter-spacing:.18em; }
h1 { margin:6px 0 0; font-family: Georgia, serif; font-size:clamp(30px,5vw,46px); line-height:1.05; }
.status { display:flex; justify-content:space-between; color:var(--muted); margin-bottom:14px; font-size:15px; }
.status strong { color:var(--ink); }
.card { background:var(--panel); border:1px solid var(--line); border-radius:22px; box-shadow:var(--shadow); }
.cipher { padding:34px 24px 24px; display:flex; flex-wrap:wrap; justify-content:center; gap:10px 8px; min-height:155px; align-items:center; }
.word { display:flex; gap:5px; margin:5px 8px; }
.cell { width:42px; height:58px; border-bottom:3px solid #aaa49a; display:flex; flex-direction:column; justify-content:flex-end; align-items:center; padding-bottom:5px; user-select:none; }
.cell .num { font-size:13px; color:#888277; line-height:1; }
.cell .letter { height:30px; font-family:Georgia,serif; font-size:26px; font-weight:700; line-height:30px; text-transform:uppercase; }
.cell.selected { border-color:var(--accent); background:#eef3f0; border-radius:8px 8px 0 0; }
.cell.solved { border-color:var(--accent); }
.space { width:10px; }
.message { min-height:27px; text-align:center; padding:0 20px 24px; color:var(--muted); font-size:15px; }
.controls { display:flex; justify-content:center; gap:10px; flex-wrap:wrap; margin:18px 0; }
.primary-btn,.secondary-btn,.ghost-btn {
  border-radius:12px; padding:11px 17px; border:1px solid var(--line); transition:.15s ease;
}
.primary-btn { background:var(--accent); color:white; border-color:var(--accent); }
.primary-btn:hover { background:var(--accent-dark); }
.secondary-btn,.ghost-btn { background:var(--panel); color:var(--ink); }
.secondary-btn:hover,.ghost-btn:hover { border-color:#aaa196; transform:translateY(-1px); }
.keyboard { display:grid; grid-template-columns:repeat(9,1fr); gap:7px; }
.key { min-height:48px; border:1px solid var(--line); background:var(--panel); border-radius:10px; font-weight:700; color:var(--ink); }
.key:hover:not(:disabled) { border-color:var(--accent); background:#eef3f0; }
.key:disabled { opacity:.38; cursor:default; }
.key.used { opacity:.42; }
.key.wrong { border-color:var(--bad); color:var(--bad); }
.hidden { display:none !important; }
.result { text-align:center; padding:55px 25px; }
.result-icon { width:64px; height:64px; margin:0 auto 20px; border-radius:50%; background:#e5eee9; color:var(--accent); display:grid; place-items:center; font-size:34px; font-weight:700; }
.result h2 { font-family:Georgia,serif; font-size:34px; margin:0 0 10px; }
.result p { color:var(--muted); margin:0 auto 25px; max-width:520px; line-height:1.6; }
dialog { width:min(620px,calc(100% - 28px)); border:1px solid var(--line); border-radius:20px; padding:0; background:var(--panel); color:var(--ink); box-shadow:0 25px 80px rgba(0,0,0,.25); }
dialog::backdrop { background:rgba(25,24,21,.5); }
.dialog-head { display:flex; justify-content:space-between; align-items:center; padding:20px 24px; border-bottom:1px solid var(--line); }
.dialog-head h2 { margin:0; font-family:Georgia,serif; }
.close-btn { border:0; background:transparent; font-size:30px; color:var(--muted); line-height:1; }
.rules { padding:20px 25px 26px; line-height:1.65; }
.rules li { margin:9px 0; }
.rules-example { padding:14px 16px; background:#f1eee7; border-radius:12px; }
@media (max-width:620px) {
  .app { width:min(100% - 20px, 920px); padding-top:18px; }
  .topbar { margin-bottom:20px; }
  .cipher { padding:22px 8px 15px; gap:6px 2px; }
  .word { margin:3px 4px; gap:3px; }
  .cell { width:31px; height:50px; }
  .cell .num { font-size:11px; }
  .cell .letter { font-size:22px; height:26px; line-height:26px; }
  .keyboard { grid-template-columns:repeat(6,1fr); }
  .key { min-height:44px; }
}

.info-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #7c2f34;
  background: #fffdf8;
  color: #7c2f34;
  font-family: Georgia, serif;
  font-size: 25px;
  font-weight: 700;
  line-height: 38px;
}
.info-btn:hover {
  background: #7c2f34;
  color: white;
}
#rulesDialog {
  width: min(500px, calc(100% - 28px));
  border: 0;
  border-radius: 0;
  padding: 0;
  background: #fbf7f0;
  color: #665b54;
  box-shadow: 0 20px 70px rgba(0,0,0,.25);
}
#rulesDialog::backdrop {
  background: rgba(40,30,25,.42);
}
#rulesDialog .rules {
  position: relative;
  padding: 22px 34px 28px 34px;
}
#rulesDialog h2 {
  margin: 0 0 20px;
  text-align: center;
  color: #7c2f34;
  font-family: Georgia, serif;
  font-size: 35px;
  line-height: 1.1;
}
#rulesDialog ul {
  margin: 0;
  padding-left: 26px;
}
#rulesDialog li {
  margin: 0 0 12px;
  padding-left: 2px;
  font-size: 17px;
  line-height: 1.45;
}
#rulesDialog li::marker {
  font-size: 18px;
}
#rulesDialog strong {
  color: #4f4742;
}
#rulesDialog .close-btn {
  position: absolute;
  top: 9px;
  right: 13px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #7c2f34;
  font-size: 28px;
}
@media (max-width:620px) {
  #rulesDialog .rules { padding: 24px 22px 25px; }
  #rulesDialog h2 { font-size: 30px; }
  #rulesDialog li { font-size: 16px; }
}

/* Mobile-first layout */
body { overflow-x:hidden; -webkit-tap-highlight-color:transparent; }
.app { width:min(100%,560px); padding:14px 12px 24px; }
.topbar { margin-bottom:14px; }
.topbar h1 { font-size:28px; }
.eyebrow { font-size:10px; }
.status { margin-bottom:9px; font-size:13px; }
.card { border-radius:16px; box-shadow:0 7px 22px rgba(50,45,35,.08); }
.cipher { min-height:145px; padding:20px 7px 15px; gap:5px 1px; }
.word { margin:3px; gap:2px; }
.cell { width:30px; height:48px; border-bottom-width:2px; }
.cell .num { font-size:10px; }
.cell .letter { font-size:21px; height:25px; line-height:25px; }
.message { min-height:24px; padding:0 10px 17px; font-size:13px; }
.controls { justify-content:flex-end; margin:10px 0; }
.hint-btn {
  min-width:48px; height:42px; padding:0 14px;
  border:1px solid var(--line); border-radius:12px;
  background:var(--panel); color:var(--accent);
  font-size:18px; font-weight:800;
}
.keyboard { grid-template-columns:repeat(7,1fr); gap:5px; }
.key { min-height:43px; border-radius:9px; font-size:15px; }
@media (min-width:561px) {
  .app { width:min(920px,calc(100% - 32px)); padding:28px 0 48px; }
  .topbar h1 { font-size:clamp(30px,5vw,46px); }
  .keyboard { grid-template-columns:repeat(9,1fr); gap:7px; }
  .key { min-height:48px; }
  .controls { justify-content:flex-end; }
}
@media (max-width:360px) {
  .app { padding-left:8px; padding-right:8px; }
  .topbar h1 { font-size:25px; }
  .cell { width:27px; }
  .keyboard { gap:4px; }
  .key { min-height:41px; font-size:14px; }
}

/* Reference-style mobile game UI */
:root {
  --game-bg: #f4ecdf;
  --burgundy: #7b2e35;
  --muted-brown: #b8a89b;
  --key-bg: #d7cbbc;
}
html, body { min-height:100%; }
body {
  background: var(--game-bg);
  color: var(--burgundy);
  font-family: Arial, Helvetica, sans-serif;
}
.app {
  width:100%;
  max-width:none;
  min-height:100vh;
  padding:0;
}
.game-header {
  position:relative;
  height:100px;
  background:#fffaf4;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 28px;
  border-bottom:6px solid #f0e7da;
}
.game-header::after {
  content:"";
  position:absolute;
  left:0; right:0; bottom:-7px;
  height:7px;
  background:repeating-linear-gradient(135deg,#f4ecdf 0 7px,#fffaf4 7px 14px);
  pointer-events:none;
}
.header-icon {
  border:0;
  background:transparent;
  color:var(--burgundy);
  padding:0;
  cursor:pointer;
}
.home-icon {
  font-size:37px;
  width:44px;
  line-height:1;
  transform:translateY(-2px);
}
.errors-block {
  position:absolute;
  left:50%;
  top:20px;
  transform:translateX(-50%);
  text-align:center;
}
.errors-title {
  color:#b8aaa0;
  font-size:25px;
  font-weight:600;
  line-height:1;
  margin-bottom:9px;
}
.error-dots { display:flex; gap:11px; justify-content:center; }
.error-dot {
  width:18px; height:18px;
  border:2px solid #c8b9ad;
  border-radius:50%;
  background:transparent;
}
.error-dot.filled {
  background:var(--burgundy);
  border-color:var(--burgundy);
}
.header-actions {
  display:flex;
  align-items:center;
  gap:23px;
}
.info-icon {
  width:31px; height:31px;
  border:3px solid var(--burgundy);
  border-radius:50%;
  font:700 22px/26px Georgia,serif;
}
.levels-icon {
  font-size:34px;
  line-height:1;
}
.level-caption {
  position:absolute;
  top:104px;
  left:50%;
  transform:translateX(-50%);
  z-index:2;
  color:#ad9e92;
  font-size:14px;
  font-weight:700;
  display:none;
}
#gameScreen {
  min-height:calc(100vh - 100px);
  position:relative;
  display:flex;
  flex-direction:column;
}
#gameScreen > .level-caption { display:block; }
#gameScreen .card {
  margin:0;
  border:0;
  border-radius:0;
  box-shadow:none;
  background:transparent;
  flex:1;
  display:flex;
  flex-direction:column;
  justify-content:center;
  min-height:calc(100vh - 300px);
}
#cipher {
  min-height:0;
  padding:0 12px;
}
.word { margin:3px 5px; }
.cell {
  width:35px;
  height:72px;
  border:0;
  border-bottom:4px solid #b8a89b;
  border-radius:0;
  background:transparent;
  color:var(--burgundy);
  padding-bottom:4px;
}
.cell.selected {
  background:#48c91b;
  border:0;
  border-radius:10px;
  color:white;
}
.cell .num {
  color:#ae9c8f;
  font-size:14px;
  order:2;
  margin-top:5px;
}
.cell .letter {
  color:var(--burgundy);
  font-family:Arial,Helvetica,sans-serif;
  font-size:31px;
  font-weight:700;
  height:34px;
  line-height:34px;
  order:1;
}
.cell.selected .num,
.cell.selected .letter { color:white; }
/* Одинаковые уже открытые буквы: последняя открытая — основная,
   остальные такие же — немного приглушены. */
.cell.same-letter-main .letter { opacity:1; }
.cell.same-letter-dim .letter { opacity:.48; }
.message {
  display:none;
}
.controls {
  position:absolute;
  right:19px;
  bottom:218px;
  z-index:10;
  margin:0;
}
.hint-floating {
  position:relative;
  width:78px;
  height:78px;
  border:0;
  border-radius:20px;
  background:#2898e7;
  color:white;
  box-shadow:0 6px 0 #1778bb,0 8px 15px rgba(0,0,0,.15);
  display:grid;
  place-items:center;
  cursor:pointer;
}
.hint-bulb {
  font-size:39px;
  line-height:1;
  filter:grayscale(1) brightness(0) invert(1);
}
.hint-count {
  position:absolute;
  top:-8px;
  left:-7px;
  width:28px;
  height:28px;
  display:grid;
  place-items:center;
  border-radius:50%;
  background:#17283a;
  color:white;
  font-size:17px;
  font-weight:700;
  border:3px solid #fff;
}
.hint-floating:disabled {
  opacity:.45;
}
.keyboard {
  position:relative;
  z-index:5;
  width:100%;
  padding:10px 23px 6px;
  background:#cfc2b3;
  grid-template-columns:repeat(11,1fr);
  gap:6px;
}
.key {
  min-height:58px;
  border:0;
  border-radius:10px;
  background:#d7cbbc;
  color:#9f9082;
  font-size:23px;
  font-weight:700;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.18);
}
.key:hover:not(:disabled) {
  background:#eee7de;
}
.key.used {
  background:#f8f6f3;
  color:var(--burgundy);
  opacity:1;
}
.key.wrong {
  background:#f8f6f3;
  color:var(--burgundy);
}
.levels-dialog {
  width:min(330px,calc(100% - 30px));
  border:0;
  border-radius:18px;
  background:#fffaf4;
}
.levels-panel {
  position:relative;
  padding:26px;
}
.levels-close-btn {
  width: 100%;
  margin-top: 22px;
  padding: 16px 20px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}
.levels-close-btn:hover { transform: translateY(-1px); }
.levels-close-btn:active { transform: translateY(0); }

.levels-panel h2 {
  margin:0 0 18px;
  text-align:center;
  color:var(--burgundy);
  font-family:Georgia,serif;
}
.level-choices {
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:12px;
}
.level-choice {
  height:62px;
  border:2px solid #d4c5b6;
  border-radius:14px;
  background:#f4ecdf;
  color:var(--burgundy);
  font-size:24px;
  font-weight:700;
}
.level-choice.active {
  background:var(--burgundy);
  color:white;
  border-color:var(--burgundy);
}
#rulesDialog {
  max-height:85vh;
}
@media (min-width:700px) {
  .app { width:500px; margin:auto; box-shadow:0 0 45px rgba(60,45,30,.12); }
  body { background:#e8dfd3; }
}
@media (max-width:430px) {
  .game-header { height:96px; padding:0 22px; }
  .errors-title { font-size:24px; }
  .home-icon { font-size:34px; }
  .header-actions { gap:18px; }
  .keyboard {
    padding:10px 23px 5px;
    grid-template-columns:repeat(11,1fr);
    gap:5px;
  }
  .key { min-height:58px; font-size:20px; }
}
@media (max-width:370px) {
  .game-header { padding:0 14px; }
  .header-actions { gap:12px; }
  .cell { width:31px; }
  .keyboard { padding-left:10px; padding-right:10px; gap:4px; }
  .key { min-height:51px; font-size:18px; border-radius:8px; }
  .controls { right:12px; }
  .hint-floating { width:70px; height:70px; }
}

/* Bright green/lime visual refresh */
:root {
  --game-bg: #f2f9e8;
  --panel-green: #e8f7cf;
  --green: #55c928;
  --lime: #8be13b;
  --dark-green: #267d32;
  --burgundy: #267d32;
  --muted-brown: #8fa58a;
  --key-bg: #dceccf;
}
body {
  background:linear-gradient(180deg,#f7fceF 0%,#eaf7db 100%);
  color:var(--dark-green);
}
.game-header {
  background:#fbfff6;
  border-bottom-color:#e2f2d3;
  color:var(--dark-green);
}
.game-header::after {
  background:repeating-linear-gradient(135deg,#eaf7db 0 7px,#fbfff6 7px 14px);
}
.header-icon { color:var(--dark-green); }
.info-icon {
  border-color:var(--dark-green);
}
.sound-switch {
  position:relative;
  width:50px;
  height:28px;
  border:0;
  border-radius:20px;
  background:#c9d5c3;
  padding:0;
  cursor:pointer;
  transition:.18s ease;
}
.sound-switch .switch-knob {
  position:absolute;
  top:4px;
  left:4px;
  width:20px;
  height:20px;
  border-radius:50%;
  background:#fff;
  box-shadow:0 2px 5px rgba(0,0,0,.18);
  transition:.18s ease;
}
.sound-switch[aria-pressed="true"] {
  background:var(--green);
}
.sound-switch[aria-pressed="true"] .switch-knob {
  left:26px;
}
.errors-title {
  color:#83a27b;
}
.error-dot {
  border-color:#a8bd9e;
}
.error-dot.filled {
  background:var(--green);
  border-color:var(--green);
}
.level-caption { color:#78a56d; }

.phrase-card {
  align-items:center;
  justify-content:center;
  text-align:center;
}
#cipher {
  width:100%;
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  align-content:center;
  align-items:center;
}
.word {
  justify-content:center;
}
.cell {
  border-bottom-color:#a6b89d;
}
.cell.selected {
  background:var(--lime);
}
.cell.solved .letter,
.cell .letter {
  color:var(--dark-green);
}
.cell.selected .letter,
.cell.selected .num {
  color:#fff;
}
.cell .num {
  color:#86a27d;
}
.hint-floating {
  background:linear-gradient(145deg,#69db2d,#36b91d);
  box-shadow:0 6px 0 #299c19,0 8px 15px rgba(60,130,35,.20);
}
.keyboard {
  background:#dcebd2;
}
.key {
  background:#d2e3c8;
  color:#91a58a;
}
.key.in-phrase {
  background:#b9e99d;
  color:#317d2e;
  box-shadow:inset 0 -2px 0 rgba(52,120,40,.12);
}
.key.revealed-key {
  background:#fff;
  color:#38a82b;
  box-shadow:inset 0 0 0 2px #78d94c;
}
.key.unavailable,
.key.unavailable:hover {
  background:#c7d2c0;
  color:#a5aea1;
  opacity:.48;
  cursor:not-allowed;
}
.key:disabled:not(.unavailable) {
  cursor:default;
}
.level-choice.active {
  background:var(--green);
  border-color:var(--green);
}
@media (max-width:430px) {
  .header-actions { gap:12px; }
  .level-top { font-size:18px; min-width:50px; }
  .sound-switch { width:46px; height:26px; }
  .sound-switch .switch-knob { width:18px; height:18px; }
  .sound-switch[aria-pressed="true"] .switch-knob { left:24px; }
}

/* Final polish: settings, typography and level counter */
.settings-icon {
  width: 36px;
  height: 36px;
  font-family: Arial, sans-serif;
  font-size: 31px;
  line-height: 36px;
  transition: transform .18s ease;
}
.settings-icon:hover { transform: rotate(25deg); }

.settings-dialog {
  width: min(360px, calc(100% - 30px));
  border: 0;
  border-radius: 20px;
  padding: 0;
  background: #fbfff6;
  box-shadow: 0 25px 80px rgba(45,80,35,.22);
}
.settings-dialog::backdrop { background: rgba(40,55,35,.42); }
.settings-panel {
  position: relative;
  padding: 25px 22px 22px;
}
.settings-panel h2 {
  margin: 0 0 20px;
  text-align: center;
  color: var(--dark-green);
  font-family: Georgia, serif;
  font-size: 29px;
}
.settings-panel .close-btn {
  position: absolute;
  top: 10px;
  right: 13px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #70906a;
  font-size: 28px;
}
.setting-row {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  padding:16px 4px 4px;
  border-top:1px solid #dcebd2;
}
.setting-title { color:var(--dark-green); font-size:18px; font-weight:800; }
.setting-subtitle { margin-top:3px; color:#91a58a; font-size:13px; }

.sound-switch {
  flex:0 0 auto;
}

.hint-label {
  margin: 0 0 12px;
  color: var(--dark-green);
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  position: relative;
  top: -4px;
  font-size: 24px;
  font-weight: 700;
  font-style: italic;
  letter-spacing: .015em;
}

.level-caption {
  top: 96px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .01em;
}
.level-caption strong { font-weight: 900; color: #628d59; }
.level-separator { font-weight: 900; color: #628d59; }

@media (max-width:430px) {
  .hint-label { font-size: 23px; margin-bottom: 10px; }
  .level-caption { top: 92px; font-size: 15px; }
  .settings-icon { font-size: 29px; }
}

/* Game over actions */
.result-actions { display:flex; flex-direction:column; gap:10px; width:100%; margin-top:18px; }
.result-actions .secondary-btn,
.result-actions .outline-btn { width:100%; }
.secondary-btn, .outline-btn { border:0; border-radius:14px; padding:13px 16px; font:inherit; font-weight:800; cursor:pointer; }
.secondary-btn { background:#e7f0e3; color:#466b3e; }
.outline-btn { background:#fff; color:#55784e; border:2px solid #c8dbc2; }
.result-actions .ad-placeholder { opacity:.72; cursor:default; }

/* Final spacing: move level counter up and widen the game area */
.level-caption {
  top: 76px;
}

@media (min-width:451px) {
  #gameScreen {
    width: 115%;
    margin-left: -7.5%;
  }
}

@media (max-width:430px) {
  .level-caption { top: 72px; }
}

/* Final width alignment: encrypted phrase area matches the keyboard */
.phrase-card {
  width: calc(100% + 20px);
  margin-left: -10px !important;
  margin-right: -10px !important;
}

@media (max-width:370px) {
  .phrase-card {
    width: calc(100% + 20px);
    margin-left: -10px !important;
    margin-right: -10px !important;
  }
}

/* Unified game column: phrase and keyboard share exactly the same outer width */
#gameScreen {
  width: 100%;
  margin-left: 0%;
}
#gameScreen .phrase-card,
#gameScreen .keyboard {
  width: 100%;
}
#gameScreen .phrase-card {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

@media (max-width:430px) {
  #gameScreen {
    width: 100%;
    margin-left: 0;
  }
}


/* Slot navigation */
.slot-navigation {
  display:flex;
  justify-content:center;
  align-items:center;
  gap:14px;
  width:100%;
  padding:12px 23px 16px;
  background:#dcebd2;
}
.slot-nav-btn {
  flex:1 1 0;
  max-width:180px;
  min-height:52px;
  border:2px solid #8fca73;
  border-radius:14px;
  background:#f8fff5;
  color:#317d2e;
  font-size:30px;
  font-weight:900;
  line-height:1;
  cursor:pointer;
  box-shadow:0 4px 0 #72ae5d, 0 7px 14px rgba(60,130,35,.16);
  transition:transform .12s ease, background .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.slot-nav-btn:hover:not(:disabled) {
  background:#b9e99d;
  transform:translateY(-1px);
}
.slot-nav-btn:active:not(:disabled) {
  transform:translateY(2px);
  box-shadow:0 2px 0 #72ae5d;
}
.slot-nav-btn:disabled {
  opacity:.38;
  cursor:default;
  box-shadow:none;
}
@media (max-width:430px) {
  .slot-navigation {
    gap:10px;
    padding:10px 14px 14px;
  }
  .slot-nav-btn {
    min-height:48px;
    font-size:27px;
    border-radius:12px;
  }
}

/* Compact viewport layout: keep the whole game visible without page scrolling */
html, body { height:100%; }
body { overflow:hidden; }
#gameScreen {
  height:calc(100dvh - 100px);
  min-height:0;
  overflow:hidden;
}
#gameScreen .phrase-card {
  flex:1 1 auto;
  min-height:0;
  overflow:hidden;
  justify-content:center;
}
#cipher { max-height:100%; overflow:hidden; }
.controls {
  position:static;
  flex:0 0 70px;
  height:70px;
  margin:0;
  padding:4px 19px 6px;
  display:flex;
  align-items:center;
  justify-content:flex-end;
}
.hint-floating {
  width:62px;
  height:62px;
  border-radius:17px;
}
.hint-bulb { font-size:31px; }
.hint-count {
  width:24px;
  height:24px;
  font-size:15px;
  border-width:2px;
  top:-5px;
  left:-5px;
}
.keyboard {
  flex:0 0 auto;
  padding-top:7px;
  padding-bottom:5px;
  gap:5px;
}
.key { min-height:50px; }
.slot-navigation {
  flex:0 0 66px;
  min-height:66px;
  padding:7px 23px 9px;
}
.slot-nav-btn { min-height:48px; }
@media (max-width:430px) {
  #gameScreen { height:calc(100dvh - 96px); }
  .controls {
    flex-basis:64px;
    height:64px;
    padding:2px 14px 4px;
  }
  .hint-floating { width:58px; height:58px; border-radius:15px; }
  .hint-bulb { font-size:29px; }
  .keyboard { padding:6px 14px 4px; gap:4px; }
  .key { min-height:47px; font-size:19px; }
  .slot-navigation {
    flex-basis:60px;
    min-height:60px;
    padding:6px 14px 8px;
  }
  .slot-nav-btn { min-height:44px; }
  .hint-label { margin-bottom:6px; }
}
@media (max-height:740px) {
  .game-header { height:88px; }
  #gameScreen { height:calc(100dvh - 88px); }
  .level-caption { top:66px; }
  .controls { flex-basis:58px; height:58px; }
  .hint-floating { width:52px; height:52px; }
  .keyboard { padding-top:4px; padding-bottom:3px; }
  .key { min-height:43px; }
  .slot-navigation { flex-basis:54px; min-height:54px; padding:4px 14px 6px; }
  .slot-nav-btn { min-height:40px; }
}

/* Final vertical polish: move the hint and encrypted phrase slightly upward */
#gameScreen .phrase-card {
  transform: translateY(-2px);
}
#gameScreen .controls {
  transform: translateY(-18px);
}


/* Phrase title and slot instruction */
#gameScreen .hint-label {
  font-family: inherit;
  font-size: 27px;
  font-weight: 800;
  font-style: normal;
  letter-spacing: 0;
  margin-bottom: 5px;
}
#gameScreen .slot-instruction {
  margin: 0 0 10px;
  color: #91a58a;
  font-size: 14px;
  font-weight: 400;
  font-style: normal;
  line-height: 1.25;
  text-align: center;
}
@media (max-width:430px) {
  #gameScreen .hint-label { font-size: 26px; }
  #gameScreen .slot-instruction { font-size: 13px; margin-bottom: 8px; }
}


/* Final requested typography and hint sizing */
#gameScreen .level-caption {
  font-size: 17px;
}
#gameScreen .hint-label {
  font-size: 29px;
  font-weight: 700;
}
#gameScreen .slot-instruction {
  margin: 38px 0 8px;
  color: #91a58a;
  font-size: 14px;
  font-weight: 400;
  font-style: normal;
  line-height: 1.25;
  text-align: center;
}
#gameScreen .hint-floating {
  width: 68px;
  height: 68px;
}
#gameScreen .hint-bulb { font-size: 34px; }
#gameScreen .hint-count { width: 25px; height: 25px; font-size: 15px; }
@media (max-width:430px) {
  #gameScreen .level-caption { font-size: 16px; top: 60px; }
  #gameScreen .hint-label { font-size: 28px; font-weight: 700; }
  #gameScreen .slot-instruction { font-size: 13px; margin: 38px 0 7px; }
  #gameScreen .hint-floating { width: 63px; height: 63px; }
  #gameScreen .hint-bulb { font-size: 32px; }
}
@media (max-height:740px) {
  #gameScreen .level-caption { top: 56px; }
  #gameScreen .hint-floating { width: 58px; height: 58px; }
  #gameScreen .hint-bulb { font-size: 30px; }
}

/* Final position lock: keep level and phrase title fixed between levels */
#gameScreen .level-caption {
  top: 56px;
}
#gameScreen .phrase-card {
  justify-content: flex-start;
  padding-top: 128px;
  box-sizing: border-box;
}
#gameScreen .hint-label {
  flex: 0 0 auto;
  margin-top: 0;
}
@media (max-width:430px) {
  #gameScreen .level-caption { top: 40px; }
  #gameScreen .phrase-card { padding-top: 108px; }
}
@media (max-height:740px) {
  #gameScreen .level-caption { top: 36px; }
}

/* Latest vertical adjustment */
#gameScreen .level-caption { top: 36px; }
#gameScreen .phrase-card { padding-top: 108px; }
#gameScreen .slot-instruction { font-size: 15px; }
@media (max-width:430px) {
  #gameScreen .level-caption { top: 20px; }
  #gameScreen .phrase-card { padding-top: 88px; }
  #gameScreen .slot-instruction { font-size: 14px; }
}
@media (max-height:740px) {
  #gameScreen .level-caption { top: 16px; }
}

/* Latest requested vertical/typography adjustment */
#gameScreen .level-caption { top: 16px; }
#gameScreen .phrase-card { padding-top: 88px; }
#gameScreen .slot-instruction { font-size: 17px; }
@media (max-width:430px) {
  #gameScreen .level-caption { top: 0; }
  #gameScreen .phrase-card { padding-top: 68px; }
  #gameScreen .slot-instruction { font-size: 16px; }
}
@media (max-height:740px) {
  #gameScreen .level-caption { top: -4px; }
}

/* Latest requested adjustment: raise phrase title and add breathing room before slots */
#gameScreen .hint-label {
  position: relative;
  top: -30px;
  margin-bottom: 20px;
}


/* Результат — модальное окно по центру, поверх игрового поля */
#resultScreen.result-dialog {
  width: min(430px, calc(100% - 30px));
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: var(--panel, #fffdf8);
  color: var(--ink, #202124);
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
  overflow: hidden;
}
#resultScreen.result-dialog::backdrop {
  background: rgba(35, 29, 25, .48);
}
#resultScreen .result {
  margin: 0;
  border: 0;
  border-radius: 22px;
  box-shadow: none;
  background: transparent;
}
#resultScreen .result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
@media (max-width: 620px) {
  #resultScreen.result-dialog {
    width: calc(100% - 28px);
  }
}

/* Popup headings use the same font as "Ошибки" and "Зашифрованная фраза". */
.levels-panel h2,
.settings-panel h2,
#rulesDialog h2,
#resultScreen .result h2 {
  font-family: Arial, Helvetica, sans-serif;
}

/* Result dialog: answer + hint reward */
#resultText {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:8px;
}
.result-answer-label {
  font-family: inherit;
  font-weight:800;
  color:var(--dark-green);
}
.result-answer {
  font-family: Georgia, serif;
  font-size:18px;
  line-height:1.35;
  color:var(--ink);
}
.result-hint-reward {
  margin-top:4px;
  font-weight:900;
  color:#628d59;
}
.result-congrats {
  font-weight:900;
  font-size:20px;
  color:var(--dark-green);
}

/* Начальный экран «Как играть»: компактнее и со скруглёнными краями */
#rulesDialog {
  width: min(420px, calc(100% - 40px));
  border-radius: 20px;
}
#rulesDialog .rules {
  padding: 20px 26px 22px;
}
#rulesDialog h2 {
  margin-bottom: 14px;
  font-size: 28px;
}
#rulesDialog li {
  margin-bottom: 9px;
  font-size: 15px;
  line-height: 1.38;
}
#rulesDialog .close-btn {
  top: 8px;
  right: 10px;
  width: 30px;
  height: 30px;
  font-size: 25px;
}
@media (max-width: 620px) {
  #rulesDialog {
    width: calc(100% - 36px);
    border-radius: 18px;
  }
  #rulesDialog .rules { padding: 18px 22px 20px; }
  #rulesDialog h2 { font-size: 26px; }
  #rulesDialog li { font-size: 14px; }
}


/* v26: unified bottom buttons for result and modal dialogs */
#resultScreen .result-actions {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}
#resultScreen .result-actions #resultBtn,
#resultScreen .result-actions #resultLevelsBtn {
  width: 180px;
  min-width: 180px;
  box-sizing: border-box;
  min-height: 50px;
  margin: 0;
}
#resultScreen .result-actions #resultLevelsBtn {
  padding: 13px 16px;
  border-radius: 12px;
  font: inherit;
  font-weight: 800;
}
.modal-bottom-btn {
  margin-top: 22px;
}
.settings-panel .modal-bottom-btn {
  margin-top: 22px;
}
#rulesDialog .modal-bottom-btn {
  margin-top: 20px;
}
#rulesDialog .rules {
  border-radius: 20px;
}
@media (max-width: 430px) {
  #resultScreen .result-actions #resultBtn,
  #resultScreen .result-actions #resultLevelsBtn {
    width: 100%;
    min-width: 0;
  }
}

/* v27: result buttons keep a generous desktop width */
#resultScreen .result-actions #resultBtn,
#resultScreen .result-actions #resultLevelsBtn {
  width: 270px;
  min-width: 270px;
}

/* v27: keyboard states
   - revealed letters: no green outline, green letter
   - letters that are in the word but not yet chosen: white background,
     green outline, normal letter color
*/
.key.in-phrase {
  background: #fff;
  color: var(--ink);
  border: 2px solid #78d94c;
  box-shadow: none;
}
.key.in-phrase.revealed-key {
  background: #fff;
  color: #38a82b;
  border: 1px solid var(--line);
  box-shadow: none;
}
.key.revealed-key:hover:not(:disabled) {
  background: #fff;
  color: #38a82b;
  border-color: var(--line);
}

/* v28: result buttons are wide and centered */
#resultScreen .result-actions {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}
#resultScreen .result-actions #resultBtn,
#resultScreen .result-actions #resultLevelsBtn {
  width: 270px;
  min-width: 270px;
  max-width: 270px;
  box-sizing: border-box;
  align-self: center;
}

/* v28: no green outlines around phrase letters */
.key.in-phrase,
.key.in-phrase.revealed-key,
.key.revealed-key:hover:not(:disabled) {
  border: 1px solid var(--line);
  box-shadow: none;
}
.key.in-phrase {
  background: #fff;
  color: var(--ink);
}
.key.in-phrase.revealed-key,
.key.revealed-key:hover:not(:disabled) {
  background: #fff;
  color: #38a82b;
}


/* v29: bottom close buttons for Settings and How to Play */
.settings-panel .modal-bottom-btn,
#rulesDialog .modal-bottom-btn {
  display:block;
  width:100%;
  box-sizing:border-box;
  margin-top:22px;
  padding:16px 20px;
  border:0;
  border-radius:14px;
  background:var(--accent);
  color:#fff;
  font:inherit;
  font-size:18px;
  font-weight:700;
  cursor:pointer;
}
.settings-panel .modal-bottom-btn:hover,
#rulesDialog .modal-bottom-btn:hover { transform:translateY(-1px); }
.settings-panel .close-btn,
#rulesDialog .close-btn { display:none !important; }


/* v30: result actions are equally wide on victory and defeat */
#resultScreen .result-actions #resultBtn,
#resultScreen .result-actions #resultRetryBtn,
#resultScreen .result-actions #resultLevelsBtn {
  width: 270px;
  min-width: 270px;
  max-width: 270px;
  box-sizing: border-box;
  align-self: center;
}

/* v30: very short feedback animations for keyboard choices */
.key.wrong-flash,
.cell.wrong-flash {
  animation: wrongChoice .30s ease-in-out both;
}

@keyframes wrongChoice {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Ошибка трясёт ячейку, но не меняет её фон, цифру или нижнюю платформу. */
.cell.wrong-flash {
  background: #d94a4a !important;
  color: white !important;
  border-bottom-color: #b8a89b !important;
}
.cell.wrong-flash .num {
  color: white !important;
}
.cell.wrong-flash .letter {
  color: white !important;
}
.key.wrong-flash {
  background: #d94a4a !important;
  color: white !important;
}

@media (max-width:430px) {
  #resultScreen .result-actions #resultBtn,
  #resultScreen .result-actions #resultRetryBtn,
  #resultScreen .result-actions #resultLevelsBtn {
    width: 270px;
    min-width: 270px;
    max-width: 270px;
  }
}

/* v31: keep the word slots centered in the available game area. */
#gameScreen .phrase-card {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
}
#gameScreen .hint-label {
  position: absolute;
  top: 54px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  z-index: 2;
}
#gameScreen .cipher-area {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
#gameScreen #cipher {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0 12px;
  box-sizing: border-box;
  min-height: 0;
  align-items: center;
  justify-content: center;
}
#gameScreen .slot-instruction {
  width: 100%;
  margin: 37px 0 0;
  padding: 0 12px;
  box-sizing: border-box;
  text-align: center;
}
@media (max-width:430px) {
  #gameScreen .hint-label { top: 48px; }
  #gameScreen #cipher { padding: 0 8px; }
  #gameScreen .slot-instruction { margin-top: 36px; padding: 0 8px; }
}
\n\n/* v41: result buttons +40px wider */\n#resultScreen .result-actions #resultBtn,\n#resultScreen .result-actions #resultRetryBtn,\n#resultScreen .result-actions #resultLevelsBtn {\n  width: 310px;\n  min-width: 310px;\n  max-width: 310px;\n}\n

/* Completed levels and correct-letter reveal */
.level-choice { position: relative; }
.level-choice .level-check {
  position: absolute;
  top: 5px;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  font-weight: 800;
}
.level-choice.active .level-check { background: #fff; color: var(--green); }
@keyframes revealLetter {
  0% { transform: scale(.72); opacity: .15; }
  65% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.cell.reveal-letter .letter { animation: revealLetter .22s ease-out both; }


/* v44: result retry matches the bottom modal buttons */
#resultScreen .result-actions #resultRetryBtn {
  background: var(--accent);
  color: #fff;
  border: 0;
}

/* v44: completed mark stays inside the level button */
.level-choice {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.level-choice .level-check {
  position: static;
  width: auto;
  height: auto;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: 22px;
  line-height: 1;
  font-weight: 900;
}
.level-choice.active .level-check {
  background: transparent;
  color: inherit;
}


/* v52: extra breathing room for long phrases on small screens.
   The long phrase level gets a little more vertical separation so the
   "Зашифрованная фраза" label never overlaps the cipher cells. */
@media (max-width:430px) {
  #gameScreen.long-phrase-level .phrase-card {
    min-height: 300px;
  }
  #gameScreen.long-phrase-level .hint-label {
    top: 28px;
  }
  #gameScreen.long-phrase-level .cipher-area {
    transform: translateY(24px);
  }
  #gameScreen.long-phrase-level #cipher {
    row-gap: 7px;
  }
  #gameScreen.long-phrase-level .slot-instruction {
    margin-top: 42px;
  }
}

@media (max-width:430px) and (max-height:740px) {
  #gameScreen.long-phrase-level .phrase-card {
    min-height: 290px;
  }
  #gameScreen.long-phrase-level .hint-label {
    top: 22px;
  }
  #gameScreen.long-phrase-level .cipher-area {
    transform: translateY(18px);
  }
  #gameScreen.long-phrase-level .slot-instruction {
    margin-top: 38px;
  }
}


/* v53: content-driven vertical layout for long phrases.
   The phrase block is sized from the real title height instead of fixed offsets. */
@media (max-width:430px) {
  body:has(#gameScreen.dynamic-tall) { overflow-y:auto; overflow-x:hidden; }
  #gameScreen.dynamic-tall {
    height: var(--dynamic-game-height, auto);
    min-height: var(--dynamic-game-height, auto);
    overflow: visible;
  }
  #gameScreen.dynamic-tall .phrase-card {
    flex: 0 0 var(--dynamic-phrase-height, auto);
    height: var(--dynamic-phrase-height, auto);
    min-height: 0;
    overflow: visible;
    transform: none;
  }
  #gameScreen.dynamic-tall .hint-label {
    top: 0;
    transform: none;
  }
  #gameScreen.dynamic-tall .cipher-area {
    transform: none;
    justify-content: flex-start;
    padding-top: var(--dynamic-title-gap, 20px);
    box-sizing: border-box;
  }
  #gameScreen.dynamic-tall #cipher {
    overflow: visible;
    max-height: none;
  }
  #gameScreen.dynamic-tall .slot-instruction {
    margin-top: var(--dynamic-instruction-gap, 22px);
  }
}

/* v54: lower the phrase label by 30px on mobile while preserving
   content-driven spacing and preventing overlap with the cipher area. */
@media (max-width:430px) {
  #gameScreen.dynamic-tall .hint-label {
    transform: translateY(30px);
  }
}

/* v55: move the long-phrase content down by 30px while keeping the
   instruction attached to the slots. Extra card height prevents overlap. */
@media (max-width:430px) {
  #gameScreen.long-phrase-level .phrase-card {
    min-height: 330px;
  }
  #gameScreen.long-phrase-level .cipher-area {
    transform: translateY(54px);
  }
}

@media (max-width:430px) and (max-height:740px) {
  #gameScreen.long-phrase-level .phrase-card {
    min-height: 320px;
  }
  #gameScreen.long-phrase-level .cipher-area {
    transform: translateY(48px);
  }
}
