:root {
  color: #2b1b12;
  background: #1b3b24;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
}

button,
select,
input {
  font: inherit;
}

button {
  align-items: center;
  background: #f2c15c;
  border: 2px solid #3a2114;
  border-radius: 0;
  box-shadow:
    inset -3px -3px 0 #a35b22,
    inset 3px 3px 0 #fff0a8,
    0 3px 0 #15100d;
  color: #2b1b12;
  cursor: pointer;
  display: inline-flex;
  font-size: clamp(0.64rem, 0.78vw, 0.84rem);
  font-weight: 900;
  gap: 0.35rem;
  justify-content: center;
  line-height: 1.05;
  min-height: 2.05rem;
  padding: 0.34rem 0.38rem;
  text-align: center;
  text-transform: uppercase;
  white-space: normal;
  word-break: normal;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  box-shadow:
    inset -3px -3px 0 #b66f1c,
    inset 3px 3px 0 #fff5a5,
    0 1px 0 #1b1025;
  transform: translateY(3px);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.8);
  opacity: 0.55;
}

button svg {
  height: 1rem;
  width: 1rem;
}

.app-shell {
  background:
    linear-gradient(45deg, rgba(255, 232, 145, 0.08) 25%, transparent 25%) 0 0 / 32px 32px,
    linear-gradient(-45deg, rgba(255, 232, 145, 0.06) 25%, transparent 25%) 0 0 / 32px 32px,
    linear-gradient(#275b31, #17391f);
  display: grid;
  gap: clamp(0.32rem, 0.7vh, 0.55rem);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  margin: 0 auto;
  max-width: 1600px;
  overflow: hidden;
  padding: clamp(0.32rem, 0.8vw, 0.6rem);
}

.top-hud {
  align-items: stretch;
  display: grid;
  gap: 0.45rem;
  grid-template-columns: minmax(20rem, 1fr) minmax(28rem, 0.82fr);
  min-height: 0;
}

.title-lockup,
.panel,
.arena-panel {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0 12%, transparent 12%),
    #d9b56d;
  border: 3px solid #f8e6a0;
  box-shadow:
    inset -4px -4px 0 rgba(0, 0, 0, 0.35),
    inset 4px 4px 0 rgba(255, 255, 255, 0.08),
    0 0 0 3px #2f2115,
    0 5px 0 rgba(0, 0, 0, 0.24);
}

.title-lockup {
  align-content: center;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16) 0 18%, transparent 18%),
    #2f6d3b;
  display: grid;
  gap: 0.4rem;
  grid-template-columns: minmax(0, 1fr) auto;
  justify-content: space-between;
  min-width: 0;
  padding: 0.38rem 0.55rem;
}

.title-lockup > div {
  min-width: 0;
}

.guide-button {
  align-self: center;
  min-height: 1.9rem;
  min-width: 4.8rem;
}

