:root {
  --wood-dark: #432512;
  --wood-mid: #6b3e1f;
  --wood-light: #9c6233;
  --parchment: #fff6df;
  --parchment-2: #f4e4bd;
  --ink: #361c0c;
  --ink-soft: #6c492d;
  --green-btn: #3b8d3e;
  --green-btn-dark: #28652b;
  --gold: #f5b727;
  --gold-soft: #ffe89e;
  --red-accent: #c84b31;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top, #5d3d22 0%, #2b180c 100%);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}

img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hidden {
  display: none !important;
}

.app-shell {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--parchment);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 36px rgba(0, 0, 0, 0.55);
  border-left: 3px solid var(--wood-dark);
  border-right: 3px solid var(--wood-dark);
}

@media (max-width: 450px) {
  .app-shell {
    border-left: none;
    border-right: none;
  }
}

/* TITLE SCREEN */
.screen-title {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: linear-gradient(180deg, #ffe2a4 0%, #f3c477 45%, #79a646 100%);
  overflow-y: auto;
}

.title-card {
  width: 100%;
  background: var(--parchment);
  border: 3px solid var(--wood-dark);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(42, 24, 16, 0.35);
}

.title-banner-wrap {
  width: 100%;
  background: #432512;
  border-bottom: 3px solid var(--wood-dark);
}

.title-banner-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 245px;
  object-fit: cover;
}

.title-content {
  padding: 16px 16px 18px;
  text-align: center;
}

.title-kicker {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: var(--gold-soft);
  color: var(--wood-dark);
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--wood-light);
}

.title-content h1 {
  margin: 8px 0 2px;
  font-size: 30px;
  line-height: 1.05;
  color: var(--wood-dark);
}

.title-sub {
  margin: 0 0 10px;
  font-weight: 700;
  font-size: 14px;
  color: var(--wood-mid);
}

.title-desc {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.btn-start {
  width: 100%;
  padding: 13px 18px;
  border-radius: 12px;
  border: 3px solid var(--green-btn-dark);
  background: linear-gradient(180deg, #53b556 0%, var(--green-btn) 100%);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--green-btn-dark);
  transition: transform 0.08s ease;
}

.btn-start:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--green-btn-dark);
}

.title-tip {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* GAME SCREEN */
.screen-game {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--parchment);
}

.top-hud {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  background: linear-gradient(180deg, #744423 0%, #593318 100%);
  border-bottom: 2px solid var(--wood-dark);
  color: #fff8e2;
}

.hud-coins-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(25, 13, 6, 0.45);
  border: 1.5px solid #e6b445;
  padding: 3px 9px 3px 5px;
  border-radius: 99px;
  font-weight: 800;
  font-size: 14px;
  color: #ffe998;
}

.pixel-icon {
  width: 20px;
  height: 20px;
}

