:root {
  --ink: #2c2118;
  --paper: #fff2cf;
  --paper-dark: #ebc77e;
  --wood: #9b6236;
  --wood-dark: #5d3926;
  --soil: #70452e;
  --soil-dark: #4b2f22;
  --leaf: #2f8a4c;
  --leaf-dark: #1d5c3a;
  --sky: #8fd0e9;
  --water: #4f8fc9;
  --tomato: #c44e3d;
  --gold: #e9b44c;
  --cream: #fff8dd;
  --shadow: rgba(44, 33, 24, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--sky);
  font-family: "Trebuchet MS", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.farm-page {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(to bottom, #86cbea 0 44%, #8fbe67 44% 62%, #6aa34e 62% 100%);
}

.farm-page::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 31vh;
  background:
    radial-gradient(circle at 2px 2px, rgba(255, 236, 173, 0.28) 0 1px, transparent 1.5px) 0 0 / 12px 12px,
    radial-gradient(circle at 7px 8px, rgba(75, 51, 34, 0.24) 0 1px, transparent 1.5px) 0 0 / 18px 18px,
    linear-gradient(90deg, rgba(58, 35, 24, 0.1) 1px, transparent 1px) 0 0 / 8px 8px,
    linear-gradient(rgba(58, 35, 24, 0.08) 1px, transparent 1px) 0 0 / 8px 8px,
    linear-gradient(180deg, #8d5a39 0, #76492f 100%);
  image-rendering: pixelated;
}

.farm-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 22%, rgba(62, 92, 54, 0.18) 0 1px, transparent 1.5px) 0 0 / 14px 14px,
    radial-gradient(circle at 68% 18%, rgba(255, 240, 180, 0.18) 0 1px, transparent 1.5px) 0 0 / 20px 20px;
  image-rendering: pixelated;
  opacity: 0.8;
}

