﻿/* ==========================================================================
   Tallgrass UI
   Chamfered wooden plaques, chalk-on-parchment type, a meadow palette taken
   from the same colours the shaders use. Flat fills and hard edges only:
   no blur, no translucency tricks, no gradient sheen.
   ========================================================================== */

:root {
  /* palette shared with src/core/config.js */
  --ink:          #1c2a16;
  --ink-soft:     #35492b;
  --moss:         #2f4a26;
  --turf:         #6f9b3e;
  --turf-lit:     #a8c95a;
  --parchment:    #efe4c8;
  --parchment-lo: #ddcda6;
  --parchment-hi: #f8f0da;
  --soil:         #6b4a2a;
  --soil-lo:      #4a3220;
  --soil-hi:      #a8794a;
  --chalk:        #f5f2e4;
  --iron:         #46433c;
  --ember:        #c8762c;
  --ember-lo:     #94551c;

  --chamfer: 9px;
  --chamfer-sm: 5px;
  --edge: 3px;

  /* Pixelify Sans carries the Latin and the digits; CJK falls through to the
     platform face, which keeps a pixel wordmark next to readable Chinese. */
  --cjk: 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', 'Source Han Sans SC',
         'Noto Sans CJK SC', 'WenQuanYi Micro Hei', sans-serif;
  --font-pixel: 'Pixelify Sans', 'Courier New', ui-monospace, var(--cjk);
  --font-body: 'Karla', 'Segoe UI', system-ui, var(--cjk);

  --shadow-drop: 0 6px 0 rgba(24, 34, 18, 0.28);
  --shadow-lift: 0 9px 0 rgba(24, 34, 18, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #10180d;
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* the 3D layer is point-upscaled from a low-res target; keep the pixels hard */
  image-rendering: pixelated;
}
#stage.is-smooth { image-rendering: auto; }

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

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding: clamp(18px, 3.2vmin, 44px);
}
.screen[hidden] { display: none; }
.screen > * { pointer-events: auto; }

.screen--boot,
.screen--modal {
  display: grid;
  place-items: center;
  background: rgba(14, 22, 11, 0.72);
  pointer-events: auto;
}

.screen--title {
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: start;
}

.screen--hud {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.screen--drawer {
  display: grid;
  justify-items: end;
  align-items: start;
  pointer-events: none;
}

/* ---------------------------------------------------------------- plaques */

.plaque {
  position: relative;
  background: var(--parchment);
  color: var(--ink);
  padding: clamp(16px, 2.2vmin, 26px) clamp(18px, 2.6vmin, 30px);
  clip-path: polygon(
    var(--chamfer) 0, calc(100% - var(--chamfer)) 0,
    100% var(--chamfer), 100% calc(100% - var(--chamfer)),
    calc(100% - var(--chamfer)) 100%, var(--chamfer) 100%,
    0 calc(100% - var(--chamfer)), 0 var(--chamfer)
  );
  box-shadow: var(--shadow-drop);
}
/* the darker frame behind the parchment, drawn as an inset ring */
.plaque::before {
  content: '';
  position: absolute;
  inset: 0;
  border: var(--edge) solid var(--soil-lo);
  clip-path: inherit;
  pointer-events: none;
}
/* a hairline of light along the top: carved wood catching the sun */
.plaque::after {
  content: '';
  position: absolute;
  inset: var(--edge);
  border-top: 2px solid var(--parchment-hi);
  border-left: 2px solid var(--parchment-hi);
  border-bottom: 2px solid var(--parchment-lo);
  clip-path: inherit;
  pointer-events: none;
}

.plaque--boot { width: min(520px, 92vw); text-align: left; }
.plaque--modal { width: min(560px, 92vw); }
.plaque--wide { width: min(900px, 94vw); max-height: 86vh; overflow: auto; }
.plaque--drawer {
  width: min(420px, 94vw);
  max-height: calc(100vh - 2 * clamp(18px, 3.2vmin, 44px));
  overflow: auto;
  pointer-events: auto;
}
.plaque--tag { padding: 12px 18px; }
.plaque--stats { padding: 12px 18px; }
.plaque--hint {
  justify-self: center;
  align-self: end;
  padding: 10px 20px;
  max-width: min(680px, 90vw);
  text-align: center;
  background: var(--parchment-hi);
}

/* ---------------------------------------------------------------- type */

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--font-pixel);
  font-size: clamp(11px, 1.25vmin, 14px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moss);
}

