:root {
  --bg: #efe3ce;
  --bg-deep: #ddc7a5;
  --panel: rgba(250, 243, 229, 0.92);
  --panel-strong: rgba(252, 246, 235, 0.98);
  --panel-emboss: rgba(255, 251, 244, 0.58);
  --ink: #2f2a24;
  --muted: #6d665c;
  --line: rgba(88, 66, 43, 0.18);
  --line-strong: rgba(70, 52, 34, 0.28);
  --accent: #a94f3d;
  --accent-soft: rgba(169, 79, 61, 0.14);
  --easy: #6f7f5e;
  --easy-soft: #ecefdc;
  --medium: #c18a3f;
  --medium-soft: #f7ead4;
  --hard: #af5c46;
  --hard-soft: #f5dfd9;
  --expert: #5f655f;
  --expert-soft: #e7e9e2;
  --positive: #70815f;
  --negative: #b45d47;
  --operator: #6c7667;
  --gold: #b5905a;
  --paper-surface: rgba(247, 238, 223, 0.96);
  --paper-note: rgba(241, 225, 197, 0.96);
  --paper-board: rgba(228, 210, 184, 0.94);
  --paper-shadow-deep: 0 18px 0 rgba(110, 85, 55, 0.08), 0 32px 56px rgba(45, 31, 18, 0.2);
  --stamp: rgba(165, 80, 55, 0.76);
  --tape: rgba(118, 106, 85, 0.78);
  --ink-wash: rgba(49, 38, 27, 0.09);
  --shadow: 0 26px 60px rgba(58, 43, 27, 0.18);
  --shadow-soft: 0 18px 34px rgba(58, 43, 27, 0.13);
  --shadow-paper: 0 8px 0 rgba(137, 108, 77, 0.08), 0 20px 40px rgba(58, 43, 27, 0.15);
  --radius: 30px;
  --circle-size-min: 54px;
  --circle-size: clamp(var(--circle-size-min), 9.2vw, 78px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body {
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(246, 237, 223, 0.96), rgba(234, 220, 198, 0.98));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    linear-gradient(180deg, rgba(255, 250, 241, 0.44), rgba(241, 228, 205, 0.12)),
    radial-gradient(circle at 20% 15%, rgba(255, 251, 245, 0.72), transparent 28%),
    radial-gradient(circle at 82% 22%, rgba(255, 241, 220, 0.42), transparent 22%);
}

body::after {
  opacity: 0.12;
  background-image:
    linear-gradient(90deg, rgba(115, 92, 60, 0.02) 0, rgba(115, 92, 60, 0.02) 1px, transparent 1px),
    linear-gradient(rgba(115, 92, 60, 0.02) 0, rgba(115, 92, 60, 0.02) 1px, transparent 1px);
  background-size: 14px 14px;
}

button {
  font: inherit;
}

a {
  color: inherit;
}

#app {
  height: var(--app-height, 100dvh);
  min-height: 0;
}

.app-shell {
  height: var(--app-height, 100dvh);
  min-height: 0;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  padding: 18px clamp(14px, 3.2vw, 30px) 22px;
  overflow: hidden;
}

.app-shell::before,
.app-shell::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.app-shell::before {
  z-index: -2;
  background: center/cover no-repeat;
  opacity: 0.98;
}

.app-shell::after {
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(248, 240, 227, 0.3), rgba(248, 240, 227, 0.08)),
    radial-gradient(circle at 50% 20%, rgba(255, 248, 236, 0.6), transparent 34%);
}

.app-shell--menu::before,
.app-shell--levels::before {
  background-image: url("assets/paper-dojo-menu-bg.webp");
}

.app-shell--game::before {
  background-image: url("assets/paper-dojo-gameplay-bg.webp");
}

.app-shell--game {
  height: var(--app-height, 100dvh);
  min-height: var(--app-height, 100dvh);
  overflow: hidden;
  padding-top: max(10px, calc(env(safe-area-inset-top) + 6px));
  padding-right: max(clamp(14px, 3.2vw, 30px), calc(env(safe-area-inset-right) + 8px));
  padding-bottom: 10px;
}

.app-shell:not(.app-shell--menu) .site-header,
.app-shell:not(.app-shell--menu) .site-footer {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  max-height: 0;
  min-height: 0;
  overflow: hidden;
  margin: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.site-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 120px;
  padding: 10px 0 6px;
}

.app-shell--game .site-header {
  min-height: 102px;
  padding: 4px 0 0;
}

.brand-link {
  position: absolute;
  left: 0;
  top: 8px;
  display: inline-flex;
  width: clamp(58px, 7vw, 90px);
  padding: 2px;
  border: 0;
  background: transparent;
  filter: drop-shadow(0 4px 8px rgba(58, 43, 27, 0.2));
  transition: transform 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}

