:root {
  --ink: #e8e0c7;
  --muted: #a9a08a;
  --paper: #171711;
  --panel: #121610;
  --line: rgba(235, 204, 141, 0.22);
  --accent: #8caf54;
  --accent-2: #d0784f;
  --sand: #d9c9a8;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
  font-family:
    "Yu Gothic UI", "Yu Gothic", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(140, 175, 84, 0.16), transparent 34%),
    linear-gradient(120deg, rgba(121, 77, 44, 0.22), transparent 42%),
    repeating-linear-gradient(0deg, rgba(235, 204, 141, 0.045) 0 1px, transparent 1px 32px),
    #0d0f0b;
}

button {
  font: inherit;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 22px;
  padding: 22px;
}

.stage-panel {
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 14px;
}

.topbar p {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 48px);
  letter-spacing: 0;
}

h1 small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 15px;
}

.meters {
  display: grid;
  grid-template-columns: repeat(2, minmax(100px, 1fr));
  gap: 10px;
}

.meters div,
.control-panel {
  background: rgba(20, 23, 16, 0.88);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.meters div {
  min-height: 64px;
  padding: 12px;
  border-radius: 8px;
  backdrop-filter: blur(6px);
}

.meters span,
.stat-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meters strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
  color: #f0d47e;
}

canvas {
  display: block;
  width: 100%;
  height: calc(100vh - 122px);
  min-height: 520px;
  background: #d8cbb5;
  border: 1px solid rgba(235, 204, 141, 0.28);
  border-radius: 8px;
  box-shadow: var(--shadow);
  touch-action: none;
}

.control-panel {
  align-self: start;
  min-height: calc(100vh - 44px);
  padding: 18px;
  color: #f8f5e9;
  background: var(--panel);
  border-color: rgba(235, 204, 141, 0.18);
  border-radius: 8px;
}

.panel-section {
  padding: 0 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.panel-section:last-child {
  margin-bottom: 0;
  border-bottom: 0;
}

.panel-section h2 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #f0d47e;
  letter-spacing: 0.08em;
}

.leg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.key-card {
  min-height: 74px;
  padding: 12px;
  color: #f8f5e9;
  background: rgba(255, 255, 255, 0.075);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  text-align: left;
  touch-action: none;
  user-select: none;
}

.key-card.active {
  color: #172018;
  background: #c9dcaa;
  border-color: #dfeac8;
}

kbd {
  display: block;
  width: 32px;
  height: 32px;
  margin-bottom: 8px;
  color: #172018;
  background: #e9d18d;
  border-radius: 6px;
  text-align: center;
  line-height: 32px;
  font-weight: 900;
}

.key-card span {
  font-size: 13px;
  font-weight: 800;
}

.key-card small {
  color: rgba(248, 245, 233, 0.72);
  font-size: 11px;
}

.turn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.gait-guide {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: stretch;
  margin-top: 12px;
}

.guide-step {
  min-width: 0;
  padding: 10px;
  color: rgba(248, 245, 233, 0.78);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease,
    color 160ms ease;
}

.guide-step span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.guide-step strong {
  display: block;
  margin-top: 5px;
  color: #f0d47e;
  font-size: 21px;
  line-height: 1;
}

.guide-step small {
  display: block;
  margin-top: 7px;
  color: rgba(248, 245, 233, 0.64);
  font-size: 10px;
  line-height: 1.45;
}

.guide-step.phase-done {
  border-color: rgba(140, 175, 84, 0.45);
  background: rgba(103, 126, 67, 0.22);
}

.guide-step.phase-next {
  color: #172018;
  background: #d8c989;
  border-color: #f0d47e;
  transform: translateY(-1px);
}

.guide-step.phase-next span,
.guide-step.phase-next small,
.guide-step.phase-next strong {
  color: #172018;
}

.guide-arrow {
  display: grid;
  place-items: center;
  color: #f0d47e;
  font-weight: 900;
}

.mini-help {
  margin: 12px 0 0;
  color: rgba(248, 245, 233, 0.68);
  font-size: 12px;
  line-height: 1.6;
}

.step-log {
  display: grid;
  gap: 6px;
  min-height: 172px;
}

.log-line {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 26px;
  padding: 5px 7px;
  color: #e4e7da;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 6px;
  font-size: 12px;
}

.log-line.good {
  color: #f8f5e9;
  background: rgba(95, 124, 69, 0.5);
}

.log-line.bad {
  color: #fff0e8;
  background: rgba(182, 95, 69, 0.45);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-row strong {
  font-size: 18px;
}

#resetButton {
  width: 100%;
  min-height: 42px;
  margin-top: 10px;
  color: #172018;
  background: #e8bf68;
  border: 0;
  border-radius: 6px;
  font-weight: 900;
}

.device-note {
  margin-top: 18px;
  padding: 16px;
  color: #d6cfb8;
  background: rgba(20, 23, 16, 0.84);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.device-note h2 {
  margin: 0 0 10px;
  color: #f0d47e;
  font-size: 15px;
  letter-spacing: 0.08em;
}

.device-note h2 small {
  color: var(--muted);
  letter-spacing: 0;
}

.device-note p {
  display: grid;
  gap: 3px;
  margin: 0 0 10px;
  line-height: 1.75;
}

.device-note p:last-child {
  margin-bottom: 0;
}

.detail-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.detail-card {
  min-width: 0;
  padding: 16px;
  color: #d6cfb8;
  background: rgba(20, 23, 16, 0.84);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.detail-card h2 {
  margin: 0 0 10px;
  color: #f0d47e;
  font-size: 18px;
  line-height: 1.45;
}

.detail-card p,
.detail-card li {
  color: #d6cfb8;
  font-size: 14px;
  line-height: 1.75;
}

.detail-card p {
  margin: 0 0 8px;
}

.detail-card p:last-child {
  margin-bottom: 0;
}

.detail-card ol {
  margin: 0;
  padding-left: 1.25em;
}

.detail-card strong {
  color: #f0d47e;
}

.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.detail-links a,
.lab-footer a {
  color: #172018;
  background: #e8bf68;
  border-radius: 6px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.detail-links a {
  padding: 9px 11px;
}

.lab-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 22px 22px;
  padding: 16px 18px;
  color: var(--muted);
  background: rgba(20, 23, 16, 0.72);
  border: 1px solid rgba(235, 204, 141, 0.16);
  border-radius: 8px;
}

.lab-footer span {
  color: #f8f5e9;
  font-weight: 800;
}

.lab-footer a {
  padding: 8px 10px;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    min-height: 0;
  }

  canvas {
    height: 62vh;
    min-height: 420px;
  }

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

@media (max-width: 620px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    display: block;
  }

  .meters {
    margin-top: 12px;
    grid-template-columns: 1fr 1fr;
  }

  .gait-guide {
    grid-template-columns: 1fr;
  }

  .guide-arrow {
    min-height: 20px;
    transform: rotate(90deg);
  }

  canvas {
    height: 52vh;
    min-height: 340px;
  }

  .detail-card {
    padding: 14px;
  }

  .lab-footer {
    display: block;
    margin: 0 14px 14px;
  }

  .lab-footer a {
    display: inline-block;
    margin-top: 10px;
  }
}
