:root {
  color-scheme: dark;
  --ink: #f2ead7;
  --muted: #baae98;
  --tile: #1e1d19;
  --tile-2: #2a2924;
  --edge: #5c5446;
  --gold: #d8ae57;
  --steel: #a6abb2;
  --danger: #d94836;
  --blue: #38bdf8;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Trebuchet MS", Arial, sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(216,174,87,.18), transparent 34%),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 42px 42px,
    #12110f;
  color: var(--ink);
  overflow-x: hidden;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #050403;
  overflow: hidden;
}

.start-screen img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

.start-screen button {
  position: absolute;
  left: 50%;
  top: min(88vh, 88%);
  width: min(330px, 52vw);
  min-height: 56px;
  transform: translate(-50%, -50%);
  padding: 12px 24px;
  color: #241607;
  font-weight: 900;
  font-size: clamp(1.05rem, 1.9vw, 2rem);
  text-transform: uppercase;
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,.46), transparent) -180% 0 / 46% 100% no-repeat,
    linear-gradient(180deg, #fff0b8 0%, #e3aa3f 48%, #8e5715 100%);
  border: 4px solid #140d04;
  outline: 2px solid rgba(255,222,126,.75);
  box-shadow:
    0 0 0 5px rgba(63,38,10,.82),
    0 0 28px rgba(255,191,68,.52),
    0 18px 38px rgba(0,0,0,.62),
    inset 0 3px 0 rgba(255,255,255,.42),
    inset 0 -5px 0 rgba(52,30,8,.38);
  cursor: pointer;
  animation: startButtonPulse 1.65s ease-in-out infinite, startButtonShine 2.6s linear infinite;
  text-shadow: 0 2px 0 rgba(255,238,182,.45), 0 -2px 0 rgba(87,48,9,.28);
}

.start-screen button:hover {
  filter: brightness(1.12);
  animation-duration: .9s, 1.25s;
}

.start-screen button:active {
  transform: translate(-50%, -44%) scale(.97);
  box-shadow:
    0 0 0 4px rgba(63,38,10,.9),
    0 0 18px rgba(255,191,68,.45),
    0 10px 22px rgba(0,0,0,.68),
    inset 0 2px 8px rgba(54,30,8,.38);
}

@media (max-aspect-ratio: 4 / 3) {
  .start-screen button {
    top: 84%;
    width: min(320px, 70vw);
    transform: translate(-50%, -50%);
  }

  .start-screen button:active {
    transform: translate(-50%, -44%) scale(.97);
  }
}

@keyframes startButtonPulse {
  0%,
  100% {
    outline-color: rgba(255,222,126,.66);
    box-shadow:
      0 0 0 5px rgba(63,38,10,.82),
      0 0 22px rgba(255,191,68,.44),
      0 18px 38px rgba(0,0,0,.62),
      inset 0 3px 0 rgba(255,255,255,.42),
      inset 0 -5px 0 rgba(52,30,8,.38);
  }

  50% {
    outline-color: rgba(255,245,174,1);
    box-shadow:
      0 0 0 7px rgba(101,64,16,.9),
      0 0 44px rgba(255,204,83,.74),
      0 20px 42px rgba(0,0,0,.62),
      inset 0 3px 0 rgba(255,255,255,.52),
      inset 0 -5px 0 rgba(52,30,8,.34);
  }
}

@keyframes startButtonShine {
  to {
    background-position: 230% 0, 0 0;
  }
}

.game-shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 16px 0;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: center;
  justify-items: center;
  min-height: 76px;
  padding: 12px 0 18px;
  text-align: center;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4.4vw, 4.3rem);
  line-height: .9;
  color: var(--gold);
  padding: 8px 18px 10px;
  border: 2px solid rgba(216,174,87,.55);
  background: linear-gradient(180deg, rgba(34,30,22,.86), rgba(16,15,13,.72));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.04), 0 12px 34px rgba(0,0,0,.38);
  text-shadow: 0 3px 0 #3f2811, 0 0 18px rgba(255,224,144,.25), 0 8px 26px rgba(0,0,0,.6);
}

#levelName {
  color: var(--muted);
  margin-top: 7px;
  font-size: 1rem;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.stats span,