.brand-link:hover {
  opacity: 0.96;
  transform: translateY(-2px);
  filter: drop-shadow(0 6px 10px rgba(58, 43, 27, 0.24));
}

.brand-link img {
  width: 100%;
  height: auto;
  display: block;
}

.app-shell--menu .brand-link {
  width: clamp(116px, 14vw, 180px);
}

.app-shell--menu .hero-copy {
  padding: 0 132px;
}

.app-shell--game .brand-link {
  top: 2px;
}

.hero-copy {
  position: relative;
  display: grid;
  place-items: center;
  gap: 18px;
  text-align: center;
  padding: 0 68px;
}

.app-shell--game .hero-copy {
  padding: 0 62px;
}

.section-kicker {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-copy h1,
.game-title-group h2,
.panel-header h2 {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.hero-copy h1 {
  position: relative;
  display: inline-block;
  font-family: Georgia, "Times New Roman", serif;
  z-index: 1;
  font-size: clamp(3.35rem, 7.8vw, 5.6rem);
  line-height: 0.88;
  margin-top: 12px;
  color: #30271f;
  letter-spacing: -0.03em;
  transform: rotate(-1.7deg);
  text-shadow: 0 4px 0 rgba(255, 247, 235, 0.68), 0 12px 22px rgba(44, 30, 18, 0.14);
}

.hero-copy::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 2px;
  width: min(520px, 78vw);
  height: 160px;
  transform: translateX(-50%);
  border-radius: 999px;
  background:
    radial-gradient(circle at center, rgba(255, 249, 239, 0.58), rgba(255, 249, 239, 0) 70%);
  filter: blur(4px);
  pointer-events: none;
}

.hero-copy::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  width: clamp(126px, 17vw, 180px);
  height: clamp(126px, 17vw, 180px);
  transform: translateX(-14%) rotate(-9deg);
  border-radius: 50%;
  background:
    radial-gradient(circle at 46% 44%, rgba(192, 94, 64, 0.92), rgba(160, 74, 49, 0.9) 62%, rgba(150, 65, 39, 0.4) 63%, transparent 70%),
    radial-gradient(circle at 50% 50%, rgba(243, 220, 192, 0.14), transparent 68%);
  opacity: 0.86;
  box-shadow: 0 10px 24px rgba(111, 44, 25, 0.18);
  pointer-events: none;
}

.hero-copy h1::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -18px;
  width: 186px;
  height: 24px;
  transform: translateX(-50%);
  background:
    radial-gradient(circle at 18px 9px, rgba(169, 79, 61, 0.34) 0 6px, transparent 7px),
    linear-gradient(90deg, transparent, rgba(169, 79, 61, 0.4) 15%, rgba(109, 102, 92, 0.26) 50%, rgba(169, 79, 61, 0.4) 85%, transparent);
  opacity: 0.86;
}

.app-shell--game .hero-copy h1 {
  font-size: clamp(2.2rem, 4.8vw, 3.5rem);
  margin-top: 4px;
}

.subtitle {
  margin: 12px 0 0;
  font-size: clamp(1rem, 2vw, 1.18rem);
  color: #394049;
  text-shadow: 0 1px 10px rgba(255, 255, 255, 0.64);
}

.app-shell--game .subtitle {
  margin-top: 6px;
  font-size: clamp(0.92rem, 1.55vw, 1.04rem);
}

.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vw, 18px) 0;
}

.app-shell--game .app-main {
  min-height: 0;
  align-items: stretch;
  padding: 4px 0 2px;
}

.screen {
  width: min(100%, 1040px);
  max-height: 100%;
}

.screen-menu,
.screen-levels {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.app-shell--game .screen {
  height: 100%;
}

.screen-menu,
.screen-levels,
.screen-game {
  animation: screen-fade 260ms ease;
}

.intro-card,
.levels-panel,
.game-shell {
  position: relative;
  background:
    linear-gradient(180deg, rgba(254, 249, 240, 0.96), rgba(245, 234, 214, 0.96));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-paper);
  overflow: hidden;
}

.intro-card::before,
.levels-panel::before,
.game-shell::before,
.rules-modal::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.38), transparent 20%),
    radial-gradient(circle at 20% 18%, rgba(255, 251, 243, 0.45), transparent 22%);
}

.intro-card::after,
.levels-panel::after,
.game-shell::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: calc(var(--radius) - 10px);
  border: 1px solid rgba(128, 101, 71, 0.08);
  pointer-events: none;
}

.intro-card {
  width: min(100%, 360px);
  margin: 0 auto 18px;
  padding: 16px 22px 18px;
  text-align: center;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(244, 228, 198, 0.98), rgba(232, 211, 180, 0.95));
  border: 1px solid rgba(133, 100, 64, 0.16);
  box-shadow: 0 10px 0 rgba(130, 104, 73, 0.08), 0 20px 34px rgba(59, 39, 21, 0.15);
}

