:root {
  color-scheme: light;
  font-family: "Arial Narrow", "Roboto Condensed", "Franklin Gothic Medium", Arial, sans-serif;
  --ink: #162024;
  --paper: #f5ead1;
  --paper-light: #fff9e9;
  --wall: #d9d0b8;
  --red: #cf3d32;
  --red-dark: #8e2824;
  --blue: #276578;
  --blue-dark: #173d49;
  --green: #56855c;
  --yellow: #e6b943;
  --shadow: rgba(32, 31, 24, .24);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow: hidden; }
body { color: var(--ink); background: #9f998a; user-select: none; -webkit-tap-highlight-color: transparent; }
button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.hidden { display: none !important; }

.app {
  position: relative;
  width: min(100%, 920px);
  height: 100dvh;
  min-height: 560px;
  margin: auto;
  overflow: hidden;
  display: grid;
  grid-template-rows: 48px 60px minmax(0, 1fr) 28px;
  background: var(--wall);
  box-shadow: 0 0 80px #28292370;
}

.topbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  color: var(--paper-light);
  background: var(--ink);
  border-bottom: 4px solid var(--red);
}
.home-link { color: #d8d1bf; font-size: 10px; font-weight: 900; letter-spacing: .12em; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 1000; letter-spacing: .12em; }
.brand-ze { display: grid; place-items: center; width: 30px; height: 25px; color: white; background: var(--red); transform: skew(-7deg); letter-spacing: -.05em; }
.sound-button { justify-self: end; width: 32px; height: 32px; padding: 0; border: 1px solid #eee8d455; border-radius: 50%; color: var(--paper-light); background: transparent; cursor: pointer; }
.sound-off { display: none; }
.sound-button[aria-pressed="true"] .sound-on { display: none; }
.sound-button[aria-pressed="true"] .sound-off { display: inline; }

.hud {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 1.2fr auto 1fr 1.2fr;
  align-items: stretch;
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
}
.hud-item { display: flex; align-items: baseline; justify-content: center; gap: 8px; padding: 8px 15px; border-right: 1px solid #625f5644; }
.hud-item span { color: #68675e; font-size: 9px; font-weight: 900; letter-spacing: .16em; }
.hud-item strong { font-size: 27px; line-height: 1; font-weight: 1000; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.time-panel strong { min-width: 70px; }
.time-panel.danger strong { color: var(--red); animation: time-pulse .7s ease-in-out infinite; }
.shift-light { display: flex; align-items: center; gap: 5px; padding: 0 15px; border-right: 1px solid #625f5644; }
.shift-light i { width: 7px; height: 7px; border: 1px solid #7e796b; border-radius: 50%; background: #aaa38e; }
.shift-light i:first-child { background: var(--green); box-shadow: 0 0 7px #56855c; }

.workfloor {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(270px, .84fr) minmax(430px, 1.16fr);
  overflow: hidden;
  background-color: var(--wall);
  background-image: linear-gradient(#ffffff17 1px, transparent 1px), linear-gradient(90deg, #ffffff17 1px, transparent 1px);
  background-size: 28px 28px;
}
.workfloor::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 14px 25px #4c4c3a1a; }
.wall-details { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.pipe { position: absolute; width: 16px; border: 2px solid #77766e; background: #a7a69c; box-shadow: inset 3px 0 #d3d1c4, 3px 4px 0 #595b5544; }
.pipe-one { top: -5px; bottom: 42%; left: 20px; }
.pipe-two { top: -5px; height: 90px; right: 18px; }
.notice { position: absolute; top: 12px; right: 45px; padding: 4px 7px; border: 1px solid #67645b; color: #615e53; background: #eee5cf; font-size: 8px; font-weight: 900; letter-spacing: .12em; transform: rotate(1deg); }

.incoming-station { position: relative; z-index: 2; min-width: 0; display: grid; place-items: center; align-content: center; padding: 52px 24px 32px 42px; border-right: 2px solid #777267; }
.belt-label { position: absolute; top: 24px; left: 43px; right: 24px; display: flex; align-items: center; gap: 8px; color: #625f55; font-size: 9px; font-weight: 1000; letter-spacing: .18em; }
.belt-label i { height: 1px; flex: 1; background: #777268; }
.conveyor { position: absolute; z-index: -1; left: 16px; right: 0; top: 46%; height: 88px; display: flex; gap: 11px; padding: 10px; overflow: hidden; border-block: 3px solid var(--ink); background: #4f5756; transform: translateY(-50%); }
.conveyor::before { content: ""; position: absolute; inset: 7px 0; border-block: 1px solid #adb0a7; }
.conveyor span { flex: 0 0 54px; height: 54px; margin-top: 4px; border: 2px solid #272d2d; border-radius: 50%; background: radial-gradient(circle, #858b87 0 21%, #555d5b 22% 59%, #2c3332 60% 67%, #717875 68%); }

.envelope {
  position: relative;
  width: min(100%, 350px);
  min-height: 170px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 15px 18px 14px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background-color: var(--paper-light);
  background-image: repeating-linear-gradient(135deg, transparent 0 10px, #28677b22 10px 15px, transparent 15px 25px, #c9433722 25px 30px);
  background-size: 100% 8px;
  background-repeat: no-repeat;
  box-shadow: 0 8px 0 #303531, 0 15px 24px #34372f55;
  transform: rotate(-1.2deg);
  transition: transform .18s ease, opacity .16s ease;
}
.envelope::before { content: ""; position: absolute; inset: 8px; border: 1px solid #8a83736b; pointer-events: none; }
.envelope-topline, .envelope-bottomline { z-index: 1; display: flex; justify-content: space-between; align-items: center; color: #716d61; font-size: 7px; font-weight: 900; letter-spacing: .14em; }
.word { z-index: 1; align-self: center; max-width: 100%; padding: 14px 4px 11px; overflow-wrap: anywhere; text-align: center; font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: clamp(31px, 5.2vw, 54px); font-weight: 900; line-height: .92; letter-spacing: .025em; text-transform: uppercase; }
.barcode { width: 50px; height: 13px; background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 8px); }
.stamp { position: absolute; z-index: 3; top: 50%; left: 50%; opacity: 0; padding: 5px 9px 3px; border: 4px double currentColor; border-radius: 4px; color: var(--green); font-size: 22px; font-weight: 1000; letter-spacing: .07em; white-space: nowrap; transform: translate(-50%, -50%) rotate(-10deg) scale(1.65); }
.envelope.correct .stamp, .envelope.wrong .stamp, .envelope.returned .stamp { opacity: .94; animation: stamp-in .21s cubic-bezier(.1, .9, .32, 1.15) forwards; }
.envelope.wrong .stamp { color: var(--red); }
.envelope.returned .stamp { color: var(--blue); font-size: 17px; }
.envelope.exit-bin-1 { transform: translate(56%, 65%) rotate(11deg) scale(.65); opacity: 0; }
.envelope.exit-bin-2 { transform: translate(105%, 63%) rotate(-7deg) scale(.65); opacity: 0; }
.envelope.exit-bin-3 { transform: translate(60%, 110%) rotate(-5deg) scale(.65); opacity: 0; }
.envelope.exit-bin-4 { transform: translate(108%, 110%) rotate(8deg) scale(.65); opacity: 0; }
.envelope.exit-return { transform: translate(-75%, 10%) rotate(-13deg) scale(.72); opacity: 0; }
.envelope.wrong { animation: envelope-shake .2s ease; }
.envelope.arriving { animation: envelope-arrive .2s ease-out; }
.feedback { position: absolute; z-index: 5; top: calc(50% - 118px); left: 50%; min-width: 110px; opacity: 0; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 2px; color: white; background: var(--green); box-shadow: 3px 3px 0 var(--ink); text-align: center; font-size: 11px; font-weight: 1000; letter-spacing: .08em; pointer-events: none; transform: translateX(-50%) translateY(10px) rotate(-2deg); }
.feedback.show { opacity: 1; animation: feedback-pop .4s ease both; }
.feedback.bad { background: var(--red); }

.sorting-desk { position: relative; z-index: 2; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 34px 32px 28px; background: #bdb6a5a6; }
.desk-instruction { margin: 0; color: #5f5c52; font-size: 9px; font-weight: 1000; letter-spacing: .17em; text-align: center; }
.bins { min-height: 250px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.bin {
  position: relative;
  min-width: 0;
  min-height: 116px;
  display: grid;
  grid-template-rows: 18px 1fr auto;
  align-items: center;
  padding: 12px 12px 13px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 4px 4px 8px 8px;
  color: var(--paper-light);
  background: var(--blue);
  box-shadow: inset 0 -9px #0000001a, 0 6px 0 var(--blue-dark), 0 10px 13px var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .1s ease, filter .1s ease;
}
.bin:nth-child(even) { background: #2e7184; }
.bin::after { content: ""; position: absolute; inset: 5px; border: 1px solid #ffffff2d; border-radius: 2px 2px 6px 6px; pointer-events: none; }
.bin .key { position: absolute; z-index: 2; top: 8px; left: 9px; width: 21px; height: 21px; display: grid; place-items: center; border: 1px solid #fff7df9c; border-radius: 3px; color: #fff9e8; background: #163c47aa; font-family: Arial, sans-serif; font-size: 10px; font-weight: 900; }
.bin .slot { position: relative; z-index: 1; width: 65%; height: 12px; align-self: start; justify-self: center; border: 2px solid #102d35; border-radius: 99px; background: #0e2931; box-shadow: inset 0 3px 2px #0009, 0 1px #ffffff46; }
.bin strong { z-index: 1; align-self: end; font-size: clamp(15px, 2.3vw, 23px); line-height: 1; letter-spacing: -.025em; text-transform: uppercase; overflow-wrap: anywhere; }
.bin small { z-index: 1; color: #dce8e5; font-size: 8px; font-weight: 900; letter-spacing: .15em; }
.bin:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-2px); }
.bin:active:not(:disabled), .bin.hit { transform: translateY(5px); box-shadow: inset 0 -5px #0000001a, 0 1px 0 var(--blue-dark); }
.bin.wrong-hit { animation: bin-shake .2s ease; background: var(--red); }
.bin:disabled { cursor: default; }

.return-button { min-height: 59px; display: grid; grid-template-columns: 40px 1fr 28px; align-items: center; gap: 10px; padding: 7px 12px; border: 2px solid var(--ink); border-radius: 3px; color: var(--paper-light); background: var(--red); box-shadow: 0 5px 0 var(--red-dark), 0 9px 13px var(--shadow); text-align: left; cursor: pointer; touch-action: manipulation; }
.return-button:hover:not(:disabled) { filter: brightness(1.06); }
.return-button:active:not(:disabled), .return-button.hit { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-dark); }
.return-button.wrong-hit { animation: bin-shake .2s ease; filter: saturate(.4); }
.return-icon { font-size: 31px; line-height: 1; text-align: center; }
.return-button strong, .return-button small { display: block; }
.return-button strong { font-size: 14px; letter-spacing: .06em; }
.return-button small { margin-top: 2px; color: #f5d8ce; font-size: 8px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
kbd { display: grid; place-items: center; width: 24px; height: 24px; border: 1px solid #fff9e999; border-radius: 3px; background: #85282066; box-shadow: none; font-family: Arial, sans-serif; font-size: 10px; font-weight: 900; }

.footer-strip { z-index: 6; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 13px; color: #dbd5c5; background: #353a39; font-size: 7px; font-weight: 900; letter-spacing: .14em; }
.footer-strip > :last-child { justify-self: end; }
.seed-label { padding: 3px 10px; color: #222926; background: #c7c0af; transform: skew(-5deg); }

.overlay { position: absolute; z-index: 30; inset: 48px 0 28px; display: grid; place-items: center; padding: 18px; background: #17211f99; backdrop-filter: blur(4px); transition: opacity .2s ease; }
.overlay.dismissed { opacity: 0; pointer-events: none; }
.modal { position: relative; width: min(100%, 470px); max-height: 100%; overflow: auto; padding: clamp(24px, 5vh, 38px) clamp(22px, 6vw, 45px); border: 3px solid var(--ink); border-radius: 5px; background-color: var(--paper-light); background-image: repeating-linear-gradient(135deg, transparent 0 12px, #27657814 12px 18px, transparent 18px 30px, #cf3d3214 30px 36px); background-size: 100% 9px; background-repeat: no-repeat; box-shadow: 10px 10px 0 var(--ink); text-align: center; transform: rotate(-.4deg); }
.postal-mark { width: 72px; height: 72px; display: grid; grid-template-columns: 1fr 23px; align-items: center; margin: 0 auto 13px; border: 4px double var(--red); border-radius: 50%; color: var(--red); font-weight: 1000; transform: rotate(-7deg); }
.postal-mark span { font-size: 27px; letter-spacing: -.08em; }
.postal-mark i { font-size: 18px; font-style: normal; }
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: 9px; font-weight: 1000; letter-spacing: .2em; }
h1, h2 { margin: 0; font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-weight: 900; line-height: .88; letter-spacing: .035em; }
h1 { font-size: clamp(50px, 13vw, 76px); }
h2 { font-size: clamp(36px, 9vw, 53px); }
.intro { max-width: 340px; margin: 17px auto 18px; color: #5e5d55; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.45; }
.rules { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 21px; border-block: 1px dashed #8c8678; }
.rules span { padding: 11px 5px; color: #666258; font-size: 8px; font-weight: 900; letter-spacing: .1em; }
.rules b { display: block; margin-bottom: 2px; color: var(--ink); font-size: 17px; }
.primary-button, .secondary-button { min-height: 45px; padding: 10px 18px; border: 2px solid var(--ink); border-radius: 3px; font-weight: 1000; letter-spacing: .08em; cursor: pointer; touch-action: manipulation; }
.primary-button { color: white; background: var(--red); box-shadow: 0 5px 0 var(--red-dark); }
.primary-button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-dark); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.start-modal .primary-button { width: min(100%, 270px); }
.challenge { margin: 16px 0 0; color: #777268; font-size: 8px; font-weight: 900; letter-spacing: .13em; }
.challenge strong { color: var(--ink); }

.result-modal { padding-top: 32px; }
.complete-stamp { display: inline-block; margin: 0 auto 13px; padding: 5px 8px 3px; border: 4px double var(--green); color: var(--green); font-size: 15px; font-weight: 1000; letter-spacing: .08em; transform: rotate(-4deg); }
.final-score { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 17px 0 14px; }
.final-score span { font-size: 10px; font-weight: 900; letter-spacing: .15em; }
.final-score strong { font-size: 44px; line-height: 1; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.final-score small { align-self: flex-start; display: none; padding: 3px 5px; color: white; background: var(--green); font-size: 7px; font-weight: 900; letter-spacing: .08em; transform: rotate(3deg); }
.final-score small.show { display: inline; }
.results-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0 0 20px; border-block: 1px solid #aaa394; }
.results-grid div { padding: 11px 5px; border-right: 1px solid #c6bead; }
.results-grid div:last-child { border-right: 0; }
.results-grid dt { color: #736f64; font-size: 7px; font-weight: 900; letter-spacing: .08em; }
.results-grid dd { margin: 4px 0 0; font-size: 21px; font-weight: 1000; }
.result-actions { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; }
.secondary-button { background: #e3dac5; box-shadow: 0 4px 0 #827e73; font-size: 10px; }
.secondary-button:active { transform: translateY(3px); box-shadow: 0 1px 0 #827e73; }
.share-button.copied { color: white; background: var(--green); }

.loading-error { position: absolute; z-index: 40; left: 50%; bottom: 42px; width: min(90%, 420px); display: grid; gap: 2px; padding: 12px 15px; border: 2px solid var(--ink); color: white; background: var(--red); box-shadow: 4px 4px 0 var(--ink); transform: translateX(-50%); text-align: center; }
.loading-error span { font-family: Arial, sans-serif; font-size: 11px; }

@keyframes envelope-arrive { from { opacity: 0; transform: translateX(-45%) rotate(-4deg) scale(.88); } }
@keyframes envelope-shake { 25% { transform: translateX(-6px) rotate(-3deg); } 60% { transform: translateX(6px) rotate(2deg); } }
@keyframes stamp-in { to { transform: translate(-50%, -50%) rotate(-10deg) scale(1); } }
@keyframes feedback-pop { 0% { opacity: 0; transform: translateX(-50%) translateY(10px) rotate(-2deg) scale(.85); } 25%, 75% { opacity: 1; transform: translateX(-50%) translateY(0) rotate(-2deg) scale(1); } 100% { opacity: 0; transform: translateX(-50%) translateY(-9px) rotate(-2deg); } }
@keyframes bin-shake { 33% { transform: translateX(-5px); } 66% { transform: translateX(5px); } }
@keyframes time-pulse { 50% { opacity: .55; } }

@media (max-width: 680px) {
  .app { min-height: 520px; grid-template-rows: 44px 52px minmax(0, 1fr) 24px; }
  .topbar { padding: 0 10px; }
  .brand { font-size: 13px; }
  .brand-ze { width: 26px; height: 22px; }
  .hud { grid-template-columns: 1.2fr .8fr 1.2fr; }
  .shift-light { display: none; }
  .hud-item { gap: 5px; padding: 6px 8px; }
  .hud-item strong { font-size: 22px; }
  .hud-item span { font-size: 7px; }
  .time-panel strong { min-width: 57px; }
  .workfloor { grid-template-columns: 1fr; grid-template-rows: minmax(178px, .8fr) minmax(282px, 1.2fr); overflow: hidden; }
  .incoming-station { padding: 31px 40px 19px; border-right: 0; border-bottom: 2px solid #777267; }
  .belt-label { top: 10px; left: 40px; right: 40px; }
  .conveyor { left: 0; top: 53%; height: 69px; }
  .conveyor span { flex-basis: 43px; height: 43px; margin-top: 1px; }
  .envelope { width: min(100%, 310px); min-height: 124px; padding: 12px 16px 10px; box-shadow: 0 6px 0 #303531, 0 11px 18px #34372f55; }
  .word { padding: 9px 3px 7px; font-size: clamp(28px, 9.8vw, 42px); }
  .feedback { top: 10px; }
  .sorting-desk { gap: 7px; padding: 13px 18px 15px; }
  .bins { min-height: 0; flex: 1; gap: 9px; }
  .bin { min-height: 82px; grid-template-rows: 14px 1fr auto; padding: 8px 8px 9px; box-shadow: inset 0 -6px #0000001a, 0 4px 0 var(--blue-dark); }
  .bin .key { top: 6px; left: 7px; width: 18px; height: 18px; }
  .bin .slot { height: 9px; }
  .bin strong { font-size: clamp(14px, 4.6vw, 20px); }
  .return-button { min-height: 50px; grid-template-columns: 33px 1fr 26px; }
  .return-icon { font-size: 26px; }
  .footer-strip { font-size: 6px; }
  .overlay { inset: 44px 0 24px; padding: 13px; }
  .modal { padding: 23px 20px; box-shadow: 7px 7px 0 var(--ink); }
  .results-grid { grid-template-columns: repeat(2, 1fr); }
  .results-grid div:nth-child(2) { border-right: 0; }
  .results-grid div:nth-child(-n+2) { border-bottom: 1px solid #c6bead; }
  .result-actions { grid-template-columns: repeat(2, 1fr); }
  .result-actions .primary-button { grid-column: 1 / -1; }
}

@media (max-height: 700px) and (min-width: 681px) {
  .incoming-station { padding-top: 38px; }
  .envelope { min-height: 145px; }
  .sorting-desk { padding-block: 19px; }
  .bins { min-height: 210px; }
  .bin { min-height: 96px; }
}

@media (max-height: 620px) and (max-width: 680px) {
  .app { min-height: 480px; grid-template-rows: 40px 45px minmax(0, 1fr) 22px; }
  .workfloor { grid-template-rows: minmax(145px, .72fr) minmax(250px, 1.28fr); }
  .incoming-station { padding: 27px 48px 13px; }
  .envelope { min-height: 105px; }
  .envelope-topline, .envelope-bottomline { font-size: 6px; }
  .word { padding: 5px 2px; font-size: clamp(25px, 8.5vw, 36px); }
  .sorting-desk { padding: 8px 15px 10px; }
  .desk-instruction { display: none; }
  .bin { min-height: 72px; }
  .return-button { min-height: 44px; }
  .postal-mark { width: 54px; height: 54px; }
  .intro { margin-block: 11px; }
  .rules { margin-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