.contract-row {
  min-width: 96px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #27251f, #191814);
  border: 1px solid var(--edge);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.03), 0 8px 18px rgba(0,0,0,.18);
}

.stats b {
  display: block;
  color: #fff7da;
  font-size: 1.25rem;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.mirror-wrap {
  min-width: 0;
}

.mirror {
  position: relative;
  width: min(100%, calc(100vh - 132px));
  max-width: 850px;
  aspect-ratio: 1;
  margin: 0 auto;
  background: #24221f;
  border: 8px solid #5a5040;
  box-shadow:
    0 18px 48px rgba(0,0,0,.55),
    0 0 0 2px rgba(216,174,87,.22),
    inset 0 0 0 2px #c2b18c,
    inset 0 0 0 8px rgba(0,0,0,.24);
  overflow: hidden;
  touch-action: none;
  image-rendering: pixelated;
  cursor: none;
}

.mirror.finished {
  cursor: auto;
}

canvas,
#razorCursor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#beardCanvas,
#fxCanvas {
  pointer-events: none;
}

#razorCursor {
  width: 108px;
  height: 108px;
  inset: auto;
  transform: translate(-50%, -10%);
  object-fit: contain;
  filter: drop-shadow(0 10px 8px rgba(0,0,0,.65));
  pointer-events: none;
  opacity: .92;
  transition: opacity .12s ease, transform .12s ease;
}

.mirror.charging #razorCursor {
  opacity: .55;
}

.mirror.shaving #razorCursor {
  opacity: 1;
  transform: translate(-50%, -10%) scale(1.06);
}

.mirror.finished #razorCursor {
  opacity: 0;
}

#razorCursor.machine-cursor {
  width: 128px;
  height: 128px;
  transform: translate(-50%, -12%);
}

.mirror.shaving #razorCursor.machine-cursor {
  transform: translate(-50%, -12%) scale(1.08);
}

#razorCursor.brush-cursor {
  width: 118px;
  height: 118px;
  transform: translate(-50%, -16%) rotate(-8deg);
}

.mirror.shaving #razorCursor.brush-cursor {
  transform: translate(-50%, -16%) rotate(-8deg);
}

.progress-frame {
  width: min(100%, 850px);
  height: 18px;
  margin: 12px auto 0;
  border: 2px solid #685d49;
  background: #151412;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.04);
}

#progressBar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #c9d46d, #f1c85c, #d9803f);
  transition: width .18s ease;
}

.shop {
  display: grid;
  gap: 12px;
}

.panel {
  background: linear-gradient(180deg, rgba(38,35,29,.96), rgba(22,21,18,.96));
  border: 1px solid var(--edge);
  padding: 12px;
  box-shadow: 0 14px 30px rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,255,255,.035), 0 0 0 1px rgba(216,174,87,.08);
}

.panel h2 {
  font-size: 1rem;
  color: var(--gold);
  margin-bottom: 10px;
}

.tool {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
  color: var(--ink);
  background: linear-gradient(180deg, #2d2b25, #1f1e1a);
  border: 1px solid #6c6253;
  cursor: pointer;
  text-align: left;
  min-height: 58px;
}

.tool.active {
  border-color: var(--gold);
  background: linear-gradient(180deg, #3a3223, #242019);
  box-shadow: inset 0 0 0 2px rgba(216,174,87,.18), 0 8px 18px rgba(0,0,0,.22);
}

.tool:disabled {
  opacity: .45;
  cursor: default;
}

.tool small {
  color: var(--steel);
  white-space: nowrap;
}

.tool span {
  display: grid;
  gap: 2px;
}

.tool b {
  color: #fff3c4;
}

.tool em {
  color: var(--muted);
  font-size: .82rem;
  font-style: normal;
  line-height: 1.2;
}

.battery-box {
  margin-top: 8px;
  padding: 10px;
  background: #171713;
  border: 1px solid #514a3e;
}

.battery-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: .92rem;
}

.battery-top b {
  color: #d9f0c0;
}

.battery-track {
  height: 14px;
  margin: 8px 0;
  background: #0f100d;
  border: 1px solid #5f5748;
  overflow: hidden;
}

#batteryBar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #a8372f, #d8ae57, #86d36f);
  transition: width .18s ease;
}

.contract-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  margin-top: 8px;
}