.sky-band {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sun {
  position: absolute;
  top: 58px;
  right: 28px;
  width: 48px;
  height: 48px;
  background: #ffd76d;
  box-shadow:
    0 0 0 5px rgba(255, 215, 109, 0.18),
    0 0 0 10px rgba(255, 215, 109, 0.08);
  opacity: 0.78;
}

.cloud {
  position: absolute;
  width: 92px;
  height: 24px;
  background: #f7fff0;
  box-shadow:
    18px -12px 0 #f7fff0,
    45px -8px 0 #f7fff0,
    70px 0 0 #f7fff0;
}

.cloud-one {
  top: 96px;
  left: 8vw;
}

.cloud-two {
  top: 156px;
  right: 23vw;
  transform: scale(0.75);
}

.farm-shell {
  position: relative;
  z-index: 1;
  width: min(1160px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(250px, 330px) 1fr;
  grid-template-rows: auto auto;
  grid-template-areas:
    "brand mascot sky"
    "tabs mascot sky";
  align-items: center;
  column-gap: 28px;
  row-gap: 16px;
  min-height: 210px;
  margin-bottom: 18px;
}

.brand-block {
  display: flex;
  align-items: flex-end;
  min-width: 0;
  grid-area: brand;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(2.4rem, 5.2vw, 4.4rem);
  text-shadow: 3px 3px 0 rgba(255, 248, 221, 0.85);
}

h2 {
  font-size: 1.5rem;
}

.view-tabs {
  grid-area: tabs;
  display: flex;
  gap: 8px;
  padding: 6px;
  background: rgba(255, 248, 221, 0.78);
  border: 3px solid var(--wood-dark);
  box-shadow: 4px 4px 0 var(--shadow);
}

.mascot-stage {
  grid-area: mascot;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: min(100%, 330px);
  height: 210px;
  pointer-events: none;
}

.nav-characters {
  display: block;
  width: auto;
  height: min(100%, 210px);
  max-width: 100%;
  image-rendering: pixelated;
  object-fit: contain;
  filter: drop-shadow(3px 4px 0 rgba(45, 31, 22, 0.25));
}

.view-tabs button,
.primary-button,
.secondary-button,
.quiet-button {
  min-height: 42px;
  border: 3px solid var(--wood-dark);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.view-tabs button {
  padding: 0 14px;
  background: var(--paper);
}

.view-tabs button.active {
  background: var(--gold);
}

.primary-button {
  padding: 0 18px;
  background: var(--leaf);
  color: #fffbe8;
  font-weight: 800;
}

.secondary-button {
  padding: 0 16px;
  background: var(--paper);
  font-weight: 700;
}

.quiet-button {
  width: auto;
  padding: 0 10px;
  background: #d79a55;
  color: #fffbe8;
  font-size: 0.82rem;
  font-weight: 800;
}

.compact-reset {
  min-height: 30px;
  border-width: 2px;
  box-shadow: 2px 2px 0 var(--shadow);
}

.reset-zone {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.reset-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: #fff8dd;
  border: 2px solid var(--paper-dark);
  font-size: 0.82rem;
  font-weight: 900;
}

.mini-confirm {
  min-height: 26px;
  padding: 0 8px;
  border: 2px solid var(--wood-dark);
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
}

.mini-confirm.yes {
  background: #c44e3d;
  color: #fffbe8;
}

.primary-button:hover,
.secondary-button:hover,
.quiet-button:hover,
.view-tabs button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--shadow);
  filter: brightness(1.03);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
}

.farm-grid {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.farm-status,
.study-board,
.field-board,
.gate-panel,
.loading-panel {
  border: 4px solid var(--wood-dark);
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--shadow);
}

.farm-status {
  padding: 12px;
}

.mini-field {
  display: grid;
  grid-template-columns: repeat(6, 26px);
  justify-content: center;
  gap: 4px;
  padding: 8px;
  margin-bottom: 12px;
  background:
    linear-gradient(90deg, rgba(255, 214, 143, 0.1) 1px, transparent 1px) 0 0 / 12px 12px,
    linear-gradient(rgba(42, 24, 17, 0.3) 1px, transparent 1px) 0 0 / 12px 12px,
    var(--soil-dark);
  border: 3px solid var(--wood-dark);
  box-shadow: inset 0 0 0 3px rgba(255, 248, 221, 0.08);
}

.plot {
  aspect-ratio: 1;
  background:
    linear-gradient(135deg, rgba(255, 213, 143, 0.12) 0 20%, transparent 20% 100%),
    linear-gradient(180deg, #8b5738 0 45%, #6f432c 45% 100%);
  border: 1px solid #3a241b;
  position: relative;
  box-shadow:
    inset 2px 0 0 rgba(255, 219, 154, 0.12),
    inset -2px -2px 0 rgba(45, 25, 17, 0.22);
}

.plot.grown::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 6px;
  height: 13px;
  transform: translateX(-50%);
  background: var(--leaf);
  box-shadow:
    -5px 4px 0 var(--leaf-dark),
    5px 1px 0 #4cae62,
    0 -5px 0 #e0b84f;
}

.plot:nth-child(4n)::after,
.plot:nth-child(7n)::after {
  content: "";
  position: absolute;
  right: 4px;
  top: 5px;
  width: 3px;
  height: 3px;
  background: rgba(255, 225, 153, 0.38);
}

.stats-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 12px;
}

.stats-list div {
  padding: 8px;
  background: var(--cream);
  border: 2px solid var(--paper-dark);
}

.stats-list dt {
  font-size: 0.82rem;
  color: #68452b;
}

.stats-list dd {
  margin: 4px 0 0;
  font-size: 1.12rem;
  font-weight: 900;
}

.study-board {
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(93, 57, 38, 0.08) 1px, transparent 1px) 0 0 / 18px 18px,
    var(--paper);
}

.word-header,
.field-header,
.result-title,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  margin-right: 6px;
  background: #d9f0bc;
  border: 2px solid #6e8c45;
  font-size: 0.82rem;
  font-weight: 800;
}

.tag.muted {
  background: #ffe0a4;
  border-color: #b16b32;
}

.level-meter {
  display: flex;
  gap: 4px;
  padding: 5px;
  background: #fff8dd;
  border: 2px solid var(--paper-dark);
}

.level-meter span {
  width: 18px;
  height: 12px;
  background: #d8bf8a;
}

.level-meter span.filled {
  background: var(--leaf);
}

.memory-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}

.memory-strip span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  background: #fff8dd;
  border: 2px solid var(--paper-dark);
  color: #4f3725;
  font-size: 0.9rem;
  font-weight: 900;
}