.intro-card p {
  margin: 0;
  position: relative;
  z-index: 1;
  color: #4b4339;
  font-weight: 700;
}

.intro-card p + p {
  margin-top: 2px;
}

.intro-card::before {
  background:
    linear-gradient(180deg, rgba(255, 247, 234, 0.55), transparent 40%),
    repeating-linear-gradient(90deg, rgba(138, 105, 70, 0.045) 0 2px, transparent 2px 10px);
}

.intro-card::after {
  inset: auto 12px -9px;
  height: 18px;
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 9px 0, transparent 9px, rgba(213, 192, 165, 0.98) 9.5px) left bottom / 18px 18px repeat-x;
  opacity: 0.95;
}

.difficulty-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  width: min(100%, 920px);
  margin: 0 auto;
  align-items: stretch;
}

.menu-actions {
  display: flex;
  justify-content: center;
  margin: 0 auto 18px;
}

.menu-rules-button {
  min-width: 132px;
  min-height: 40px;
  padding-inline: 20px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(206, 194, 155, 0.98), rgba(176, 161, 124, 0.98));
  color: #2f271f;
  box-shadow: 0 8px 16px rgba(59, 39, 21, 0.14);
}

.menu-rules-button::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 56px;
  height: 18px;
  transform: translateX(-50%) rotate(-1deg);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(149, 138, 116, 0.92), rgba(114, 103, 81, 0.86));
  opacity: 0.88;
  box-shadow: 0 2px 5px rgba(36, 26, 18, 0.18);
  pointer-events: none;
}

.difficulty-card {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  align-items: start;
  justify-items: center;
  width: 100%;
  position: relative;
  min-height: 294px;
  padding: 26px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(248, 238, 220, 0.98), rgba(236, 220, 192, 0.96));
  box-shadow: var(--paper-shadow-deep);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  overflow: visible;
  height: 100%;
}

.difficulty-card:hover {
  transform: translateY(-4px) rotate(-0.4deg);
  box-shadow: 0 18px 0 rgba(110, 85, 55, 0.1), 0 36px 56px rgba(58, 43, 27, 0.24);
}

.difficulty-card[data-accent="easy"] {
  border-color: rgba(111, 127, 94, 0.22);
  background:
    linear-gradient(180deg, rgba(247, 241, 227, 0.98), rgba(235, 224, 203, 0.96));
}

.difficulty-card[data-accent="medium"] {
  border-color: rgba(193, 138, 63, 0.26);
  background:
    linear-gradient(180deg, rgba(248, 238, 222, 0.98), rgba(236, 221, 194, 0.96));
}

.difficulty-card[data-accent="hard"] {
  border-color: rgba(175, 92, 70, 0.24);
  background:
    linear-gradient(180deg, rgba(247, 236, 224, 0.98), rgba(233, 214, 196, 0.96));
}

.difficulty-card[data-accent="expert"] {
  border-color: rgba(95, 101, 95, 0.24);
  background:
    linear-gradient(180deg, rgba(244, 233, 218, 0.98), rgba(232, 212, 186, 0.96));
}

.difficulty-card::before {
  content: "";
  position: absolute;
  inset: 10px 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(119, 94, 64, 0.12);
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 28%),
    repeating-linear-gradient(90deg, rgba(137, 103, 69, 0.03) 0 2px, transparent 2px 11px);
}

.difficulty-card::after {
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  width: 52px;
  height: 18px;
  transform: translateX(-50%) rotate(-1deg);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(93, 84, 72, 0.86), rgba(67, 61, 53, 0.92));
  box-shadow: 0 4px 10px rgba(39, 26, 18, 0.18);
}

.difficulty-card[data-accent="easy"]::after {
  background: linear-gradient(180deg, rgba(111, 127, 94, 0.88), rgba(91, 104, 77, 0.94));
}

.difficulty-card[data-accent="medium"]::after {
  background: linear-gradient(180deg, rgba(193, 138, 63, 0.88), rgba(156, 111, 47, 0.94));
}

.difficulty-card[data-accent="hard"]::after {
  background: linear-gradient(180deg, rgba(175, 92, 70, 0.9), rgba(144, 72, 53, 0.94));
}

.difficulty-card[data-accent="expert"]::after {
  background: linear-gradient(180deg, rgba(95, 101, 95, 0.88), rgba(72, 77, 72, 0.94));
}

.difficulty-icon {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 22px;
  font-size: 2.25rem;
  font-weight: 800;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 252, 246, 0.98), rgba(245, 233, 210, 0.96) 72%, rgba(227, 208, 178, 0.98));
  border: 1px solid rgba(108, 82, 48, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.66), 0 10px 18px rgba(60, 41, 21, 0.09);
}