.contract-row span {
  color: var(--muted);
}

.pressure-game {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 4;
  width: min(78%, 540px);
  transform: translateX(-50%);
  padding: 12px;
  background: rgba(20, 18, 15, .94);
  border: 2px solid var(--gold);
  box-shadow: 0 16px 34px rgba(0,0,0,.46);
}

.pressure-game[hidden],
.shave-banner[hidden] {
  display: none;
}

.pressure-title {
  color: #fff0b9;
  font-size: 1.18rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.pressure-track {
  position: relative;
  height: 28px;
  background: linear-gradient(90deg, #8e2d23, #d1873f 24%, #d8ae57 42%, #f7e08c 50%, #d8ae57 58%, #d1873f 76%, #8e2d23);
  border: 2px solid #6c6253;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.18);
}

.pressure-perfect {
  position: absolute;
  left: 45%;
  top: -5px;
  width: 10%;
  height: calc(100% + 10px);
  border-left: 2px solid #fff8c9;
  border-right: 2px solid #fff8c9;
  background: rgba(255, 244, 160, .22);
}

.pressure-needle {
  position: absolute;
  left: 0;
  top: -8px;
  width: 5px;
  height: calc(100% + 16px);
  background: #f7f2dc;
  box-shadow: 0 0 0 2px #2b2116, 0 0 16px rgba(255,255,255,.55);
}

.pressure-copy {
  color: var(--muted);
  margin-top: 8px;
  font-size: .96rem;
}

.shave-banner {
  position: absolute;
  left: 50%;
  top: 18px;
  z-index: 4;
  transform: translateX(-50%);
  padding: 8px 14px;
  color: #1e160b;
  font-weight: 700;
  background: var(--gold);
  border: 2px solid #fff0b9;
  box-shadow: 0 12px 26px rgba(0,0,0,.42);
}

.action-hint {
  position: absolute;
  left: 50%;
  top: 58px;
  z-index: 4;
  transform: translateX(-50%);
  max-width: min(82%, 560px);
  padding: 8px 12px;
  color: #fff0b9;
  background: rgba(20, 18, 15, .82);
  border: 1px solid rgba(216,174,87,.75);
  box-shadow: 0 10px 26px rgba(0,0,0,.35);
  text-align: center;
  font-size: .98rem;
}

.action-hint[hidden] {
  display: none;
}

.level-complete {
  position: absolute;
  left: 50%;
  bottom: 34px;
  z-index: 5;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "title button"
    "copy button";
  column-gap: 18px;
  row-gap: 3px;
  place-items: center;
  width: min(76%, 560px);
  padding: 12px 14px;
  background: rgba(22, 20, 17, .92);
  border: 2px solid var(--gold);
  box-shadow: 0 18px 42px rgba(0,0,0,.45);
}

.level-complete[hidden] {
  display: none;
}

.level-complete strong {
  grid-area: title;
  justify-self: start;
  font-size: clamp(1.35rem, 3vw, 2.15rem);
  color: #fff0b9;
  text-align: left;
  text-shadow: 0 3px 0 #4a2e13, 0 0 18px rgba(216,174,87,.35);
}

.level-complete p {
  grid-area: copy;
  justify-self: start;
  color: var(--muted);
  font-size: 1rem;
}

.level-complete button {
  grid-area: button;
  padding: 10px 14px;
  border: 0;
  color: #21180c;
  background: var(--gold);
  cursor: pointer;
}

@media (max-width: 850px) {
  .topbar {
    display: grid;
    align-items: center;
  }

  .stats {
    justify-content: center;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .mirror {
    width: min(100%, calc(100vh - 250px));
  }

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

@media (max-width: 560px) {
  .game-shell {
    width: min(100vw - 16px, 1180px);
  }

  .stats span {
    min-width: calc(33.333% - 6px);
  }

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

  .mirror {
    border-width: 5px;
    width: min(100%, calc(100vh - 310px));
  }

  .level-complete {
    bottom: 18px;
    width: min(88%, 420px);
    grid-template-columns: 1fr;
    grid-template-areas:
      "title"
      "copy"
      "button";
  }

  .level-complete button {
    justify-self: stretch;
  }

  .pressure-game {
    bottom: 14px;
    width: min(90%, 420px);
  }
}
