:root {
  --ink: #e8e2d4;
  --muted: #a39886;
  --paper: #14120f;
  --panel: #1c1915;
  --line: #2e2922;
  --light: #f2d48a;
  --light-deep: #c9a15a;
  --dark: #c45a6a;
  --good: #7dcea0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  overflow: hidden;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

h1 {
  margin: 0;
  font-weight: 500;
  letter-spacing: 0.01em;
  font-size: 22px;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.meter {
  position: relative;
  width: 280px;
  height: 28px;
  border: 1px solid var(--line);
  background: #2a1218;
  flex: none;
}

.meter-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #8a6a32, var(--light));
}

#meter-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 2px #000;
}

#stage {
  position: relative;
  border: 1px solid var(--line);
  background: #0e0d0b;
  line-height: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  cursor: crosshair;
}

#overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 8, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
}

#overlay[hidden] { display: none; }

#overlay-card {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 28px 32px;
  max-width: 420px;
  text-align: center;
}

#overlay-card h2 {
  margin: 0 0 8px;
  font-weight: 500;
}

#overlay-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

button {
  font-family: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
}

button:hover { border-color: var(--muted); }

footer {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

.tools {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.tool {
  text-align: left;
  padding: 8px 10px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tool.selected {
  border-color: var(--light-deep);
  background: #262117;
}

.tool:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool-name { font-size: 16px; }

.tool-cost {
  color: var(--light);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.tool-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 4px;
}

.status {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.energy-top, .buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.energy-track {
  height: 8px;
  background: #2a2418;
  border: 1px solid var(--line);
  margin-top: 4px;
}

.energy-fill {
  height: 100%;
  width: 100%;
  background: var(--light-deep);
}

.energy-note, #hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

#clock {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 20px;
}

#pause, #restart, #overlay-again {
  padding: 6px 14px;
}

.speeds {
  display: flex;
  gap: 6px;
}

.speed {
  padding: 6px 10px;
  min-width: 36px;
  text-align: center;
}

.speed.selected {
  border-color: var(--light-deep);
  background: #262117;
}

@media (max-width: 800px) {
  header, footer { display: flex; flex-direction: column; }
  .meter { width: 100%; }
  .tools { grid-template-columns: 1fr; }
}