.sentence-sign {
  position: relative;
  margin: 20px 0;
  padding: 30px;
  background:
    linear-gradient(90deg, rgba(255, 235, 174, 0.08) 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(#c07a45, #a96336);
  border: 4px solid var(--wood-dark);
  color: #fff8dd;
  box-shadow:
    inset 0 0 0 4px rgba(255, 248, 221, 0.14),
    4px 4px 0 rgba(65, 39, 25, 0.16);
}

.sentence-sign::before,
.sentence-sign::after {
  content: "";
  position: absolute;
  bottom: -34px;
  width: 16px;
  height: 34px;
  background: var(--wood-dark);
}

.sentence-sign::before {
  left: 36px;
}

.sentence-sign::after {
  right: 36px;
}

.sentence {
  margin: 0 0 18px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.5rem, 3.4vw, 2.65rem);
  line-height: 1.45;
}

.target-word {
  display: inline-block;
  padding: 0 4px;
  background: #ffe67e;
  color: #2d2218;
  font-weight: 900;
}

.word-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0;
  color: #ffedb0;
  font-weight: 900;
}

.word-line span {
  font-size: 1.25rem;
}

.word-line small {
  font-size: 0.95rem;
}

.answer-form {
  margin-top: 46px;
}

.answer-form label,
.login-form label {
  display: block;
  margin-bottom: 10px;
  font-size: 1.08rem;
  font-weight: 900;
}

textarea,
input {
  width: 100%;
  border: 3px solid var(--wood-dark);
  background: #fffdf1;
  color: var(--ink);
  outline: none;
  box-shadow: inset 3px 3px 0 rgba(93, 57, 38, 0.12);
}

textarea {
  min-height: 130px;
  resize: vertical;
  padding: 16px;
  line-height: 1.5;
  font-size: 1.08rem;
}

input {
  height: 48px;
  padding: 0 12px;
}

textarea:focus,
input:focus {
  border-color: var(--leaf-dark);
}

.action-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 12px;
}

.result-panel {
  margin-top: 20px;
  padding: 18px;
  border: 6px solid var(--wood-dark);
  background: #fff8dd;
  box-shadow:
    6px 6px 0 rgba(44, 33, 24, 0.18),
    inset 0 0 0 3px rgba(255, 255, 255, 0.42);
}

.result-panel.success {
  border-color: var(--leaf-dark);
  background: #edf9d8;
}

.result-panel.warning {
  border-color: #b16b32;
  background: #fff0c8;
}

.result-panel.danger {
  border-color: var(--tomato);
  background: #ffe2d7;
}

.result-title {
  justify-content: space-between;
  align-items: stretch;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 3px solid rgba(93, 57, 38, 0.16);
}