.difficulty-copy {
  display: grid;
  gap: 6px;
  text-align: center;
  justify-items: center;
  align-self: start;
}

.difficulty-title {
  font-size: 1.46rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.difficulty-description {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
  max-width: 16ch;
  min-height: 3.9em;
  display: flex;
  align-items: center;
}

.difficulty-progress {
  width: 100%;
  margin-top: auto;
  padding-top: 12px;
  display: grid;
  justify-items: center;
  text-align: center;
  color: var(--muted);
  border-top: 1px dashed rgba(117, 92, 62, 0.22);
  position: relative;
}

.difficulty-progress::before {
  content: "⋆ ⋆ ⋆";
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 10px;
  background: inherit;
  color: rgba(145, 111, 71, 0.72);
  letter-spacing: 0.28em;
  font-size: 0.74rem;
}

.difficulty-progress strong {
  display: block;
  font-size: 1.46rem;
  line-height: 1;
  color: var(--ink);
}

.panel-header,
.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-header {
  width: min(100%, 780px);
  margin: 0 auto 18px;
}

.screen-levels .panel-header > div {
  position: relative;
  padding: 0 18px 8px;
}

.screen-levels .panel-header > div::before {
  content: "";
  position: absolute;
  inset: -10px 0 0;
  background:
    radial-gradient(circle at center, rgba(176, 91, 63, 0.16), transparent 58%);
  filter: blur(2px);
  pointer-events: none;
}

.panel-header h2,
.game-title-group h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 3vw, 2.2rem);
}

.levels-panel {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: clamp(24px, 3vw, 34px) clamp(18px, 2.8vw, 26px) clamp(26px, 3vw, 36px);
  border-radius: 34px;
  background:
    linear-gradient(180deg, rgba(247, 237, 220, 0.97), rgba(233, 216, 188, 0.95));
  box-shadow: var(--paper-shadow-deep);
}

.levels-panel::before {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.4), transparent 22%),
    radial-gradient(circle at 84% 18%, rgba(169, 79, 61, 0.06), transparent 20%),
    radial-gradient(circle at 16% 82%, rgba(111, 127, 94, 0.08), transparent 22%),
    repeating-linear-gradient(90deg, rgba(137, 103, 69, 0.03) 0 2px, transparent 2px 10px);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 16px);
  padding: 10px 6px 2px;
}

.level-tile {
  min-height: 84px;
  border: 1px solid rgba(92, 69, 43, 0.14);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(252, 245, 232, 0.98), rgba(236, 220, 193, 0.96));
  color: var(--ink);
  font-size: clamp(1rem, 2.4vw, 1.45rem);
  font-weight: 800;
  box-shadow: 0 10px 0 rgba(121, 95, 63, 0.08), 0 18px 22px rgba(58, 43, 27, 0.12);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, border-color 160ms ease;
  position: relative;
  overflow: visible;
}

.level-tile:hover:not(:disabled) {
  transform: translateY(-3px) rotate(-0.5deg);
  box-shadow: 0 12px 0 rgba(121, 95, 63, 0.08), 0 22px 28px rgba(58, 43, 27, 0.16);
}

.level-tile::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 38px;
  height: 14px;
  transform: translateX(-50%) rotate(-1deg);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(127, 117, 99, 0.86), rgba(88, 79, 68, 0.92));
  box-shadow: 0 3px 8px rgba(36, 26, 18, 0.18);
}

.level-tile::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 12px;
  border: 1px solid rgba(120, 91, 60, 0.1);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 34%);
  pointer-events: none;
}

.level-tile.is-complete[data-accent="easy"] {
  background: linear-gradient(180deg, #8a9773, #6b7d5b);
  color: #fff8ef;
}

.level-tile.is-complete[data-accent="medium"] {
  background: linear-gradient(180deg, #c99651, #af7f3c);
  color: #fff9f1;
}

.level-tile.is-complete[data-accent="hard"] {
  background: linear-gradient(180deg, #c0735b, #a45140);
  color: #fff7f2;
}

.level-tile.is-complete[data-accent="expert"] {
  background: linear-gradient(180deg, #757a73, #5b615b);
  color: #fff9f0;
}

.level-tile.is-locked {
  color: #8b8276;
  background:
    repeating-linear-gradient(135deg, rgba(230, 222, 206, 0.96) 0 12px, rgba(219, 209, 192, 0.96) 12px 24px);
  cursor: not-allowed;
  box-shadow: inset 0 0 0 1px rgba(106, 87, 63, 0.04);
}

.text-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(92, 69, 43, 0.18);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(252, 246, 235, 0.98), rgba(241, 228, 205, 0.94));
  color: var(--ink);
  box-shadow: 0 10px 18px rgba(58, 43, 27, 0.08);
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
  position: relative;
}

.text-button:hover,
.icon-button:hover {
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 1), rgba(243, 230, 209, 0.96));
  transform: translateY(-1px);
  box-shadow: 0 16px 24px rgba(58, 43, 27, 0.13);
}

