:root {
  --ink: #2e1b10;
  --cream: #fff4dd;
  --gold: #f6b73e;
  --gold-deep: #c98212;
  --brown: #3b2416;
  --panel: rgba(255, 244, 219, .72);
  --line: rgba(92, 52, 20, .22);
  --ui-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --title-font: Georgia, "Times New Roman", serif;
  --propisi-font: "PropisiWeb", "PropisiOriginal", "PropisiOFont", cursive;
  --english-font: "SassoonJoined", Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100vh;
  color: var(--cream);
  font-family: var(--ui-font);
  background:
    linear-gradient(180deg, rgba(22, 13, 8, .18), rgba(22, 13, 8, .4)),
    url("./фон собери предложение.PNG") center / cover fixed no-repeat,
    #180f0a;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.game-shell {
  position: relative;
  width: min(100%, 1240px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(18px, 2.4vw, 30px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 50px;
  position: relative;
  z-index: 5;
}

.back-button,
.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 226, 170, .22);
  border-radius: 12px;
  color: #fff6e7;
  background: rgba(55, 34, 20, .6);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
  text-decoration: none;
  font-size: 28px;
  line-height: 1;
}

.icon-button {
  font-size: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
  color: #fff3d5;
  font-family: var(--title-font);
  font-size: 31px;
  font-weight: 700;
  letter-spacing: .02em;
  text-shadow: 0 3px 16px rgba(0, 0, 0, .45);
}

.brand img {
  width: 58px;
  height: 46px;
  object-fit: contain;
  filter: drop-shadow(0 7px 16px rgba(244, 199, 107, .24));
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented {
  display: inline-flex;
  align-items: center;
  padding: 4px;
  border-radius: 12px;
  background: rgba(72, 43, 25, .82);
  border: 1px solid rgba(255, 226, 170, .18);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05);
}

.segmented button {
  min-width: 38px;
  height: 32px;
  border-radius: 8px;
  color: rgba(255, 244, 224, .72);
  background: transparent;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: .08em;
}

.segmented button.is-active {
  color: #2c170b;
  background: linear-gradient(180deg, #ffd36c, #f0a725);
  box-shadow: 0 8px 20px rgba(235, 154, 27, .24);
}

.level-picker {
  position: relative;
}

.level-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  color: #fff3d5;
  background: rgba(55, 34, 20, .64);
  border: 1px solid rgba(255, 226, 170, .2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06), 0 12px 30px rgba(0, 0, 0, .18);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .02em;
  white-space: nowrap;
}

.level-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  display: grid;
  gap: 6px;
  min-width: 190px;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid rgba(255, 226, 170, .18);
  background: rgba(37, 23, 14, .94);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .32), inset 0 0 0 1px rgba(255, 255, 255, .05);
  backdrop-filter: blur(14px);
}

.level-menu.hidden {
  display: none;
}

.level-menu button {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 11px;
  color: #fff3d5;
  background: rgba(255, 255, 255, .06);
  font-size: 12px;
  font-weight: 850;
  text-align: left;
}

