/* Verdant Vale. The game is a canvas; everything here is the frame around it:
   the loading screen, the menus, the lobby, chat and the touch controls. */

:root {
  color-scheme: dark;
  --ink: #e8f2df;
  --ink-2: #aebcc2;
  --ink-3: #7f9299;
  --panel: rgba(13, 24, 38, 0.96);
  --edge: rgba(180, 207, 150, 0.62);
  --leaf: #9ad34e;
  --leaf-deep: #5f873f;
  --warn: #ef9c89;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: #101827;
}

* { box-sizing: border-box; }

html, body, #shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body { background: radial-gradient(circle at 50% 20%, #314e69 0%, #172439 55%, #0b111d 100%); color: var(--ink); }

#shell { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }

#game { display: block; width: 100%; height: 100%; cursor: crosshair; image-rendering: pixelated; }

[hidden] { display: none !important; }

/* ------------------------------------------------------------ brand --- */

.brand { text-align: center; filter: drop-shadow(0 8px 0 rgba(11, 20, 24, 0.45)); }
.brand h1 {
  margin: 0;
  color: #eefac9;
  font-family: Georgia, serif;
  font-size: clamp(38px, 7vw, 76px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 0.9;
  text-shadow: 0 3px 0 #7eaa3f, 0 6px 0 #365b32, 3px 0 0 #29442c, -3px 0 0 #29442c;
}
.brand p {
  margin: 21px 0 0;
  color: #dbe9f2;
  font-size: clamp(10px, 1.4vw, 14px);
  font-weight: 800;
  letter-spacing: 0.36em;
  text-shadow: 0 2px 0 #172033;
}
.brand-leaf {
  display: inline-block;
  margin-bottom: 18px;
  color: var(--leaf);
  font-size: 30px;
  transform: rotate(28deg);
  text-shadow: 0 3px 0 #315c2b;
}

/* ---------------------------------------------------------- loading --- */

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 48px;
  background:
    linear-gradient(180deg, rgba(15, 27, 45, 0.2), rgba(8, 13, 23, 0.84)),
    radial-gradient(circle at 50% 30%, #638fc0, #253d5d 58%, #111a2c);
  z-index: 20;
  transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader {
  width: min(62vw, 330px);
  height: 8px;
  overflow: hidden;
  border: 2px solid rgba(226, 242, 255, 0.7);
  border-radius: 2px;
  background: rgba(8, 16, 26, 0.55);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}
.loader span {
  display: block;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, #6ca33e, #c4e865, #6ca33e);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ---------------------------------------------------------- screens --- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 28px;
  padding: 24px 16px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: rgba(6, 11, 20, 0.6);
  user-select: text;
  -webkit-user-select: text;
}
/* Screens shown with no world running behind them get the sky of their own. */
#title, #lobby, #result {
  background:
    linear-gradient(180deg, rgba(15, 27, 45, 0.15), rgba(8, 13, 23, 0.86)),
    radial-gradient(circle at 50% 30%, #4f7ca8, #22395a 58%, #0f1828);
}

button {
  font: inherit;
  font-weight: 800;
  color: var(--ink);
  background: rgba(24, 40, 58, 0.92);
  border: 2px solid rgba(164, 185, 194, 0.35);
  border-radius: 7px;
  padding: 11px 16px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled) { border-color: var(--edge); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--leaf-deep); border-color: #8fbf5c; color: #f5f8e8; }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
button.small { min-height: 36px; padding: 7px 11px; font-size: 13px; }
:focus-visible { outline: 3px solid var(--leaf); outline-offset: 2px; }

.modes { display: grid; gap: 12px; width: min(92vw, 520px); }
.mode {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 16px 20px;
  background: rgba(13, 24, 38, 0.88);
  border-color: rgba(180, 207, 150, 0.35);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}
.mode strong { font-family: Georgia, serif; font-size: 22px; color: #eefac9; letter-spacing: 0.02em; }
.mode span { color: var(--ink-2); font-weight: 700; font-size: 13px; }
.mode:hover:not(:disabled) { transform: translateY(-1px); }
.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 99px;
  background: #e0574a;
  color: #fff;
  font: 800 12px/1.4 "Trebuchet MS", sans-serif;
  vertical-align: middle;
}

.mode.learn { border-color: rgba(244, 207, 88, 0.45); }
.mode.learn strong { color: #f4cf58; }
.mode.learn.suggest {
  border-color: #f4cf58;
  background: rgba(58, 52, 22, 0.9);
  animation: beckon 2.4s ease-in-out infinite;
}
@keyframes beckon { 50% { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(244, 207, 88, 0.25); } }
@media (prefers-reduced-motion: reduce) { .mode.learn.suggest { animation: none; } }

.who, .news { margin: 0; color: var(--ink-2); font-size: 13px; font-weight: 700; text-align: center; max-width: 520px; }
.who a { color: #c4e865; }
.news { color: #dbe6c8; }
.foot { display: flex; gap: 8px; }

.panel {
  width: min(94vw, 720px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px;
  background: var(--panel);
  border: 2px solid var(--edge);
  border-radius: 12px;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.3);
}
.panel h2 { margin: 0; font-family: Georgia, serif; font-size: 26px; color: #eefac9; letter-spacing: 0.03em; }
.panel h3 { margin: 20px 0 8px; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); }
.panel p { color: var(--ink-2); font-weight: 600; line-height: 1.5; }
.small-panel { width: min(92vw, 400px); display: grid; gap: 10px; text-align: center; }
.small-panel p { margin: 0 0 6px; }

.lobby header { display: flex; align-items: center; gap: 12px; }
.lobby header h2 { flex: 1; }
.rating { color: #f4cf58; font-weight: 800; font-size: 14px; }
.rules { font-size: 13px; }
.challenge { display: flex; flex-wrap: wrap; gap: 8px; }
.challenge input {
  flex: 1 1 200px;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: rgba(6, 12, 22, 0.8);
  border: 2px solid rgba(164, 185, 194, 0.35);
  border-radius: 7px;
}
/* The tier a battle is posted at: four metals, one picked. */
.tiers { flex: 1 1 100%; margin: 0 0 4px; padding: 0; border: 0; min-width: 0; }
.tiers legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); }
.tier-note { margin-left: 6px; letter-spacing: 0; text-transform: none; font-weight: 700; font-size: 13px; color: var(--ink-2); }
.tier-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tier {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 8px;
  border: 2px solid rgba(164, 185, 194, 0.35);
  border-radius: 7px;
  background: rgba(24, 40, 58, 0.92);
  font-weight: 800;
  color: var(--ink-2);
  cursor: pointer;
}
.tier input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.tier-icon { width: 24px; height: 24px; flex: none; }
.tier:hover { border-color: var(--edge); }
.tier:has(input:checked) { border-color: var(--metal); background: rgba(8, 15, 25, 0.9); color: var(--ink); box-shadow: inset 0 -3px 0 var(--metal); }
.tier:has(input:focus-visible) { outline: 3px solid var(--leaf); outline-offset: 2px; }
.tier-chip {
  display: inline-block;
  padding: 0 7px;
  border: 1px solid var(--metal);
  border-radius: 99px;
  color: var(--metal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: 1px;
}
@media (max-width: 420px) {
  .tier { flex-direction: column; gap: 2px; font-size: 12px; }
}

.notice { margin: 10px 0 0; color: #c4e865 !important; }
.notice.bad { color: var(--warn) !important; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(8, 15, 25, 0.7);
  border-radius: 7px;
  font-weight: 700;
  color: var(--ink-2);
  font-size: 14px;
}
.list li .grow { flex: 1; min-width: 0; }
.list li strong { color: var(--ink); }
.list li.empty { justify-content: center; color: var(--ink-3); font-weight: 600; }
.list li.live { border-left: 4px solid #e0574a; }
.board { counter-reset: place; }
.board li::before { counter-increment: place; content: counter(place); color: var(--ink-3); width: 20px; }
.board li.you { border-left: 4px solid #f4cf58; }

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 1px 6px;
  border: 1px solid rgba(220, 234, 210, 0.45);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: rgba(232, 242, 223, 0.1);
  color: #f3f8e6;
  font: 800 0.86em/1.35 ui-monospace, "SFMono-Regular", Menlo, monospace;
  text-align: center;
  white-space: nowrap;
}

/* --------------------------------------------------------- tutorials --- */

.lessons header { display: flex; align-items: center; gap: 12px; }
.lessons header h2 { flex: 1; }
.lesson-list li { gap: 12px; }
.lesson-list .grow { display: grid; gap: 2px; }
.lesson-list small { color: var(--ink-3); font-weight: 600; font-size: 13px; }
.lesson-num {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(164, 185, 194, 0.16);
  color: var(--ink-2);
  font-weight: 800;
}
.lesson.finished .lesson-num { background: var(--leaf-deep); color: #f5f8e8; }
.lesson.next { border-left: 4px solid #f4cf58; }

/* --------------------------------------------------------- versus cpu --- */

.cpu header { display: flex; align-items: center; gap: 12px; }
.cpu header h2 { flex: 1; }
.cpu .tiers { margin: 4px 0 14px; }
.cpu-list .beaten { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }

/* ------------------------------------------------------------ manual --- */

#manual { padding: 12px; }
.manual {
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(96vw, 1040px);
  height: min(92vh, 900px);
  max-height: none;
  padding: 0;
  overflow: hidden;
}
.manual header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(180, 207, 150, 0.25);
}
.manual header h2 { flex: 1; }
.manual-note { margin: 0; color: var(--warn) !important; font-size: 13px; }
.manual-body { display: grid; grid-template-columns: 230px 1fr; min-height: 0; }
.manual-toc {
  overflow-y: auto;
  padding: 12px 10px;
  border-right: 1px solid rgba(180, 207, 150, 0.2);
}
.manual-toc a {
  display: flex;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}
.manual-toc a span { width: 1.4em; color: var(--ink-3); text-align: right; }
.manual-toc a:hover, .manual-toc a.here { background: rgba(164, 185, 194, 0.12); color: var(--ink); }
.manual-toc a.here span { color: #f4cf58; }
.manual-text {
  overflow-y: auto;
  padding: 4px 26px 40px;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.6;
  user-select: text;
  -webkit-user-select: text;
  outline: none;
}
.manual-text .chapter { padding-top: 18px; }
.manual-text h3 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 10px;
  color: #eefac9;
  font: 900 23px/1.2 Georgia, serif;
  letter-spacing: 0.01em;
  text-transform: none;
}
.manual-text h3 .num { color: var(--leaf-deep); font-size: 18px; }
.manual-text h4 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 20px 0 6px;
  color: var(--ink);
  font-size: 15px;
}
.manual-text p, .manual-text li, .manual-text dd { color: var(--ink-2); font-weight: 600; }
.manual-text b { color: var(--ink); }
.manual-text a { color: #c4e865; }
.manual-text .lead { font-size: 16px; color: var(--ink); }
.manual-text ul, .manual-text ol { padding-left: 1.3em; }
.manual-text li { margin: 4px 0; }
.manual-text dt { margin-top: 12px; color: var(--ink); font-weight: 800; }
.manual-text dd { margin: 2px 0 0 0; }
.manual-text dl.words { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.manual-text dl.words dt, .manual-text dl.words dd { margin: 0; }
.manual-text .where { margin-left: 6px; color: var(--ink-3); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.callout {
  margin: 14px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--leaf);
  border-radius: 6px;
  background: rgba(154, 211, 78, 0.08);
  color: var(--ink-2);
  font-weight: 600;
}
.callout.warn { border-color: #f4cf58; background: rgba(244, 207, 88, 0.08); }
.table-wrap { overflow-x: auto; margin: 10px 0; }
.manual-text table { width: 100%; border-collapse: collapse; font-size: 14px; }
.manual-text th {
  padding: 6px 10px;
  color: var(--ink-3);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.manual-text td { padding: 6px 10px; border-top: 1px solid rgba(164, 185, 194, 0.14); font-weight: 600; vertical-align: middle; }
.manual-text td:first-child { white-space: nowrap; }
.manual-text table.numbers td { white-space: nowrap; }
.manual-text table.recipes td:first-child { width: 38%; }
.manual-text table.things td:first-child { width: 1%; }
.manual-text .no { color: var(--warn); }
.manual-text .need { display: inline-flex; align-items: center; gap: 2px; margin-right: 10px; white-space: nowrap; }
.manual-text canvas { vertical-align: middle; image-rendering: pixelated; }
.manual-text canvas.swatch { margin-right: 4px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); }
.manual-text canvas.heart { margin-right: 2px; }

@media (max-width: 720px) {
  #manual { padding: 0; }
  .manual { width: 100vw; height: 100%; border-radius: 0; border-width: 0; }
  .manual-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .manual-toc {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid rgba(180, 207, 150, 0.2);
  }
  .manual-toc a { flex: none; white-space: nowrap; }
  .manual-text { padding: 0 16px 32px; font-size: 14px; }
}

/* ------------------------------------------------------------- coach --- */

#coach {
  position: absolute;
  z-index: 7;
  left: max(16px, env(safe-area-inset-left));
  bottom: 60px;
  width: min(380px, calc(100vw - 32px));
  padding: 12px 14px;
  background: rgba(13, 24, 38, 0.95);
  border: 2px solid rgba(244, 207, 88, 0.6);
  border-radius: 10px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
  transition: border-color 200ms ease, opacity 200ms ease;
}
#coach.cheer, #coach.done { border-color: var(--leaf); }
.coach-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #f4cf58;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.coach-head span:last-child { color: var(--ink-3); white-space: nowrap; }
.coach-progress { height: 4px; margin: 7px 0 9px; border-radius: 2px; background: rgba(164, 185, 194, 0.18); overflow: hidden; }
.coach-progress span { display: block; height: 100%; width: 0; background: #f4cf58; transition: width 400ms ease; }
#coach.cheer .coach-progress span, #coach.done .coach-progress span { background: var(--leaf); }
.coach-text { margin: 0; color: var(--ink); font-size: 15px; font-weight: 600; line-height: 1.5; }
.coach-text b { color: #fff3c4; }
.coach-big { display: block; margin-bottom: 4px; color: #c4e865 !important; font: 900 20px/1.3 Georgia, serif; }
.coach-nudge {
  margin: 9px 0 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(239, 156, 137, 0.14);
  color: #ffd2c6;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}
.coach-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.coach-actions:empty { display: none; }
#coach.over-inventory { opacity: 0.93; }

/* ------------------------------------------------------------ in game --- */

.hud-button {
  position: absolute;
  z-index: 6;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  width: 40px;
  min-height: 40px;
  padding: 0;
  background: rgba(10, 18, 30, 0.78);
  font-size: 18px;
}
.hud-button.help { top: calc(max(10px, env(safe-area-inset-top)) + 48px); font-weight: 900; }
.hud-button.map { top: calc(max(10px, env(safe-area-inset-top)) + 96px); display: grid; place-items: center; }
.hud-button.map.on { background: rgba(226, 194, 101, 0.95); border-color: #fff0ad; color: #483d27; }
.hud-button.map.locked { opacity: 0.45; }
.hud-button.wide {
  top: auto;
  bottom: 100px;
  left: 50%;
  width: auto;
  padding: 0 16px;
  transform: translateX(-50%);
  background: #7a2a24;
  border-color: #e0574a;
  font-size: 14px;
}

#chat {
  position: absolute;
  z-index: 7;
  left: max(16px, env(safe-area-inset-left));
  bottom: 70px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
#chat ol { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 3px; }
#chat li {
  justify-self: start;
  max-width: 100%;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(8, 14, 24, 0.66);
  color: #dfe9e2;
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
  transition: opacity 1s ease;
}
#chat li b { color: #c4e865; }
#chat li.faded { opacity: 0; }
#chat form { pointer-events: auto; }
#chat input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: rgba(6, 12, 22, 0.92);
  border: 2px solid var(--edge);
  border-radius: 7px;
}

/* --------------------------------------------------- touch controls --- */

#mobile-controls {
  position: absolute;
  inset: auto 0 max(18px, env(safe-area-inset-bottom));
  display: none;
  align-items: end;
  justify-content: space-between;
  padding: 0 20px;
  pointer-events: none;
  z-index: 5;
}
#mobile-controls button {
  width: 64px;
  height: 64px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  background: rgba(13, 27, 43, 0.5);
  color: rgba(255, 255, 255, 0.85);
  font-size: 22px;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
  pointer-events: auto;
}
.move-pad { display: flex; gap: 12px; }
#mobile-controls .inventory {
  position: absolute;
  right: 20px;
  bottom: 78px;
  width: 50px;
  height: 50px;
  border-color: rgba(177, 214, 142, 0.5);
  color: #dff1c1;
  font-size: 19px;
}
#mobile-controls .jump { margin-left: auto; margin-right: 12px; }
#mobile-controls .action { border-color: rgba(255, 216, 104, 0.55); color: #ffe79c; }

@media (hover: none) and (max-width: 900px), (pointer: coarse) and (max-width: 900px) {
  #shell.playing #mobile-controls { display: flex; }
  #shell.playing #mobile-controls.inventory-open { display: none; }
  #game { cursor: default; }
  /* Up and to the left: clear of the touch buttons, the hearts and you. */
  #coach {
    top: 80px;
    bottom: auto;
    left: 60px;
    width: min(310px, 42vw);
    max-height: calc(100% - 190px);
    overflow-y: auto;
    padding: 9px 11px;
  }
  .coach-text { font-size: 13px; }
  .coach-big { font-size: 16px; }
  .coach-nudge { font-size: 12px; }
  /* Over the inventory it is only the words, over its title, and taps go
     through to whatever is under them. */
  #coach.over-inventory {
    top: 6px;
    left: 56px;
    right: 56px;
    width: auto;
    max-height: 64px;
    padding: 6px 10px;
    overflow: hidden;
    opacity: 0.94;
    pointer-events: none;
  }
  #coach.over-inventory .coach-head, #coach.over-inventory .coach-progress,
  #coach.over-inventory .coach-actions, #coach.over-inventory .coach-nudge { display: none; }
  #coach.over-inventory .coach-text { font-size: 12px; line-height: 1.35; }
}
@media (hover: none) and (max-width: 900px) and (orientation: portrait), (pointer: coarse) and (max-width: 900px) and (orientation: portrait) {
  #coach { top: 136px; left: 10px; right: 10px; width: auto; }
  #coach.over-inventory { top: 6px; max-height: 76px; }
}