.screen-levels .text-button,
.screen-game .text-button,
.screen-game .icon-button {
  box-shadow: 0 8px 0 rgba(119, 93, 63, 0.08), 0 16px 18px rgba(58, 43, 27, 0.12);
}

.text-button:focus-visible,
.icon-button:focus-visible,
.difficulty-card:focus-visible,
.level-tile:focus-visible,
.circle:focus-visible {
  outline: 3px solid rgba(169, 79, 61, 0.34);
  outline-offset: 3px;
}

.icon-button {
  font-weight: 700;
}

.text-button::after,
.icon-button::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: inherit;
  border: 1px solid rgba(116, 90, 57, 0.08);
  pointer-events: none;
}

.game-shell {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 30px);
  background:
    linear-gradient(180deg, rgba(244, 231, 211, 0.96), rgba(224, 201, 167, 0.95));
  border-color: rgba(108, 79, 48, 0.16);
  box-shadow: 0 18px 0 rgba(118, 89, 55, 0.08), 0 34px 56px rgba(42, 30, 18, 0.22);
}

.game-shell::before {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.32), transparent 22%),
    radial-gradient(circle at 50% 0, rgba(255, 247, 234, 0.22), transparent 36%),
    radial-gradient(circle at 88% 18%, rgba(169, 79, 61, 0.05), transparent 18%),
    repeating-linear-gradient(90deg, rgba(137, 103, 69, 0.03) 0 2px, transparent 2px 10px);
}

.app-shell--game .screen-game {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.app-shell--game .game-shell {
  width: min(100%, 1040px);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-content: stretch;
  padding: 14px 18px 10px;
}

.game-toolbar {
  margin-bottom: 12px;
  padding: 0 6px 10px;
  border-bottom: 1px dashed rgba(117, 89, 57, 0.22);
}

.app-shell--game .game-toolbar {
  margin-bottom: 6px;
}

.game-toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.fullscreen-button {
  display: none;
  width: 46px;
  min-width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 50%;
}

.fullscreen-button[hidden] {
  display: none !important;
}

.fullscreen-icon {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.fullscreen-icon-exit,
.fullscreen-button[aria-pressed="true"] .fullscreen-icon-enter {
  display: none;
}

.fullscreen-button[aria-pressed="true"] .fullscreen-icon-exit {
  display: block;
}

@media (min-width: 821px) and (any-pointer: fine) {
  .fullscreen-button.is-supported {
    display: inline-flex;
  }
}

@media (min-width: 821px) and (min-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  .fullscreen-button.is-supported {
    display: inline-flex;
  }
}

.game-title-group {
  text-align: center;
  flex: 1;
}

.game-title-group h2 {
  letter-spacing: 0.015em;
}

.move-count {
  margin: 6px 0 0;
  color: #6e6558;
  font-weight: 600;
}

.app-shell--game .game-title-group h2 {
  font-size: clamp(1.3rem, 2.3vw, 1.8rem);
}

.app-shell--game .move-count {
  margin-top: 4px;
  font-size: 0.94rem;
}

.preview-card {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  max-width: min(100%, 720px);
  padding: 12px 18px;
  border-radius: 14px;
  border: 1px solid rgba(108, 82, 48, 0.12);
  background:
    linear-gradient(180deg, rgba(245, 229, 198, 0.98), rgba(234, 214, 184, 0.96));
  box-shadow: 0 8px 0 rgba(124, 94, 61, 0.08), 0 14px 22px rgba(58, 43, 27, 0.14);
  text-align: center;
  font-weight: 700;
  animation: pop-in 240ms ease;
  position: relative;
}

.preview-card::after {
  content: "";
  position: absolute;
  right: auto;
  left: 50%;
  top: -8px;
  width: 44px;
  height: 14px;
  transform: translateX(-50%) rotate(-1deg);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(124, 112, 92, 0.88), rgba(94, 85, 70, 0.92));
  box-shadow: 0 3px 8px rgba(36, 26, 18, 0.14);
}

.preview-card.is-zero {
  border-color: rgba(78, 143, 107, 0.32);
  color: var(--easy);
}

.preview-card small {
  font-size: 0.82rem;
  opacity: 0.86;
}

.board-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  min-height: 0;
  height: 100%;
  padding: 18px;
  border-radius: 36px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 248, 234, 0.22), transparent 55%),
    linear-gradient(180deg, rgba(128, 98, 65, 0.18), rgba(73, 51, 31, 0.16)),
    linear-gradient(180deg, rgba(222, 199, 167, 0.8), rgba(180, 152, 117, 0.72));
  border: 1px solid rgba(109, 81, 49, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 245, 226, 0.54), 0 18px 28px rgba(48, 34, 20, 0.16);
  overflow: hidden;
}