.level-menu button:hover {
  color: #2c170b;
  background: linear-gradient(180deg, #ffd36c, #f0a725);
}

.sound-button {
  font-size: 18px;
}

.progress-row {
  position: absolute;
  top: clamp(96px, 9vw, 124px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.crystals {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.crystal {
  width: clamp(32px, 3.2vw, 46px);
  height: clamp(58px, 5.6vw, 82px);
  background: url("./crystal-progress.png") center / contain no-repeat;
  opacity: .24;
  filter: grayscale(.7) drop-shadow(0 2px 6px rgba(0, 0, 0, .32));
  transition: opacity .24s ease, filter .24s ease, transform .24s ease;
}

.crystal.filled {
  opacity: 1;
  filter: drop-shadow(0 0 16px rgba(255, 207, 92, .7));
  transform: translateY(-2px) scale(1.05);
}

.progress-label {
  display: none;
}

.book-area {
  position: relative;
  min-height: calc(100vh - 120px);
  margin-top: -20px;
}

.owl {
  position: absolute;
  left: clamp(34px, 8vw, 104px);
  bottom: clamp(122px, 13vw, 172px);
  width: clamp(92px, 10vw, 142px);
  z-index: 2;
  filter: drop-shadow(0 16px 20px rgba(0, 0, 0, .35));
}

.parchment {
  position: relative;
  width: 100%;
  min-height: calc(100vh - 112px);
  padding: clamp(24px, 4vw, 48px) clamp(28px, 5vw, 70px) clamp(22px, 3vw, 38px);
  color: var(--cream);
}

.task-copy {
  margin: 4px auto 26px;
  text-align: center;
  max-width: 720px;
}

.kicker {
  display: none;
  margin-bottom: 6px;
  color: rgba(255, 227, 171, .7);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1 {
  font-family: var(--title-font);
  font-size: clamp(30px, 3.2vw, 48px);
  line-height: 1;
  color: #ffdf8f;
  text-shadow: 0 0 18px rgba(255, 185, 68, .28), 0 4px 18px rgba(0, 0, 0, .46);
}

.answer-zone {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: clamp(12px, 1.6vw, 20px);
  min-height: clamp(74px, 8vw, 104px);
  margin: 0 auto clamp(18px, 2.4vw, 30px);
  padding: 6px min(4vw, 46px);
}

.sentence-slot {
  position: relative;
  display: grid;
  place-items: center;
  width: auto;
  min-width: clamp(96px, 10vw, 138px);
  min-height: clamp(58px, 5vw, 72px);
  padding: 7px 14px;
  border-radius: 18px;
  background:
    linear-gradient(90deg, transparent 9px, rgba(255, 206, 98, .95) 9px 11px, transparent 11px) left top / 100% 2px no-repeat,
    linear-gradient(90deg, transparent 9px, rgba(255, 206, 98, .95) 9px 11px, transparent 11px) left bottom / 100% 2px no-repeat,
    linear-gradient(180deg, transparent 9px, rgba(255, 206, 98, .95) 9px 11px, transparent 11px) left top / 2px 100% no-repeat,
    linear-gradient(180deg, transparent 9px, rgba(255, 206, 98, .95) 9px 11px, transparent 11px) right top / 2px 100% no-repeat,
    radial-gradient(circle at 50% 0, rgba(255, 239, 164, .72) 0 2px, transparent 3px),
    radial-gradient(circle at 50% 100%, rgba(255, 239, 164, .64) 0 2px, transparent 3px),
    rgba(18, 10, 8, .18);
  box-shadow:
    0 0 0 1px rgba(255, 197, 72, .16),
    inset 0 0 22px rgba(255, 190, 64, .08),
    0 0 24px rgba(255, 190, 64, .16);
}

.sentence-slot.filled {
  background:
    radial-gradient(circle at 50% 0, rgba(255, 239, 164, .72) 0 2px, transparent 3px),
    radial-gradient(circle at 50% 100%, rgba(255, 239, 164, .64) 0 2px, transparent 3px),
    rgba(255, 205, 92, .08);
}

.answer-placeholder {
  color: rgba(74, 43, 24, .42);
  font-weight: 800;
}

.word-bank {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: clamp(10px, 1.4vw, 16px);
  min-height: 112px;
  margin: 0 auto clamp(18px, 3vw, 34px);
  padding-inline: clamp(20px, 8vw, 120px);
}

.word-token {
  position: relative;
  min-width: 92px;
  min-height: 66px;
  padding: 0 34px;
  display: inline-grid;
  place-items: center;
  color: #3b2213;
  background:
    linear-gradient(180deg, rgba(255, 239, 198, .96), rgba(236, 199, 126, .94)),
    url("./рамочка для слов.PNG") center / 100% 100% no-repeat;
  border-radius: 18px;
  font-size: clamp(20px, 2.35vw, 28px);
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  filter: drop-shadow(0 12px 14px rgba(89, 50, 23, .16));
  transition: transform .18s ease, filter .18s ease, opacity .18s ease;
  user-select: none;
}

.word-token:hover {
  transform: translateY(-3px);
  filter: drop-shadow(0 16px 18px rgba(89, 50, 23, .2)) drop-shadow(0 0 12px rgba(244, 183, 62, .18));
}

.word-token.used {
  opacity: .28;
  pointer-events: none;
  transform: scale(.96);
}

.word-token.answer {
  background-size: 100% 100%;
  min-width: 92px;
  min-height: 58px;
  padding-inline: 22px;
  font-size: clamp(18px, 2vw, 24px);
}

.word-token.correct {
  filter: drop-shadow(0 0 18px rgba(244, 183, 62, .28));
}

.word-token.error {
  animation: shake .28s ease;
}

body[data-font="propisi"] .word-token {
  font-family: var(--propisi-font);
  font-size: clamp(34px, 3.85vw, 48px);
  font-weight: 400;
}

body[data-font="cormorant"] .word-token,
body[data-font="cormorant"] h1 {
  font-family: var(--title-font);
}

body[data-font="sassoon"] .word-token {
  font-family: var(--english-font);
  font-size: clamp(24px, 2.8vw, 36px);
  font-weight: 400;
}

body[data-font="manrope"] .word-token {
  font-family: var(--ui-font);
}

body[data-case="upper"] .word-token {
  text-transform: uppercase;
}

body[data-case="lower"] .word-token {
  text-transform: lowercase;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  width: min(100%, 900px);
  margin: 0 auto;
}

.primary-button,
.secondary-button {
  min-height: 54px;
  border-radius: 12px;
  font-weight: 900;
  font-size: 18px;
}

.primary-button {
  color: #2e1709;
  background: linear-gradient(90deg, #ffd266, #d9860e);
  box-shadow: 0 18px 34px rgba(205, 126, 14, .22), inset 0 0 0 1px rgba(255, 255, 255, .3);
}

.secondary-button {
  color: #ffefd0;
  background: rgba(48, 25, 20, .78);
  border: 1px solid rgba(255, 204, 96, .28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05), 0 10px 20px rgba(0, 0, 0, .2);
}

.exit-button {
  display: grid;
  place-items: center;
  text-decoration: none;
  background: rgba(255, 255, 255, .08);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 7, 4, .72);
  backdrop-filter: blur(10px);
}

.modal.hidden {
  display: none;
}

.modal-card {
  position: relative;
  width: min(100%, 620px);
  padding: 34px;
  border: 1px solid rgba(255, 226, 170, .16);
  border-radius: 32px;
  background:
    radial-gradient(circle at top right, rgba(255, 198, 82, .12), transparent 32%),
    linear-gradient(180deg, rgba(45, 28, 17, .96), rgba(28, 17, 10, .96));
  color: #fff5e6;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .38);
}

.modal-card h2 {
  margin-bottom: 12px;
  font-family: var(--title-font);
  font-size: clamp(36px, 5vw, 58px);
}

.modal-card p {
  margin-bottom: 18px;
  color: rgba(255, 244, 224, .78);
  line-height: 1.55;
}

.close-button {
  position: absolute;
  right: 18px;
  top: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff3dc;
  background: rgba(255, 255, 255, .08);
  font-size: 28px;
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 226, 170, .18);
  border-radius: 18px;
  color: #fff8ef;
  background: rgba(255, 255, 255, .07);
  outline: none;
  line-height: 1.5;
}

.result-card {
  text-align: center;
}

.result-crystals {
  margin: 16px 0 22px;
}

.result-actions {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(126px, .62fr);
  gap: 12px;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

@media (min-width: 681px) {
  .game-shell {
    height: 100vh;
    padding: 16px 24px 18px;
  }

  .progress-row {
    top: 70px;
  }

  .crystal {
    width: clamp(24px, 2.3vw, 34px);
    height: clamp(44px, 4vw, 62px);
  }

  .book-area {
    min-height: calc(100vh - 66px);
    margin-top: 0;
  }

  .parchment {
    min-height: calc(100vh - 78px);
    padding: 82px clamp(28px, 4vw, 58px) 14px;
    display: flex;
    flex-direction: column;
  }

  .task-copy {
    margin: 0 auto 14px;
  }

  h1 {
    font-size: clamp(28px, 2.7vw, 40px);
  }

  .answer-zone {
    gap: clamp(8px, 1vw, 14px);
    min-height: 64px;
    margin: 0 auto 16px;
    padding: 4px min(2vw, 26px);
  }

  .sentence-slot {
    min-width: clamp(92px, 9vw, 124px);
    min-height: 54px;
    padding: 6px 12px;
  }

  .word-bank {
    gap: clamp(8px, 1vw, 12px);
    min-height: 74px;
    margin-bottom: 14px;
    padding-inline: clamp(24px, 5vw, 80px);
  }

  .word-token {
    min-width: 84px;
    min-height: 54px;
    padding: 0 26px;
  }

  .word-token.answer {
    min-width: 82px;
    min-height: 48px;
    padding-inline: 18px;
  }

  body[data-font="propisi"] .word-token {
    font-size: clamp(31px, 3.35vw, 41px);
  }

  body[data-font="sassoon"] .word-token {
    font-size: clamp(23px, 2.4vw, 32px);
  }

  .actions {
    gap: 12px;
    width: min(100%, 820px);
    margin-top: auto;
  }

  .primary-button,
  .secondary-button {
    min-height: 46px;
    font-size: 16px;
    border-radius: 11px;
  }
}

@media (max-width: 680px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .game-shell {
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    padding: 10px 8px 0;
  }

  .topbar {
    min-height: 62px;
    gap: 8px;
  }

  .back-button,
  .icon-button {
    width: 46px;
    height: 46px;
    border-radius: 14px;
  }

  .brand {
    gap: 6px;
    font-size: 24px;
  }

  .brand img {
    width: 58px;
  }

  .segmented {
    padding: 4px;
    border-radius: 16px;
  }

  .segmented button {
    min-width: 40px;
    height: 38px;
    border-radius: 12px;
    font-size: 13px;
  }

  .top-actions {
    gap: 6px;
  }

  .level-toggle {
    height: 38px;
    padding: 0 10px;
    border-radius: 12px;
    font-size: 11px;
  }

  .level-menu {
    min-width: 168px;
  }

  .progress-row {
    top: 76px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    min-height: 0;
    padding: 0;
    gap: 6px;
  }

  .crystal {
    width: 28px;
    height: 54px;
  }

  .owl {
    display: none;
  }

  .parchment {
    width: 100%;
    min-height: calc(100dvh - 78px);
    padding: 18px 10px 10px;
  }

  .font-toggle button {
    min-width: 42px;
  }

  .task-copy {
    margin: 2px auto 12px;
  }

  .kicker {
    font-size: 10px;
  }

  h1 {
    font-size: 28px;
  }

  .answer-zone {
    min-height: 104px;
    gap: 8px;
    margin-bottom: 18px;
    padding: 6px 2px;
  }

  .sentence-slot {
    min-width: clamp(76px, 25vw, 104px);
    min-height: 50px;
    padding: 6px 9px;
  }

  .word-bank {
    gap: 8px;
    min-height: 92px;
    margin-bottom: 12px;
    padding-inline: 4px;
  }

  .word-token {
    min-width: 72px;
    min-height: 48px;
    padding: 0 16px;
    border-radius: 13px;
    font-size: 17px;
  }

  .word-token.answer {
    min-width: 68px;
    min-height: 44px;
    padding-inline: 12px;
    font-size: 16px;
  }

  body[data-font="propisi"] .word-token {
    font-size: 30px;
  }

  body[data-font="sassoon"] .word-token {
    font-size: 23px;
  }

  .actions {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 18px 74px;
  }

  .primary-button,
  .secondary-button {
    min-height: 48px;
    border-radius: 16px;
    font-size: 17px;
  }

  .modal-card {
    max-height: calc(100dvh - 28px);
    overflow: auto;
    padding: 28px 20px;
    border-radius: 24px;
  }

  .result-actions {
    grid-template-columns: 1fr;
  }
}