.hud-badge {
  background: rgba(255, 246, 223, 0.14);
  border: 1px solid rgba(255, 246, 223, 0.28);
  border-radius: 8px;
  padding: 4px 7px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.btn-icon {
  margin-left: auto;
  background: rgba(255, 246, 223, 0.16);
  border: 1.5px solid rgba(255, 246, 223, 0.35);
  color: #fff;
  border-radius: 8px;
  width: 32px;
  height: 29px;
  font-size: 15px;
  cursor: pointer;
}

/* STORY BANNER */
.story-banner {
  flex-shrink: 0;
  background: var(--parchment-2);
  border-bottom: 2px solid #d5bc8a;
  padding: 6px 10px;
}

.story-banner.ready {
  background: linear-gradient(90deg, #ffe793 0%, #ffd257 100%);
  border-bottom-color: #c58f1a;
}

.story-banner.finished {
  background: linear-gradient(90deg, #fff0ba 0%, #fde08d 100%);
}

.story-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.story-info {
  flex: 1;
  min-width: 0;
}

.story-info strong {
  display: block;
  font-size: 12px;
  color: var(--wood-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-info span {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-bar {
  margin-top: 3px;
  height: 5px;
  background: rgba(67, 37, 18, 0.18);
  border-radius: 99px;
  overflow: hidden;
}

.story-bar-fill {
  height: 100%;
  background: var(--green-btn);
  transition: width 0.25s ease;
}

.btn-story-claim {
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 9px;
  border: 2px solid var(--green-btn-dark);
  background: var(--green-btn);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  animation: pulseBtn 1.2s infinite ease-in-out;
}

.btn-story-hint {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1.5px solid var(--wood-light);
  background: var(--parchment);
  cursor: pointer;
  font-size: 14px;
}

@keyframes pulseBtn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* FARM VIEW & CANVAS */
.farm-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(180deg, #98c768 0%, #6f9e42 100%);
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
}

#farm-canvas {
  aspect-ratio: 380 / 430;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  touch-action: none;
  border-radius: 10px;
  border: 2px solid var(--wood-dark);
  box-shadow: 0 4px 12px rgba(28, 16, 6, 0.35);
  background: #6da947;
  cursor: pointer;
}

/* QUICK ACTION BAR */
.quick-bar {
  flex-shrink: 0;
  background: var(--parchment);
  border-top: 2px solid var(--wood-dark);
  padding: 6px 8px 7px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seed-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.seed-chip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 5px;
  border-radius: 10px;
  border: 2px solid #c9ad7c;
  background: #fffdf5;
  cursor: pointer;
  color: var(--ink);
}

.seed-chip.active {
  border-color: var(--green-btn);
  background: #e8fad8;
  box-shadow: 0 0 0 1px var(--green-btn);
}

.seed-chip.locked {
  background: #efe3c8;
  opacity: 0.85;
}

.seed-chip.buyable {
  border-color: #d68c19;
  background: #fff3cc;
  opacity: 1;
}

.seed-chip img {
  width: 26px;
  height: 26px;
}

.seed-meta {
  text-align: left;
  line-height: 1.1;
}

.seed-meta strong {
  display: block;
  font-size: 11px;
}

.seed-meta span {
  font-size: 10px;
  color: var(--ink-soft);
}

.btn-sell-quick {
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid #965b10;
  background: linear-gradient(180deg, #ffca47 0%, #eb9f1e 100%);
  color: #3a1f07;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}

.btn-sell-quick:disabled {
  background: #e3d4b4;
  border-color: #bda87f;
  color: #7d6748;
  cursor: default;
}

.btn-sell-quick.pulse {
  box-shadow: 0 2px 0 #965b10;
}

/* DRAWER VIEW */
.drawer-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 10px 14px;
  background: var(--parchment);
}

.drawer-section {
  margin-bottom: 16px;
}

.drawer-section h3 {
  margin: 0 0 4px;
  font-size: 15px;
  color: var(--wood-dark);
}

.sec-sub {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.sec-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-card {
  background: #fffdf6;
  border: 2px solid #d4b988;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 2px 4px rgba(67, 37, 18, 0.08);
}

.game-card.highlight {
  border-color: #469c48;
  background: #f5ffea;
}

.game-card p {
  margin: 3px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.card-flex {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.card-sprite {
  width: 54px;
  height: 54px;
  flex-shrink: 0;
  background: var(--parchment-2);
  border: 1.5px solid #d4b988;
  border-radius: 10px;
  padding: 3px;
}

.card-sprite.lg {
  width: 68px;
  height: 68px;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-body strong {
  display: block;
  font-size: 14px;
  color: var(--wood-dark);
}

.bonus-line {
  color: #2f6f31 !important;
  font-weight: 700;
}

.tag-pill {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  background: var(--parchment-2);
  border: 1px solid #cdb079;
  color: var(--wood-mid);
  padding: 2px 7px;
  border-radius: 99px;
  margin-bottom: 3px;
}

/* ORDERS */
.order-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.mini-portrait {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1.5px solid var(--wood-light);
  background: var(--parchment-2);
}

.order-head > div {
  flex: 1;
}

.order-head strong {
  display: block;
  font-size: 13.5px;
}

.reward-tag {
  font-size: 12px;
  font-weight: 800;
  color: var(--green-btn-dark);
}

.req-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.req-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #f6ebd1;
  border: 1.5px solid #d1b584;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
}

.req-pill.ok {
  background: #e1f8d5;
  border-color: #5ca85e;
}

.req-pill img {
  width: 22px;
  height: 22px;
}

/* BARN */
.barn-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.barn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fffdf6;
  border: 1.5px solid #d6bc8e;
  border-radius: 10px;
  padding: 6px 8px;
}

.barn-row img {
  width: 30px;
  height: 30px;
}

.barn-info {
  flex: 1;
  min-width: 0;
}

.barn-info strong {
  display: block;
  font-size: 12.5px;
}

.barn-info span {
  font-size: 11px;
  color: var(--ink-soft);
}

.empty-msg {
  font-size: 12.5px;
  color: var(--ink-soft);
  text-align: center;
  padding: 12px;
  background: #f5ead1;
  border-radius: 10px;
}

/* RECIPE PILLS */
.recipe-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.recipe-pill {
  border: 1.5px solid #c9ab78;
  background: #f9efda;
  color: var(--ink);
  border-radius: 7px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.recipe-pill.active {
  background: var(--green-btn);
  border-color: var(--green-btn-dark);
  color: #fff;
}

/* ALMANAC */
.almanac-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.almanac-tile {
  background: #fffdf6;
  border: 1.5px solid #d4b988;
  border-radius: 10px;
  padding: 7px 5px;
  text-align: center;
}

.almanac-tile img {
  width: 38px;
  height: 38px;
  display: block;
  margin: 0 auto 4px;
}

.almanac-tile.unknown img {
  filter: brightness(0.12) opacity(0.35);
}

.almanac-tile strong {
  display: block;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.almanac-tile span {
  font-size: 10.5px;
  color: var(--ink-soft);
}

/* BUTTONS */
.btn-primary {
  padding: 9px 12px;
  border-radius: 9px;
  border: 2px solid var(--green-btn-dark);
  background: var(--green-btn);
  color: #fff;
  font-weight: 800;
  font-size: 12.5px;
  cursor: pointer;
}

.btn-primary:disabled,
.btn-primary.disabled {
  background: #d8ccb3;
  border-color: #b7a685;
  color: #77664e;
  cursor: default;
}

.btn-primary.full,
.btn-ghost.full {
  width: 100%;
}

.btn-accent {
  padding: 6px 10px;
  border-radius: 8px;
  border: 2px solid #965b10;
  background: #ffbe3b;
  color: #3a1f07;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}

.btn-small {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--wood-mid);
  background: var(--parchment-2);
  color: var(--wood-dark);
  font-weight: 800;
  font-size: 11.5px;
  cursor: pointer;
}

.btn-ghost {
  padding: 5px 9px;
  border-radius: 8px;
  border: 1.5px solid #cdb07d;
  background: #faf0da;
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}

.btn-danger {
  padding: 9px 12px;
  border-radius: 9px;
  border: 2px solid #8a2a17;
  background: var(--red-accent);
  color: #fff;
  font-weight: 800;
  font-size: 12.5px;
  cursor: pointer;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row > button {
  flex: 1;
}

/* BOTTOM NAVIGATION */
.bottom-nav {
  flex-shrink: 0;
  height: 58px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: linear-gradient(180deg, #6e4020 0%, #4b2a13 100%);
  border-top: 2.5px solid var(--wood-dark);
}

.nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: #ead7b3;
  cursor: pointer;
  padding: 4px 2px;
}

.nav-btn.active {
  background: rgba(255, 232, 158, 0.16);
  color: #ffe791;
  box-shadow: inset 0 3px 0 #ffd147;
}

.nav-ico {
  font-size: 18px;
  line-height: 1;
}

.nav-lbl {
  font-size: 10.5px;
  font-weight: 700;
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: 11px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--red-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #fff;
}

/* MODALS & TOAST */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 10, 4, 0.68);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  z-index: 40;
}

.dialogue-box {
  width: 100%;
  background: var(--parchment);
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
}

.dialogue-box h3 {
  margin: 0 0 8px;
  color: var(--wood-dark);
}

.dialogue-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.dlg-portrait {
  width: 62px;
  height: 62px;
  border-radius: 10px;
  border: 2px solid var(--wood-mid);
  background: var(--parchment-2);
}

.dialogue-head strong {
  display: block;
  font-size: 16px;
  color: var(--wood-dark);
}

.dialogue-head span {
  font-size: 12px;
  color: var(--ink-soft);
}

.dlg-text {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: #fffdf7;
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid #dec699;
}

.offline-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.offline-chip {
  background: #e6f9da;
  border: 1.5px solid #59a45b;
  color: #1f5521;
  font-weight: 800;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 9px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(34, 18, 8, 0.92);
  color: #fff6dc;
  padding: 8px 14px;
  border-radius: 99px;
  border: 1.5px solid #e6b445;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