.lesson-tag {
  color: #f8e6a0;
  font-size: clamp(0.56rem, 0.68vw, 0.7rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: #f9e27d;
  font-size: clamp(1.05rem, 2vw, 1.8rem);
  letter-spacing: 0;
  line-height: 0.98;
  text-shadow:
    3px 3px 0 #5b271a,
    0 0 0 #2b1b12;
  overflow-wrap: anywhere;
}

h2 {
  color: #144f32;
  font-size: clamp(0.78rem, 0.95vw, 0.98rem);
  line-height: 1;
  text-transform: uppercase;
}

h3 {
  color: #7c341e;
  font-size: clamp(0.7rem, 0.82vw, 0.84rem);
  line-height: 1;
  text-transform: uppercase;
}

p,
li,
span,
td,
th {
  font-size: clamp(0.6rem, 0.72vw, 0.78rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.score-panel {
  display: grid;
  gap: 0.32rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.score-card {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.13) 0 22%, transparent 22%),
    #356b8f;
  border: 3px solid #f8e6a0;
  box-shadow:
    inset -3px -3px 0 rgba(0, 0, 0, 0.28),
    inset 3px 3px 0 rgba(255, 255, 255, 0.12),
    0 0 0 2px #2f2115;
  display: grid;
  min-width: 0;
  padding: 0.32rem;
}

.score-card span {
  color: #f9e27d;
  font-size: clamp(0.52rem, 0.62vw, 0.66rem);
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.score-card strong {
  color: #ffffff;
  font-size: clamp(1rem, 1.55vw, 1.55rem);
  line-height: 1;
  text-shadow: 2px 2px 0 #173247;
}

.game-frame {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: minmax(12rem, 0.62fr) minmax(27rem, 1.55fr) minmax(15.5rem, 0.72fr);
  min-height: 0;
}

.panel,
.arena-panel {
  min-height: 0;
  overflow: hidden;
  padding: 0.45rem;
}

.intel-panel,
.command-panel {
  display: grid;
  gap: 0.35rem;
}

.intel-panel {
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}

.command-panel {
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
}

.mission-copy {
  color: #2b1b12;
  font-weight: 800;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.vocab-grid {
  display: grid;
  gap: 0.25rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.vocab-chip {
  background: #f4df9e;
  border: 2px solid #80512a;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.24);
  display: grid;
  min-width: 0;
  padding: 0.26rem;
}

.vocab-chip strong {
  color: #126244;
  font-size: clamp(0.54rem, 0.64vw, 0.68rem);
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.vocab-chip span {
  color: #2b1b12;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-card {
  display: grid;
  gap: 0.3rem;
  min-height: 0;
}

.message-card > div,
.mini-panel {
  background:
    linear-gradient(90deg, rgba(128, 81, 42, 0.12) 1px, transparent 1px),
    #f4df9e;
  background-size: 10px 10px;
  border: 2px solid #80512a;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.3);
}

.message-card > div {
  min-height: 0;
  padding: 0.34rem;
}

.message-card h3 {
  align-items: center;
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.2rem;
}

.message-card svg {
  height: 1rem;
  width: 1rem;
}

.message-card p {
  color: #2b1b12;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.reward-panel {
  display: grid;
  gap: 0.28rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.reward-card {
  border: 2px solid #80512a;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.25);
  display: grid;
  gap: 0.2rem;
  min-width: 0;
  padding: 0.34rem;
}

.reward-card.good {
  background: #dff0a1;
}

.reward-card.bad {
  background: #f0b2a1;
}

.reward-card strong {
  color: #144f32;
  font-size: clamp(0.62rem, 0.78vw, 0.82rem);
  text-transform: uppercase;
}

.reward-card.bad strong {
  color: #7c341e;
}

.reward-card span {
  color: #2b1b12;
  display: -webkit-box;
  font-weight: 800;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.arena-panel {
  display: grid;
  gap: 0.35rem;
  grid-template-rows: auto minmax(0, 1fr);
}

.arena-topline {
  align-items: center;
  display: flex;
  gap: 0.4rem;
  justify-content: space-between;
  min-width: 0;
}

.arena-topline > div {
  min-width: 0;
}

.arena-topline p {
  color: #2b1b12;
  font-weight: 800;
  margin-top: 0.12rem;
}

.challenge-pill {
  background: #c8343e;
  border: 2px solid #f8e6a0;
  box-shadow: 0 2px 0 #2f2115;
  color: #ffffff;
  flex: 0 0 auto;
  font-size: clamp(0.56rem, 0.7vw, 0.74rem);
  font-weight: 900;
  padding: 0.26rem 0.38rem;
  text-transform: uppercase;
}

.challenge-pill.solved {
  background: #2f8e41;
}

.grid-shell {
  align-items: center;
  background:
    linear-gradient(45deg, rgba(255, 232, 145, 0.15) 25%, transparent 25%) 0 0 / 24px 24px,
    #6c9a4b;
  border: 3px solid #80512a;
  box-shadow:
    inset -4px -4px 0 rgba(0, 0, 0, 0.32),
    inset 4px 4px 0 rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: min(1vh, 0.45rem);
}

.grid {
  aspect-ratio: 1 / 1;
  display: grid;
  gap: min(0.55vh, 0.32rem);
  grid-template-columns: repeat(6, minmax(0, 1fr));
  max-height: 100%;
  max-width: 100%;
  width: min(100%, calc(100vh - 8.6rem));
}

.cell {
  align-items: center;
  background:
    radial-gradient(circle at 22% 26%, rgba(249, 226, 125, 0.18) 0 12%, transparent 13%),
    radial-gradient(circle at 76% 72%, rgba(20, 79, 50, 0.22) 0 13%, transparent 14%),
    #5fa942;
  border: 2px solid #2e6d32;
  box-shadow:
    inset -5px -5px 0 rgba(0, 0, 0, 0.22),
    inset 4px 4px 0 rgba(255, 255, 255, 0.16);
  color: #ffffff;
  display: flex;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.cell.visited {
  background:
    radial-gradient(circle at 50% 50%, rgba(248, 230, 160, 0.34) 0 18%, transparent 19%),
    #8ac45f;
}

.cell.start {
  background:
    linear-gradient(45deg, #9a9a82 25%, #b9b89f 25% 50%, #9a9a82 50% 75%, #c9c7ae 75%) 0 0 / 18px 18px;
  border-color: #f8e6a0;
}

.cell.goal {
  background:
    radial-gradient(circle at 50% 42%, #eaffff 0 10%, #66d4c8 11% 24%, transparent 25%),
    radial-gradient(circle at 50% 50%, rgba(249, 226, 125, 0.55) 0 34%, transparent 35%),
    #3c8f57;
  border-color: #f8e6a0;
}

.cell.trap {
  background:
    radial-gradient(circle at 50% 54%, #17100e 0 35%, #4d2b24 36% 48%, transparent 49%),
    #9b3d32;
  border-color: #f8e6a0;
}

.cell.robot-cell {
  outline: 3px solid #ffd84f;
  outline-offset: -5px;
  z-index: 1;
}

.cell-label,
.trap-label,
.goal-icon,
.trail {
  font-size: clamp(0.48rem, 0.85vw, 0.82rem);
  font-weight: 900;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

.goal-icon {
  align-items: center;
  color: #ffffff;
  display: inline-flex;
  flex-direction: column;
  gap: 0.12rem;
}

.goal-icon svg {
  height: 1rem;
  width: 1rem;
}

.trail {
  align-items: center;
  background: #f9e27d;
  border: 2px solid #80512a;
  color: #2b1b12;
  display: flex;
  height: clamp(0.85rem, 1.6vw, 1.1rem);
  justify-content: center;
  position: absolute;
  right: 0.2rem;
  top: 0.2rem;
  width: clamp(0.85rem, 1.6vw, 1.1rem);
}

.child-stack {
  align-content: center;
  display: grid;
  gap: 0.1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  inset: 0.12rem;
  justify-content: center;
  position: absolute;
  z-index: 3;
}

.child-token {
  align-items: center;
  background: #356b8f;
  border: 1px solid #f8e6a0;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  color: #ffffff;
  display: flex;
  font-size: clamp(0.42rem, 0.68vw, 0.66rem);
  font-weight: 900;
  justify-content: center;
  min-height: 0.88rem;
  min-width: 0;
  text-shadow: 1px 1px 0 #173247;
}

.child-token.best {
  background: #f9e27d;
  border-color: #2f2115;
  color: #2b1b12;
  outline: 2px solid #ffffff;
  text-shadow: none;
}

.robot {
  align-items: center;
  animation: robot-bob 900ms steps(2, end) infinite;
  background: #3b8b4c;
  border: 4px solid #f8e6a0;
  box-shadow:
    inset -5px -5px 0 #16502a,
    inset 4px 4px 0 #7ed26d,
    0 0 0 4px rgba(255, 255, 255, 0.18);
  color: #f8e6a0;
  display: flex;
  height: clamp(2.1rem, 6.2vw, 4.2rem);
  justify-content: center;
  position: relative;
  width: clamp(2.1rem, 6.2vw, 4.2rem);
  z-index: 2;
}

.robot::before {
  background: #c8343e;
  border: 2px solid #f8e6a0;
  box-shadow: inset -2px -2px 0 #7c1d25;
  content: "";
  height: 26%;
  left: 19%;
  position: absolute;
  top: -12%;
  transform: skewX(-18deg);
  width: 52%;
}

.robot::after {
  background: #356b8f;
  border: 2px solid #f8e6a0;
  box-shadow: inset -2px -2px 0 #173247;
  content: "";
  height: 34%;
  position: absolute;
  right: -18%;
  top: 44%;
  width: 28%;
}

.robot svg {
  height: 66%;
  width: 66%;
  z-index: 1;
}

@keyframes robot-bob {
  50% {
    transform: translateY(-3px);
  }
}

.controls {
  display: grid;
  gap: 0.25rem;
}

.training-actions {
  display: grid;
  gap: 0.25rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.training-actions button {
  min-height: 2.1rem;
}

.training-actions button:nth-child(2) {
  background: #c8343e;
  box-shadow:
    inset -4px -4px 0 #7c1d25,
    inset 4px 4px 0 #ff858c,
    0 4px 0 #15100d;
  color: #ffffff;
}

.mini-panel {
  display: grid;
  gap: 0.28rem;
  min-height: 0;
  padding: 0.34rem;
}

.mutation-panel p,
.history-panel p,
.settings-panel p,
.playback-panel p {
  color: #2b1b12;
}

.settings-grid {
  display: grid;
  gap: 0.22rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-grid label {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.settings-grid span {
  color: #144f32;
  font-size: clamp(0.5rem, 0.58vw, 0.62rem);
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.settings-grid input {
  background: #fff4c6;
  border: 2px solid #80512a;
  color: #2b1b12;
  font-size: clamp(0.62rem, 0.72vw, 0.78rem);
  font-weight: 900;
  min-height: 1.45rem;
  min-width: 0;
  padding: 0.1rem 0.18rem;
  width: 100%;
}

.playback-panel p {
  display: -webkit-box;
  font-weight: 800;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.playback-actions {
  display: grid;
  gap: 0.22rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.playback-actions button {
  min-height: 1.8rem;
  padding: 0.2rem;
}

.gene-row {
  display: grid;
  gap: 0.22rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gene {
  background: #fff4c6;
  border: 2px solid #80512a;
  color: #144f32;
  display: block;
  font-size: clamp(0.52rem, 0.62vw, 0.68rem);
  font-weight: 900;
  min-width: 0;
  overflow: hidden;
  padding: 0.22rem;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.mutation-note {
  background: #dff0a1;
  border: 2px solid #80512a;
  color: #2b1b12;
  display: -webkit-box;
  font-size: clamp(0.56rem, 0.68vw, 0.72rem);
  font-weight: 900;
  min-width: 0;
  overflow: hidden;
  padding: 0.25rem;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.history-panel {
  overflow: hidden;
}

table {
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
}

th,
td {
  border-bottom: 2px solid rgba(128, 81, 42, 0.32);
  color: #2b1b12;
  padding: 0.16rem 0.12rem;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th:nth-child(1),
td:nth-child(1) {
  width: 17%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 20%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 28%;
}

th {
  color: #7c341e;
  font-size: clamp(0.5rem, 0.58vw, 0.62rem);
  text-transform: uppercase;
}

td {
  font-weight: 800;
}

.change {
  background: #356b8f;
  border: 1px solid #f8e6a0;
  color: #ffffff;
  display: inline-block;
  font-size: clamp(0.46rem, 0.56vw, 0.6rem);
  font-weight: 900;
  padding: 0.08rem 0.16rem;
  text-transform: uppercase;
}

.change.up {
  background: #2f8e41;
}

.change.down {
  background: #c8343e;
}

.walkthrough {
  align-items: center;
  background: rgba(16, 31, 18, 0.66);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 1rem;
  position: fixed;
  z-index: 20;
}

.walkthrough-card {
  background:
    linear-gradient(90deg, rgba(128, 81, 42, 0.12) 1px, transparent 1px),
    #f4df9e;
  background-size: 10px 10px;
  border: 5px solid #f8e6a0;
  box-shadow:
    inset -7px -7px 0 rgba(0, 0, 0, 0.28),
    inset 6px 6px 0 rgba(255, 255, 255, 0.22),
    0 0 0 5px #2f2115,
    0 16px 0 rgba(0, 0, 0, 0.28);
  color: #2b1b12;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: auto minmax(0, 1fr);
  max-width: min(42rem, calc(100vw - 2rem));
  min-width: 0;
  padding: clamp(0.8rem, 2vw, 1.2rem);
}

.wizard-pixel {
  align-items: center;
  background: #3b8b4c;
  border: 4px solid #f8e6a0;
  box-shadow:
    inset -5px -5px 0 #16502a,
    inset 4px 4px 0 #7ed26d,
    0 0 0 4px #80512a;
  color: #f8e6a0;
  display: flex;
  grid-row: 1 / 4;
  height: clamp(4rem, 10vw, 5.6rem);
  justify-content: center;
  width: clamp(4rem, 10vw, 5.6rem);
}

.wizard-pixel svg {
  height: 68%;
  width: 68%;
}

.walkthrough-copy {
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

.wizard-kicker {
  color: #126244;
  font-size: clamp(0.65rem, 0.85vw, 0.82rem);
  font-weight: 900;
  text-transform: uppercase;
}

.walkthrough-copy h2 {
  color: #7c341e;
  font-size: clamp(1.1rem, 2vw, 1.8rem);
  overflow-wrap: anywhere;
}

.walkthrough-copy p {
  font-size: clamp(0.9rem, 1.2vw, 1.08rem);
  font-weight: 800;
}

.walkthrough-copy strong {
  background: #fff4c6;
  border: 3px solid #80512a;
  color: #144f32;
  display: block;
  font-size: clamp(0.78rem, 1vw, 0.95rem);
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 0.45rem;
}

.wizard-dots {
  display: flex;
  gap: 0.35rem;
}

.wizard-dots span {
  background: #80512a;
  border: 2px solid #3a2114;
  display: block;
  height: 0.85rem;
  width: 0.85rem;
}

.wizard-dots .active {
  background: #2f8e41;
}

.walkthrough-actions {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 1180px) {
  .game-frame {
    grid-template-columns: minmax(11rem, 0.7fr) minmax(22rem, 1.45fr) minmax(15rem, 0.85fr);
  }
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .top-hud,
  .game-frame {
    grid-template-columns: 1fr;
  }

  .walkthrough-card {
    grid-template-columns: 1fr;
  }

  .wizard-pixel {
    grid-row: auto;
  }
}

@media (max-height: 760px) and (min-width: 921px) {
  .app-shell {
    gap: 0.28rem;
    padding: 0.28rem;
  }

  .panel,
  .arena-panel {
    padding: 0.32rem;
  }

  .message-card > div,
  .mini-panel {
    padding: 0.26rem;
  }

  .controls,
  .command-panel,
  .intel-panel {
    gap: 0.24rem;
  }

  button {
    min-height: 1.78rem;
    padding: 0.22rem 0.28rem;
  }

  .vocab-grid,
  .gene-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .message-card p {
    -webkit-line-clamp: 1;
  }

  .reward-card span,
  .mission-copy,
  .mutation-panel p {
    -webkit-line-clamp: 1;
  }

  .grid {
    width: min(100%, calc(100vh - 7.4rem));
  }

  .score-card {
    padding: 0.24rem;
  }

  .score-card strong {
    font-size: clamp(0.92rem, 1.35vw, 1.25rem);
  }

  .training-actions button,
  .playback-actions button {
    min-height: 1.7rem;
  }

  .settings-grid input {
    min-height: 1.25rem;
  }

}