.wordmark {
  margin: 0 0 10px;
  font-family: var(--font-pixel);
  font-weight: 700;
  font-size: clamp(34px, 5.6vmin, 62px);
  line-height: 0.92;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-shadow: 3px 3px 0 var(--turf-lit), 6px 6px 0 rgba(28, 42, 22, 0.22);
}
.wordmark--large {
  font-size: clamp(46px, 9.4vmin, 118px);
  color: var(--parchment-hi);
  text-shadow:
    4px 4px 0 var(--moss),
    8px 8px 0 rgba(16, 24, 13, 0.45);
}

.lede {
  margin: 0 0 22px;
  max-width: 46ch;
  font-size: clamp(14px, 1.65vmin, 18px);
  line-height: 1.5;
  color: var(--chalk);
  text-shadow: 0 2px 0 rgba(16, 24, 13, 0.55);
}

.screen--title .eyebrow {
  color: var(--turf-lit);
  text-shadow: 0 2px 0 rgba(16, 24, 13, 0.6);
}

.title__stack { max-width: min(720px, 92vw); }

.corner-note {
  margin: 0;
  justify-self: start;
  font-size: clamp(11px, 1.3vmin, 13px);
  color: var(--parchment-lo);
  text-shadow: 0 1px 0 rgba(16, 24, 13, 0.7);
}

/* ---------------------------------------------------------------- buttons */

.menu {
  display: grid;
  gap: 10px;
  width: min(340px, 78vw);
}

.btn {
  --chamfer: var(--chamfer-sm);
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 13px 18px;
  border: 0;
  background: var(--parchment);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: clamp(15px, 1.85vmin, 20px);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: left;
  cursor: pointer;
  clip-path: polygon(
    var(--chamfer) 0, calc(100% - var(--chamfer)) 0,
    100% var(--chamfer), 100% calc(100% - var(--chamfer)),
    calc(100% - var(--chamfer)) 100%, var(--chamfer) 100%,
    0 calc(100% - var(--chamfer)), 0 var(--chamfer)
  );
  box-shadow: 0 5px 0 var(--soil-lo);
  transition: transform 90ms steps(2), box-shadow 90ms steps(2), background-color 90ms;
}
.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--soil-lo);
  clip-path: inherit;
  pointer-events: none;
}
.btn__meta {
  font-family: var(--font-body);
  font-size: 0.68em;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--soil);
  white-space: nowrap;
}
.btn:hover { background: var(--parchment-hi); transform: translateY(-2px); box-shadow: 0 7px 0 var(--soil-lo); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--soil-lo); }
.btn:focus-visible { outline: 3px solid var(--ember); outline-offset: 3px; }

.btn--primary {
  background: var(--turf);
  color: var(--chalk);
  box-shadow: 0 5px 0 var(--moss);
}
.btn--primary::before { border-color: var(--moss); }
.btn--primary .btn__meta { color: #e6f2cd; }
.btn--primary:hover { background: var(--turf-lit); color: var(--ink); box-shadow: 0 7px 0 var(--moss); }
.btn--primary:active { box-shadow: 0 2px 0 var(--moss); }

.btn--small {
  width: auto;
  padding: 8px 14px;
  font-size: clamp(12px, 1.5vmin, 15px);
  justify-content: center;
}

/* ---------------------------------------------------------------- boot */

.boot__step {
  margin: 4px 0 12px;
  font-family: var(--font-pixel);
  font-size: 15px;
  color: var(--soil);
}
.boot__note {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
}
.meter {
  height: 12px;
  background: var(--parchment-lo);
  border: 2px solid var(--soil-lo);
  padding: 2px;
}
.meter__fill {
  height: 100%;
  width: 4%;
  background: var(--turf);
  /* stepped fill: the bar advances in blocks, matching the pixel grid */
  background-image: repeating-linear-gradient(
    90deg, var(--turf) 0 8px, var(--moss) 8px 10px
  );
  transition: width 200ms steps(6);
}

/* ---------------------------------------------------------------- hud */

.hud__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.hud__index {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--soil);
}
.hud__name {
  margin: 2px 0 0;
  font-family: var(--font-pixel);
  font-size: clamp(19px, 2.6vmin, 27px);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.hud__concept {
  margin: 3px 0 0;
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
}

.plaque--stats dl {
  display: flex;
  gap: clamp(14px, 2.2vmin, 26px);
  margin: 0;
}
.plaque--stats dt {
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--soil);
}
.plaque--stats dd {
  margin: 2px 0 0;
  font-family: var(--font-pixel);
  font-size: clamp(19px, 2.5vmin, 26px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud__hint {
  margin: 0;
  font-size: clamp(13px, 1.6vmin, 16px);
  line-height: 1.4;
}

.hud__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.hud__buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.keycaps {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--parchment-lo);
  text-shadow: 0 1px 0 rgba(16, 24, 13, 0.75);
}
.keycaps__text { margin-right: 8px; }
.key {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  background: var(--parchment);
  color: var(--ink);
  border: 2px solid var(--soil-lo);
  border-bottom-width: 4px;
  font-family: var(--font-pixel);
  font-size: 12px;
  font-weight: 600;
}
.key--wide { min-width: 46px; }

.lock-warning {
  position: absolute;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%);
  padding: 9px 16px;
  background: var(--ember-lo);
  color: var(--chalk);
  border: 2px solid #2c1a08;
  font-size: 13px;
  font-weight: 700;
}
.lock-warning[hidden] { display: none; }