.result-copy {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.result-title strong {
  font-size: clamp(1.6rem, 3vw, 2.15rem);
  line-height: 1;
}

.result-title span {
  padding: 5px 10px;
  background: #e8d4a7;
  border: 2px solid #c49a5a;
  font-size: 0.88rem;
  font-weight: 900;
}

.result-badge {
  display: grid;
  place-items: center;
  width: 58px;
  min-width: 58px;
  height: 58px;
  border: 4px solid currentColor;
  background: #fffdf1;
  font-size: 2.7rem;
  line-height: 1;
  font-weight: 900;
  box-shadow: 3px 3px 0 rgba(44, 33, 24, 0.18);
}

.result-panel.success .result-badge,
.result-panel.success .result-title strong {
  color: var(--leaf-dark);
}

.result-panel.warning .result-badge,
.result-panel.warning .result-title strong {
  color: #9b5a20;
}

.result-panel.danger .result-badge,
.result-panel.danger .result-title strong {
  color: #a4372c;
}

.answer-reveal {
  margin-top: 14px;
  padding: 16px;
  background: #fffdf1;
  border: 3px solid var(--paper-dark);
  font-size: 1.05rem;
}

.answer-reveal p,
.result-panel p {
  margin: 10px 0;
  line-height: 1.72;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.next-button {
  margin-top: 10px;
}

.result-actions .next-button {
  margin-top: 0;
}

.danger-text {
  color: #8f2d24;
}

.field-board {
  padding: 18px;
}

.field-header {
  align-items: flex-end;
  margin-bottom: 14px;
}

.field-header p {
  margin: 0;
  color: #65462f;
}

.word-plots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(24px, 24px));
  justify-content: start;
  gap: 5px;
  padding: 12px;
  background:
    linear-gradient(90deg, rgba(255, 218, 145, 0.08) 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(rgba(42, 24, 17, 0.22) 1px, transparent 1px) 0 0 / 18px 18px,
    var(--soil-dark);
  border: 3px solid var(--wood-dark);
  max-width: 560px;
}

.word-plot {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid #3a241b;
  background:
    linear-gradient(135deg, rgba(255, 213, 143, 0.12) 0 22%, transparent 22%),
    linear-gradient(180deg, #8b5738 0 45%, #6f432c 45% 100%);
  box-shadow: none;
}

.word-plot span {
  position: absolute;
  left: 50%;
  bottom: 5px;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
}

.word-plot.level-1 span,
.word-plot.level-2 span,
.word-plot.level-3 span,
.word-plot.level-4 span,
.word-plot.level-5 span,
.word-plot.level-6 span {
  background: var(--leaf);
}

.word-plot.level-2 span,
.word-plot.level-3 span {
  height: 14px;
  box-shadow: -5px 3px 0 var(--leaf-dark), 5px 0 0 #4cae62;
}

.word-plot.level-4 span,
.word-plot.level-5 span,
.word-plot.level-6 span {
  height: 18px;
  background: var(--leaf-dark);
  box-shadow: -7px 3px 0 var(--leaf), 7px -2px 0 #6fbd57, 0 -8px 0 var(--gold);
}

.word-plot.needs-water::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 10px;
  background: var(--water);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-panel,
.loading-panel {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  padding: 28px;
  text-align: center;
}

.loading-panel {
  margin: 20vh auto 0;
  font-weight: 900;
}

.pixel-house {
  position: relative;
  width: 118px;
  height: 104px;
  margin: 0 auto 16px;
}

.pixel-house .roof,
.pixel-house .wall,
.pixel-house .door {
  position: absolute;
  display: block;
}

.pixel-house .roof {
  left: 13px;
  top: 0;
  width: 92px;
  height: 38px;
  background: var(--tomato);
  box-shadow: -12px 18px 0 var(--tomato), 12px 18px 0 var(--tomato);
}

.pixel-house .wall {
  left: 21px;
  top: 38px;
  width: 76px;
  height: 56px;
  background: #e7bd73;
  border: 4px solid var(--wood-dark);
}

.pixel-house .door {
  left: 51px;
  top: 58px;
  width: 20px;
  height: 36px;
  background: var(--wood);
  border: 3px solid var(--wood-dark);
}

.login-form {
  margin-top: 18px;
  text-align: left;
}

.login-form .primary-button {
  width: 100%;
  margin-top: 12px;
}

.form-error {
  margin: 8px 0 0;
  color: #8f2d24;
  font-weight: 800;
}

@media (max-width: 860px) {
  .farm-page {
    overflow: auto;
  }

  .farm-shell {
    width: min(100vw - 20px, 680px);
    padding-top: 18px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) 84px;
    grid-template-rows: auto auto;
    grid-template-areas:
      "brand mascot"
      "tabs tabs";
    min-height: 0;
    align-items: end;
    column-gap: 12px;
  }

  .mascot-stage {
    width: 84px;
    height: 96px;
    justify-content: flex-start;
    transform: translateX(-34px);
  }

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

  .farm-status {
    order: 2;
  }

  .stats-list {
    grid-template-columns: repeat(4, 1fr);
  }

  .word-plots {
    grid-template-columns: repeat(auto-fill, minmax(24px, 24px));
  }
}

@media (max-width: 560px) {
  .farm-shell {
    width: calc(100vw - 14px);
  }

  .topbar {
    gap: 12px;
    padding-left: 4px;
  }

  h1 {
    font-size: 2.25rem;
  }

  .view-tabs {
    width: 100%;
  }

  .view-tabs button {
    flex: 1;
    padding: 0 8px;
  }

  .nav-characters {
    height: 86px;
  }

  .study-board,
  .field-board,
  .farm-status,
  .gate-panel {
    padding: 12px;
    box-shadow: 5px 5px 0 var(--shadow);
  }

  .sentence-sign {
    padding: 18px;
  }

  .sentence {
    font-size: 1.32rem;
  }

  .stats-list {
    grid-template-columns: 1fr 1fr;
  }

  .field-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .word-plots {
    grid-template-columns: repeat(auto-fill, minmax(23px, 23px));
  }
}
