:root {
  --bg: #1b1814;
  --panel: #25211b;
  --panel-border: #3b342a;
  --text: #f1ebe0;
  --muted: #b3a792;
  --accent: #e0a458;
  --focus: #8fd3ff;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

header, footer {
  padding: 1rem 1.25rem 0.5rem;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: normal;
  letter-spacing: 0.02em;
}

.subtitle, footer {
  color: var(--muted);
  margin: 0.25rem 0 0;
}

footer {
  font-size: 0.9rem;
  max-width: 60rem;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  gap: 1rem;
  padding: 0.5rem 1.25rem 1rem;
  align-items: start;
}

.paper-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: calc(100vh - 10rem);
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.45);
}

.paper-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.status {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.buttons, .inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.controls {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.control-row.inline {
  flex-direction: row;
}

label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.25rem;
}

label > input[type="range"] {
  flex-basis: 100%;
}

output {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

select, button {
  font: inherit;
  color: var(--text);
  background: #312b23;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
}

button {
  cursor: pointer;
}

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

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.readout {
  margin: 0;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.ratio, .pendulums {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem 0.7rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ratio legend, .pendulums legend {
  padding: 0 0.3rem;
}

#pendulum-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.pendulum {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px dashed var(--panel-border);
  font-size: 0.92rem;
}

.pendulum-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.pendulum-head label {
  justify-content: flex-start;
  gap: 0.5rem;
}

.remove {
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
}

.gallery {
  margin-top: 1rem;
}

.gallery-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.gallery-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: normal;
  font-size: 1.2rem;
}

.gallery-list {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: 0.6rem;
}

.gallery-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.gallery-load {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem;
}

.gallery-load canvas {
  width: 96px;
  height: 96px;
  border-radius: 4px;
}

.gallery-name {
  font-size: 0.8rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-remove {
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  color: var(--muted);
}

kbd {
  font-family: ui-monospace, Consolas, monospace;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0 0.25rem;
}

@media (max-width: 820px) {
  main {
    grid-template-columns: 1fr;
  }
  .paper-wrap {
    max-height: none;
  }
}