/* ---------------------------------------------------------------- modals */

.modal__title {
  margin: 0 0 6px;
  font-family: var(--font-pixel);
  font-size: clamp(22px, 3.2vmin, 34px);
  font-weight: 700;
}
.modal__body {
  margin: 0 0 16px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.score {
  display: flex;
  gap: 28px;
  margin: 0 0 20px;
  padding: 12px 0;
  border-top: 2px solid var(--parchment-lo);
  border-bottom: 2px solid var(--parchment-lo);
}
.score dt, .plaque--stats dt { margin: 0; }
.score dt {
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--soil);
}
.score dd {
  margin: 2px 0 0;
  font-family: var(--font-pixel);
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.modal__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.modal__actions .btn { width: auto; flex: 1 1 auto; justify-content: center; }

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
}
.panel__note {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 62ch;
}

/* ---------------------------------------------------------------- levels */

.levelgrid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 10px;
}
.levelcard {
  --chamfer: var(--chamfer-sm);
  position: relative;
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border: 0;
  background: var(--parchment-hi);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  clip-path: polygon(
    var(--chamfer) 0, calc(100% - var(--chamfer)) 0,
    100% var(--chamfer), 100% calc(100% - var(--chamfer)),
    calc(100% - var(--chamfer)) 100%, var(--chamfer) 100%,
    0 calc(100% - var(--chamfer)), 0 var(--chamfer)
  );
  box-shadow: 0 4px 0 var(--soil-lo);
  transition: transform 90ms steps(2), box-shadow 90ms steps(2);
}
.levelcard::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--soil-lo);
  clip-path: inherit;
}
.levelcard:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--soil-lo); }
.levelcard:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--soil-lo); }
.levelcard:focus-visible { outline: 3px solid var(--ember); outline-offset: 3px; }
.levelcard__no {
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--soil);
}
.levelcard__name {
  font-family: var(--font-pixel);
  font-size: 17px;
  font-weight: 700;
}
.levelcard__meta {
  font-size: 12px;
  color: var(--ink-soft);
}
.levelcard.is-done { background: var(--turf-lit); }
.levelcard.is-done .levelcard__no { color: var(--moss); }

/* ---------------------------------------------------------------- lab */

.lab__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 6px;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--parchment-lo);
  border: 2px solid var(--soil-lo);
}
.lab__stats div { display: grid; gap: 1px; }
.lab__stats span {
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--soil);
}
.lab__stats b {
  font-family: var(--font-pixel);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.lab__groups { display: grid; gap: 18px; }
.labgroup > h3 {
  margin: 0 0 8px;
  font-family: var(--font-pixel);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moss);
  border-bottom: 2px solid var(--parchment-lo);
  padding-bottom: 5px;
}
.labrow {
  display: grid;
  grid-template-columns: 1fr 58px;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.labrow > label {
  font-size: 13px;
  color: var(--ink-soft);
}
.labrow > output {
  font-family: var(--font-pixel);
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.labrow > input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 18px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.labrow > input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: var(--parchment-lo);
  border: 2px solid var(--soil-lo);
}
.labrow > input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 18px;
  margin-top: -7px;
  background: var(--turf);
  border: 2px solid var(--moss);
}
.labrow > input[type="range"]::-moz-range-track {
  height: 8px;
  background: var(--parchment-lo);
  border: 2px solid var(--soil-lo);
}
.labrow > input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 18px;
  border-radius: 0;
  background: var(--turf);
  border: 2px solid var(--moss);
}
.labrow > input[type="range"]:focus-visible { outline: 3px solid var(--ember); outline-offset: 2px; }

.labtoggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}
.labtoggle button {
  min-width: 74px;
  padding: 6px 10px;
  border: 2px solid var(--soil-lo);
  background: var(--parchment-lo);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 12px;
  cursor: pointer;
}
.labtoggle button[aria-pressed="true"] { background: var(--turf); color: var(--chalk); border-color: var(--moss); }
.labtoggle button:focus-visible { outline: 3px solid var(--ember); outline-offset: 2px; }

.labsegment { display: flex; gap: 5px; }
.labsegment button {
  flex: 1;
  padding: 6px 4px;
  border: 2px solid var(--soil-lo);
  background: var(--parchment-lo);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 12px;
  cursor: pointer;
}
.labsegment button[aria-pressed="true"] { background: var(--turf); color: var(--chalk); border-color: var(--moss); }

/* ---------------------------------------------------------------- credits */

.credits__body h3 {
  margin: 18px 0 6px;
  font-family: var(--font-pixel);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moss);
}
.credits__body h3:first-child { margin-top: 0; }
.credits__body ul { margin: 0; padding-left: 18px; }
.credits__body li { margin-bottom: 7px; font-size: 13px; line-height: 1.5; }
.credits__body code {
  font-family: ui-monospace, 'Courier New', monospace;
  font-size: 0.92em;
  padding: 1px 4px;
  background: var(--parchment-lo);
  border: 1px solid var(--soil-hi);
}

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

@media (max-width: 720px) {
  .screen--title { align-items: end; padding-bottom: 26px; }
  .lede { display: none; }
  .hud__hint { font-size: 12px; }
  .keycaps { display: none; }
  .plaque--drawer { width: 94vw; }
}

/* ---------------------------------------------------------------- language */

.langswitch {
  display: flex;
  gap: 5px;
  margin-top: 4px;
}
.hud__buttons .langswitch { margin-top: 0; margin-left: 4px; }
.langswitch button {
  min-width: 52px;
  padding: 7px 10px;
  border: 2px solid var(--soil-lo);
  border-bottom-width: 4px;
  background: var(--parchment-lo);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.langswitch button[aria-pressed='true'] {
  background: var(--turf);
  color: var(--chalk);
  border-color: var(--moss);
}
.langswitch button:hover { background: var(--parchment-hi); }
.langswitch button[aria-pressed='true']:hover { background: var(--turf-lit); color: var(--ink); }
.langswitch button:focus-visible { outline: 3px solid var(--ember); outline-offset: 2px; }

/* Chinese sets tighter: drop the wide tracking and the uppercase transform,
   neither of which suits CJK glyphs. */
html[lang^='zh'] .eyebrow,
html[lang^='zh'] .hud__index,
html[lang^='zh'] .plaque--stats dt,
html[lang^='zh'] .score dt,
html[lang^='zh'] .lab__stats span,
html[lang^='zh'] .labgroup > h3,
html[lang^='zh'] .levelcard__no,
html[lang^='zh'] .credits__body h3 {
  text-transform: none;
  letter-spacing: 0.04em;
}
html[lang^='zh'] .lede,
html[lang^='zh'] .panel__note,
html[lang^='zh'] .hud__hint,
html[lang^='zh'] .credits__body li { line-height: 1.7; }
html[lang^='zh'] .hud__concept { font-style: normal; }
html[lang^='zh'] .btn { letter-spacing: 0.02em; }
html[lang^='zh'] .lab__stats span { font-size: 10px; }

@media (prefers-reduced-motion: reduce) {
  .btn, .levelcard, .meter__fill { transition: none; }
}

/* Touch controls: a compass pad, only shown on pointer-coarse devices */
.touchpad {
  position: fixed;
  right: clamp(14px, 3vmin, 30px);
  bottom: clamp(14px, 3vmin, 30px);
  z-index: 12;
  display: none;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 5px;
}
.touchpad button {
  border: 3px solid var(--soil-lo);
  background: var(--parchment);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}
.touchpad button:active { background: var(--turf-lit); }
.touchpad .pad-up { grid-area: 1 / 2; }
.touchpad .pad-left { grid-area: 2 / 1; }
.touchpad .pad-right { grid-area: 2 / 3; }
.touchpad .pad-down { grid-area: 3 / 2; }
body.is-touch .touchpad.is-active { display: grid; }
