:root {
  --ink: #24252b;
  --cream: #fff5e3;
  --paper: #fbeeda;
  --teal: #1f4a4c;
  --teal-deep: #173739;
  --gold: #f2c14e;
  --tomato: #c23c22;
  --line: rgba(36, 37, 43, 0.14);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--teal-deep);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  text-align: center;
  color: var(--cream);
  font-size: 18px;
}
#splash p { margin: 0; }
.logo { font-size: clamp(30px, 8vw, 54px); font-weight: 800; color: var(--gold); }

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(circle, rgba(0, 0, 0, 0.22) 2.4px, transparent 3px) 0 0 / 28px 28px,
    linear-gradient(var(--teal), var(--teal-deep));
}

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 6px;
}

.pill {
  flex: none;
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
}
button.pill { cursor: pointer; }
.status { color: var(--tomato); letter-spacing: 1px; }
.coins::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 0 0 2px #b98a1e;
}

#bench { position: relative; min-height: 0; }
#work {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  background: var(--paper);
}
#hint { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.25; }

.btn {
  min-height: 44px;
  padding: 9px 14px;
  border: 0;
  border-radius: 8px;
  background: #eadcc4;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.btn.primary { background: var(--tomato); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, .pill:focus-visible, .level:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

#panel-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(15, 27, 28, 0.62);
}
#panel {
  display: grid;
  gap: 12px;
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 12px;
  background: var(--cream);
  text-align: center;
  animation: rise 220ms ease-out;
}
#panel h1 { margin: 0; font-size: 28px; line-height: 1.1; }
#panel p { margin: 0; font-size: 17px; line-height: 1.35; }
#panel .stat { font-weight: 800; }
#panel .quote { font-style: italic; }
#panel .stars { font-size: 42px; line-height: 1; color: #b87f0d; }
.portrait { width: 88px; height: 88px; justify-self: center; }

.levels { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.level {
  display: grid;
  align-content: center;
  min-height: 48px;
  padding: 3px 0;
  border: 0;
  border-radius: 6px;
  background: #eadcc4;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.level span { min-height: 12px; color: #9a6a08; font-size: 10px; line-height: 12px; }
.level:disabled { opacity: 0.4; cursor: default; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
}

@media (max-height: 460px) {
  #hud { padding-top: 4px; padding-bottom: 3px; }
  #tools { padding-top: 4px; padding-bottom: 4px; }
  #hint { font-size: 13px; }
  #panel { gap: 8px; padding: 14px; }
  #panel h1 { font-size: 22px; }
  #panel p { font-size: 15px; }
  .portrait { width: 52px; height: 52px; }
  .levels { grid-template-columns: repeat(10, minmax(0, 1fr)); }
}

@media (max-width: 400px) {
  #tools { grid-template-columns: 1fr 1fr; }
  #hint { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  #panel { animation: none; }
}
