:root {
  color-scheme: light;
  --bg: #f5fbf9;
  --surface: #ffffff;
  --surface-strong: #e8f7f3;
  --text: #17211f;
  --muted: #5d6e69;
  --line: #cfe2dd;
  --teal: #0f9b8e;
  --teal-dark: #087a70;
  --coral: #e65157;
  --yellow: #f5c542;
  --green: #36b36a;
  --ink: #263532;
  --shadow: 0 14px 36px rgba(14, 88, 79, 0.13);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(15, 155, 142, 0.12), rgba(245, 251, 249, 0.2) 290px),
    var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand__icon {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  filter: drop-shadow(0 8px 16px rgba(15, 155, 142, 0.22));
}

.eyebrow,
.welcome,
.gesture-help,
.scoreline__label,
.note span {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 0.82rem;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.08;
}

h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.15;
}

.game-screen {
  display: grid;
  gap: 16px;
}

.briefing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 14px;
}

.briefing__copy,
.scoreline,
.board-zone,
.finish-panel {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.briefing__copy {
  min-width: 0;
  padding: 18px;
}

.briefing__media {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.briefing__media img {
  width: 42px;
  height: 42px;
  padding: 8px;
  border-radius: 8px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.welcome {
  margin: 0 0 8px;
}

#levelDescription {
  max-width: 62ch;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.scoreline {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  align-content: center;
  min-width: 330px;
  padding: 14px;
  gap: 10px;
}

.scoreline > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.scoreline strong {
  font-size: 1.35rem;
}

.scoreline__label {
  font-size: 0.78rem;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(280px, 680px) minmax(240px, 1fr);
  align-items: start;
  gap: 16px;
}

.board-zone {
  padding: 14px;
}

.board-toolbar,
.level-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.board-toolbar {
  margin-bottom: 12px;
}

.letter-board {
  --grid-size: 8;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  width: min(100%, 650px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 8px;
  border-radius: 8px;
  border: 2px solid var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 155, 142, 0.16), rgba(245, 197, 66, 0.18)),
    var(--surface);
  touch-action: none;
  user-select: none;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  margin: 3px;
  border: 1px solid #b8d4ce;
  border-radius: 6px;
  background: #fbfffe;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.cell:focus-visible,
.tool-button:focus-visible,
.ghost-button:focus-visible,
.primary-button:focus-visible,
.meta-tab:focus-visible,
.level-tab:focus-visible,
.word-chip:focus-visible,
.upgrade-button:focus-visible {
  outline: 3px solid rgba(230, 81, 87, 0.35);
  outline-offset: 2px;
}

.cell.is-selected {
  background: var(--yellow);
  border-color: #bd8e11;
  transform: scale(0.96);
}

.cell.is-found {
  background: var(--teal);
  border-color: var(--teal-dark);
  color: #ffffff;
}

.cell.is-hint {
  background: #ffe7e9;
  border-color: var(--coral);
  color: #8d2329;
}

.cell.is-wrong {
  background: #f8d8da;
  border-color: var(--coral);
  color: #8d2329;
  animation: shake 260ms linear;
}

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

.gesture-help {
  min-height: 1.4em;
  margin: 12px 2px 0;
  line-height: 1.4;
}

.side-panel {
  display: grid;
  gap: 14px;
}

.meta-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.meta-tab {
  min-height: 44px;
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
  white-space: normal;
}

.meta-tab.is-active {
  border-color: var(--teal);
  background: #e8f7f3;
  color: var(--teal-dark);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.meta-panel[hidden] {
  display: none;
}

.pet-card,
.levels-panel,
.clinic-card,
.achievements-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.levels-panel .panel-heading span {
  font-weight: 800;
}

.pet-card__top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.pet-visual {
  position: relative;
  width: 76px;
  height: 76px;
}

.pet-card__avatar {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  transition: transform 220ms ease, filter 220ms ease, border-color 220ms ease;
}

.pet-accessory {
  position: absolute;
  right: -4px;
  bottom: -4px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid #ffffff;
  border-radius: 8px;
  background: var(--coral);
  color: #ffffff;
  font-weight: 900;
  box-shadow: 0 8px 16px rgba(23, 33, 31, 0.16);
}

.pet-card[data-stage="assistant"] .pet-card__avatar {
  border-color: var(--teal);
  filter: saturate(1.12);
}

.pet-card[data-stage="clinician"] .pet-card__avatar {
  border-color: var(--yellow);
  filter: saturate(1.2) drop-shadow(0 10px 14px rgba(245, 197, 66, 0.28));
}

.pet-card[data-stage="legend"] .pet-card__avatar {
  border-color: var(--coral);
  filter: saturate(1.3) drop-shadow(0 12px 18px rgba(230, 81, 87, 0.28));
}

.pet-card[data-stage="legend"] .pet-accessory {
  background: var(--yellow);
  color: var(--ink);
}

.pet-stage {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.3;
}

.pet-meter {
  display: grid;
  gap: 6px;
}

.pet-meter__row,
.currency-line,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pet-meter__row span,
.currency-line span,
.panel-heading span {
  color: var(--muted);
}

.pet-meter__track {
  height: 10px;
  overflow: hidden;
  border: 1px solid #b8d4ce;
  border-radius: 999px;
  background: #eef8f5;
}

.pet-meter__track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--yellow));
  transition: width 220ms ease;
}

.pet-evolution {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.pet-evolution__step {
  min-height: 44px;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fcfb;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.pet-evolution__step.is-active {
  border-color: var(--teal);
  background: #e8f7f3;
  color: var(--teal-dark);
  font-weight: 800;
}

.currency-line {
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.currency-line strong::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 3px;
  background: var(--yellow);
  border: 1px solid #bd8e11;
  transform: rotate(45deg);
}

.currency-line--coins {
  background: #fff7df;
}

.currency-line--coins strong::before {
  border-radius: 50%;
  background: #f5c542;
  transform: none;
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.upgrade-button {
  display: grid;
  gap: 4px;
  min-height: 66px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.upgrade-button span {
  color: var(--muted);
  font-size: 0.78rem;
}

.upgrade-button strong {
  font-size: 1.1rem;
}

.upgrade-button small {
  color: var(--teal-dark);
  font-size: 0.72rem;
}

.upgrade-button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.clinic-card {
  gap: 13px;
}

.clinic-status {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.clinic-status img {
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.clinic-reputation {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.clinic-equipment {
  display: grid;
  gap: 8px;
}

.equipment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 70px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.equipment-item__copy {
  display: grid;
  gap: 4px;
}

.equipment-item__copy strong {
  line-height: 1.2;
}

.equipment-item__copy span {
  color: var(--muted);
  line-height: 1.3;
  font-size: 0.84rem;
}

.equipment-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.equipment-pill {
  padding: 2px 6px;
  border-radius: 999px;
  background: #e8f7f3;
  color: var(--teal-dark);
  font-size: 0.72rem;
  font-weight: 800;
}

.equipment-button {
  min-width: 92px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--teal);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

.equipment-button:disabled {
  cursor: not-allowed;
  background: #ecf2f1;
  color: var(--muted);
}

.level-tabs {
  align-items: stretch;
}

.level-tab,
.word-chip,
.tool-button,
.ghost-button,
.primary-button {
  border-radius: 8px;
  border: 1px solid var(--line);
}

.level-tab {
  display: grid;
  min-height: 58px;
  min-width: 138px;
  flex: 1 1 138px;
  padding: 10px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.level-tab.is-active {
  border-color: var(--teal);
  background: #e9faf6;
  box-shadow: inset 0 0 0 1px var(--teal);
}

.level-tab.is-complete::after {
  content: "пройден";
  justify-self: start;
  margin-top: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e7f7ec;
  color: #166d3b;
  font-size: 0.72rem;
}

.word-bank {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
}

.word-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}

.word-chip::after {
  content: "";
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--line);
}

.word-chip.is-found {
  color: #126142;
  background: #e8f7ec;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.word-chip.is-found::after {
  background: var(--green);
}

.panel-heading h2 {
  margin: 0;
}

.achievements-grid {
  display: grid;
  gap: 8px;
}

.achievement {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  min-height: 58px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fcfb;
}

.achievement__badge {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #ecf2f1;
  color: var(--muted);
  font-weight: 800;
}

.achievement strong {
  display: block;
  margin-bottom: 2px;
}

.achievement span {
  color: var(--muted);
  line-height: 1.3;
  font-size: 0.86rem;
}

.achievement.is-unlocked {
  border-color: #86d5a7;
  background: #e8f7ec;
}

.achievement.is-unlocked .achievement__badge {
  background: var(--green);
  color: #ffffff;
}

.tool-button,
.ghost-button,
.primary-button {
  min-height: 42px;
  padding: 10px 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

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

.tool-button img {
  width: 20px;
  height: 20px;
}

.tool-button:hover,
.ghost-button:hover,
.meta-tab:hover,
.level-tab:hover,
.word-chip:hover,
.upgrade-button:hover,
.equipment-button:hover {
  border-color: var(--teal);
}

.tool-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.primary-button {
  background: var(--teal);
  color: #ffffff;
  border-color: var(--teal-dark);
  font-weight: 800;
}

.ghost-button {
  flex: 0 0 auto;
}

.note {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-left: 5px solid var(--coral);
  background: rgba(255, 255, 255, 0.72);
}

.finish-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
}

.finish-panel[hidden] {
  display: none;
}

.finish-panel img {
  width: 44px;
  height: 44px;
}

.finish-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

@media (max-width: 900px) {
  .briefing,
  .play-area,
  .finish-panel {
    grid-template-columns: 1fr;
  }

  .scoreline {
    min-width: 0;
  }

  .finish-panel {
    justify-items: stretch;
  }

  .pet-card__top {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .clinic-status {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .clinic-status img {
    width: 64px;
    height: 64px;
  }

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

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

  .topbar {
    align-items: flex-start;
  }

  .brand__icon {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 1.25rem;
  }

  h2 {
    font-size: 1.18rem;
  }

  .briefing__copy,
  .scoreline,
  .board-zone {
    padding: 12px;
  }

  .scoreline {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scoreline strong {
    font-size: 1.05rem;
  }

  .letter-board {
    padding: 5px;
  }

  .cell {
    margin: 2px;
    font-size: 0.92rem;
  }

  .ghost-button,
  .tool-button,
  .primary-button {
    min-height: 40px;
    padding: 8px 10px;
  }

  .pet-card,
  .levels-panel,
  .clinic-card,
  .achievements-panel {
    padding: 12px;
  }

  .pet-visual,
  .pet-card__avatar {
    width: 64px;
    height: 64px;
  }

  .upgrade-grid {
    grid-template-columns: 1fr;
  }

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

  .equipment-item {
    grid-template-columns: 1fr;
  }

  .equipment-button {
    width: 100%;
  }
}