.board-stage::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 28px;
  border: 1px solid rgba(84, 61, 35, 0.1);
  pointer-events: none;
}

.game-board {
  position: relative;
  width: min(100%, 720px);
  aspect-ratio: 3 / 2;
  min-height: 240px;
  overflow: hidden;
  border-radius: 28px;
  border: 1px solid rgba(92, 69, 43, 0.24);
  background:
    radial-gradient(circle at 50% 50%, rgba(244, 231, 209, 0.88), rgba(223, 202, 172, 0.78) 60%, rgba(109, 83, 52, 0.4) 100%),
    linear-gradient(180deg, rgba(145, 111, 73, 0.2), rgba(60, 43, 26, 0.12)),
    url("assets/paper-dojo-gameplay-bg.webp") center/cover no-repeat;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42), inset 0 0 90px rgba(62, 44, 27, 0.14), 0 20px 28px rgba(58, 43, 27, 0.15);
  touch-action: none;
}

.game-board::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 20px;
  border: 1px solid rgba(103, 79, 50, 0.14);
  background:
    radial-gradient(circle at 50% 50%, transparent 56%, rgba(72, 52, 31, 0.08) 100%);
  pointer-events: none;
}

.game-board::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 52%, transparent 28%, rgba(75, 54, 33, 0.08) 100%),
    linear-gradient(90deg, rgba(87, 63, 38, 0.12), transparent 18%, transparent 82%, rgba(87, 63, 38, 0.12));
  pointer-events: none;
}

.app-shell--game .game-board {
  width: min(100%, 980px, calc((var(--app-height, 100dvh) - 120px) * 1.5));
  max-height: calc(var(--app-height, 100dvh) - 120px);
}

@media (orientation: portrait) {
  .app-shell--game .game-board {
    aspect-ratio: 1 / 1;
    width: min(100%, 920px, calc(var(--app-height, 100dvh) - 300px));
    max-height: calc(var(--app-height, 100dvh) - 300px);
  }
}

.board-pattern,
.board-circles,
.board-feedback,
.board-overlay {
  position: absolute;
  inset: 0;
}

.board-pattern {
  opacity: 0.2;
  background-image:
    radial-gradient(circle at 50% 100%, rgba(91, 70, 47, 0.28) 1px, transparent 1px),
    radial-gradient(circle at 0 100%, rgba(91, 70, 47, 0.22) 1px, transparent 1px),
    radial-gradient(circle at 15% 18%, rgba(168, 79, 61, 0.07), transparent 28%),
    radial-gradient(circle at 82% 76%, rgba(111, 127, 94, 0.07), transparent 26%);
  background-size: 42px 22px, 42px 22px, auto, auto;
  background-position: 0 0, 21px 11px, 0 0, 0 0;
}

.board-ghost {
  position: absolute;
  border-radius: 50%;
  border: 2px dashed rgba(213, 138, 71, 0.58);
  background: rgba(213, 138, 71, 0.08);
  pointer-events: none;
}

.board-feedback {
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 18px;
  z-index: 6;
}

.board-feedback .preview-card {
  margin-top: 4px;
}

.circle {
  position: absolute;
  display: grid;
  place-items: center;
  width: var(--circle-size);
  height: var(--circle-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  font-size: clamp(1rem, 3.1vw, 1.65rem);
  font-weight: 800;
  box-shadow: 0 16px 26px rgba(44, 40, 35, 0.18);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition:
    left 220ms cubic-bezier(0.22, 1, 0.36, 1),
    top 220ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 160ms ease,
    box-shadow 160ms ease,
    opacity 180ms ease,
    filter 180ms ease;
  animation: pop-in 260ms ease;
  will-change: left, top, transform, opacity;
}

.circle.is-instant {
  transition: none;
}

.circle-label {
  display: inline-block;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.circle-positive {
  background: linear-gradient(180deg, #869571, #697b58);
}

.circle-negative {
  background: linear-gradient(180deg, #c7745e, #a75341);
}

.circle-operator {
  background: linear-gradient(180deg, #7d8478, #626a60);
}

.circle.is-dragging {
  transform: scale(1.08);
  box-shadow: 0 18px 38px rgba(44, 40, 35, 0.24);
  cursor: grabbing;
  transition: none;
  z-index: 20;
}

.circle.is-drop-target {
  transform: scale(1.06);
  outline: 4px solid rgba(169, 79, 61, 0.24);
  outline-offset: 2px;
}

.circle.is-selected {
  outline: 4px solid rgba(169, 79, 61, 0.7);
  outline-offset: 4px;
  box-shadow: 0 0 0 7px rgba(255, 248, 234, 0.78), 0 18px 34px rgba(44, 40, 35, 0.24);
}

.circle.is-removing {
  animation: pop-out 300ms ease forwards;
}

.circle.is-merging-source {
  opacity: 0.18;
  transform: scale(0.78);
  filter: saturate(0.85);
  z-index: 12;
}

.circle.is-merge-absorbing {
  box-shadow: 0 18px 40px rgba(44, 40, 35, 0.24);
}

.circle.is-value-updating .circle-label {
  animation: value-bump 220ms ease;
}

.circle.is-shaking {
  animation: shake 380ms ease;
}

.board-overlay {
  pointer-events: none;
  display: grid;
  place-items: center;
  z-index: 7;
}

.board-message {
  display: grid;
  gap: 6px;
  place-items: center;
  padding: 18px 22px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(247, 233, 205, 0.98), rgba(235, 216, 184, 0.98));
  border: 1px solid rgba(98, 74, 45, 0.14);
  box-shadow: 0 10px 0 rgba(120, 93, 63, 0.08), 0 18px 30px rgba(58, 43, 27, 0.18);
  text-align: center;
  animation: pop-in 280ms ease;
}

.board-message p,
.board-message small {
  margin: 0;
}

.board-message-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.5rem;
  font-weight: 800;
}

.board-message.is-success .board-message-icon {
  background: rgba(78, 143, 107, 0.15);
  color: var(--easy);
}

.board-message.is-success p {
  color: var(--easy);
  font-size: 1.25rem;
  font-weight: 800;
}

.board-message.is-warning .board-message-icon {
  background: rgba(193, 98, 88, 0.14);
  color: var(--hard);
}

.board-message.is-warning p {
  color: var(--hard);
  font-size: 1.2rem;
  font-weight: 800;
}

.board-message small {
  color: var(--muted);
}

.board-instructions {
  min-height: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px auto 0;
  width: fit-content;
  max-width: 100%;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(243, 228, 202, 0.72);
  border: 1px solid rgba(116, 89, 58, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 248, 236, 0.56);
  text-align: center;
  color: #5a5147;
  font-weight: 600;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(44, 34, 23, 0.34);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.rules-modal {
  width: min(100%, 560px);
  border: 1px solid rgba(98, 74, 45, 0.16);
  border-radius: 28px;
  padding: 24px;
  background: linear-gradient(180deg, rgba(252, 246, 235, 0.98), rgba(243, 230, 210, 0.98));
  box-shadow: 0 24px 56px rgba(41, 36, 31, 0.22);
  position: relative;
  max-height: calc(var(--app-height, 100dvh) - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.rules-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.rules-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
}

.rules-copy {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  color: #46505c;
  line-height: 1.5;
}

.rules-copy p {
  margin: 0;
}

.app-shell--game .board-instructions {
  min-height: 22px;
  height: 22px;
  margin-top: 10px;
  font-size: 0.92rem;
}

.site-footer {
  padding-top: 14px;
  text-align: center;
  color: #5e564d;
  text-shadow: 0 1px 10px rgba(255, 251, 244, 0.44);
}

.app-shell--game .site-footer {
  padding-top: 6px;
  font-size: 0.82rem;
  opacity: 0.84;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  text-underline-offset: 3px;
}

@keyframes screen-fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pop-out {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.2);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-7px);
  }
  75% {
    transform: translateX(7px);
  }
}

@keyframes value-bump {
  0% {
    opacity: 0.72;
    transform: scale(0.88);
  }
  45% {
    opacity: 1;
    transform: scale(1.12);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 820px) {
  .site-header {
    min-height: 102px;
  }

  .hero-copy {
    padding: 0 58px;
  }

  .difficulty-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 620px;
  }

  .difficulty-card {
    min-height: 248px;
    padding: 22px 16px 14px;
  }

  .difficulty-progress {
    width: 100%;
  }

  .game-toolbar {
    flex-wrap: wrap;
  }

  .game-title-group {
    order: -1;
    width: 100%;
  }

  .game-toolbar-actions {
    margin-left: auto;
  }
}

@media (max-height: 900px) {
  .site-header {
    min-height: 118px;
    padding-top: 8px;
  }

  .hero-copy h1 {
    font-size: clamp(2.5rem, 5.8vw, 4rem);
  }

  .subtitle {
    margin-top: 8px;
    font-size: clamp(0.92rem, 1.7vw, 1.06rem);
  }

  .intro-card {
    margin-bottom: 14px;
    padding: 14px 18px;
  }

  .difficulty-list {
    gap: 10px;
  }

  .difficulty-card {
    min-height: 228px;
    padding: 18px 16px 14px;
  }

  .difficulty-icon {
    width: 68px;
    height: 68px;
  }

  .app-shell--game {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .app-shell--game .site-header {
    min-height: 88px;
  }

  .app-shell--game .hero-copy h1 {
    font-size: clamp(2rem, 4.2vw, 3rem);
  }

  .app-shell--game .subtitle {
    font-size: 0.92rem;
  }

  .app-shell--game .game-shell {
    padding: 12px 16px 8px;
  }

  .app-shell--game .preview-zone {
    min-height: 48px;
  }

  .board-stage {
    padding: 14px;
  }

  .app-shell--game .game-board {
    width: min(100%, 920px, calc((var(--app-height, 100dvh) - 220px) * 1.5));
    max-height: calc(var(--app-height, 100dvh) - 220px);
  }

  .app-shell--game .board-instructions {
    margin-top: 8px;
    min-height: 20px;
  }
}

@media (min-width: 821px) and (max-height: 650px) {
  .app-shell {
    padding: 8px clamp(16px, 2.4vw, 24px);
  }

  .site-header {
    min-height: 76px;
    height: 76px;
    padding: 2px 0;
  }

  .app-shell--menu .brand-link {
    width: clamp(100px, 12vw, 150px);
    top: 2px;
  }

  .app-shell--menu .hero-copy h1 {
    margin-top: 0;
    font-size: clamp(2.5rem, 5vw, 3.5rem);
  }

  .app-main {
    padding: 4px 0;
  }

  .screen-menu {
    display: grid;
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "intro difficulties"
      "actions difficulties";
    gap: 10px 16px;
    align-items: center;
    overflow: visible;
  }

  .screen-menu .intro-card {
    grid-area: intro;
    width: 100%;
    margin: 0;
    padding: 12px 14px 14px;
  }

  .screen-menu .menu-actions {
    grid-area: actions;
    margin: 0;
  }

  .screen-menu .difficulty-list {
    grid-area: difficulties;
    align-self: center;
    width: 100%;
    gap: 8px;
  }

  .screen-menu .difficulty-card {
    min-height: 250px;
    gap: 6px;
    padding: 14px 10px 10px;
  }

  .screen-menu .difficulty-icon {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    font-size: 1.55rem;
  }

  .screen-menu .difficulty-title {
    font-size: 1.25rem;
  }

  .screen-menu .difficulty-description {
    font-size: 0.8rem;
    line-height: 1.25;
  }

  .screen-menu .difficulty-progress strong {
    font-size: 1.3rem;
  }

  .site-footer {
    min-height: 28px;
    padding-top: 4px;
    font-size: 0.86rem;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 12px;
  }

  .brand-link {
    left: 4px;
    top: 6px;
  }

  .app-shell--menu .brand-link {
    width: clamp(96px, 24vw, 144px);
  }

  .app-shell--menu .hero-copy {
    padding: 0 92px;
  }

  .hero-copy {
    padding: 0 44px;
  }

  .intro-card,
  .levels-panel,
  .game-shell {
    border-radius: 24px;
  }

  .difficulty-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .difficulty-card {
    min-height: 214px;
  }

  .level-grid {
    gap: 8px;
  }

  .level-tile {
    min-height: 60px;
    border-radius: 18px;
  }

  .board-stage {
    padding: 10px;
    border-radius: 28px;
  }

  .game-board {
    border-radius: 26px;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding: 12px 10px 14px;
  }

  .site-header {
    min-height: 110px;
    padding-top: 6px;
  }

  .hero-copy {
    padding: 0 40px;
  }

  .hero-copy h1 {
    font-size: clamp(2rem, 11vw, 2.8rem);
    margin-top: 4px;
  }

  .subtitle {
    margin-top: 6px;
    font-size: 0.92rem;
  }

  .intro-card {
    margin-bottom: 12px;
    padding: 12px 16px;
  }

  .difficulty-list {
    gap: 8px;
  }

  .difficulty-card {
    min-height: 190px;
    gap: 8px;
    padding: 16px 12px 12px;
  }

  .difficulty-card::after {
    width: 42px;
    height: 12px;
    top: -7px;
  }

  .rules-modal {
    padding: 18px 16px;
    border-radius: 24px;
  }

  .difficulty-icon {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    font-size: 1.45rem;
  }

  .difficulty-title {
    font-size: 1.12rem;
  }

  .difficulty-description {
    font-size: 0.82rem;
  }

  .difficulty-progress strong {
    font-size: 1.28rem;
  }

  .text-button,
  .icon-button,
  .fullscreen-button {
    min-width: 44px;
    min-height: 44px;
    padding-inline: 14px;
  }

  .preview-zone {
    min-height: 64px;
  }
}
