:root {
  --ink: #2b2019;
  --paper: #fdfcf8;
  --panel: #f5f1e8;
  --line: #e3dccb;
  --accent: #b5432a;
  --gold: #c9a227;
  --muted: #8a7b6a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.45;
}

header {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 18px 200px 10px 28px;
  border-bottom: 3px solid var(--accent);
}

h1 { margin: 0; font-size: 30px; letter-spacing: 0.2px; }
.subtitle { font-size: 19px; font-style: italic; color: var(--muted); font-weight: normal; }
.credit { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.credit a { color: var(--accent); }

.funsmith-badge {
  position: absolute;
  top: 14px;
  right: 28px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 2px solid #5865f2;
  border-radius: 8px;
  background: #fff;
  color: #5865f2;
  font-weight: bold;
  font-size: 14px;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(88, 101, 242, 0.15);
}
.funsmith-badge:hover { background: #5865f2; color: #fff; }

main {
  display: flex;
  gap: 22px;
  padding: 18px 28px 30px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.stage-col { flex: 1 1 640px; min-width: 540px; }
.side-col  { flex: 0 1 340px; min-width: 300px; display: flex; flex-direction: column; gap: 14px; }

/* ---- phase cards (windup / active / recovery) ---- */
.phase-cards { display: flex; gap: 12px; margin-bottom: 12px; }
.phase-card {
  flex: 1;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  opacity: 0.5;
  transition: opacity 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.phase-card h3 { margin: 0 0 3px; font-size: 15px; color: var(--accent); }
.phase-card .ph-t { font-size: 11px; color: var(--muted); font-weight: normal; float: right; }
.phase-card p { margin: 0; font-size: 11.5px; color: var(--muted); }
.phase-card.active {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(181, 67, 42, 0.18);
}

/* ---- canvas ---- */
.canvas-wrap { position: relative; }
canvas#game {
  display: block;
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #0d0c0b;
}
.ip-note {
  margin: 0 28px 20px;
  font-size: 11.5px;
  color: var(--muted);
}
.demo-pill {
  position: absolute;
  top: 10px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.demo-pill input { accent-color: var(--accent); margin: 0; }
.demo-pill:has(input:checked) { border-color: var(--accent); color: var(--accent); }

.freeze-badge {
  position: absolute;
  top: 10px; right: 12px;
  background: var(--gold);
  color: #2b2019;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 1.5px;
  padding: 3px 10px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.05s;
}
.freeze-badge.on { opacity: 1; }

.attack-btn {
  position: absolute;
  bottom: 12px; right: 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 #7d2c1a;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.attack-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #7d2c1a; }
.attack-btn kbd { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.4); color: #fff; }

.stats-bar { margin-top: 8px; font-size: 14px; }
.controls-hint { font-size: 12px; color: var(--muted); }
kbd {
  font-family: inherit;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  padding: 0 5px;
  font-size: 11px;
}

/* ---- explainer ---- */
.explainer {
  background: #fff;
  border: 2px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
}
.explainer h2 { margin: 0 0 6px; font-size: 19px; color: var(--accent); }
.explainer p { margin: 0 0 8px; }
.explainer p:last-child { margin-bottom: 0; }
.explainer .rule { background: var(--panel); border-radius: 6px; padding: 6px 10px; font-size: 13px; }

/* ---- layer toggles ---- */
.layers {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px 12px;
}
.layers-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.layers h4 { margin: 0; font-size: 15px; }
.layers-sub { font-size: 11px; color: var(--muted); font-weight: normal; font-style: italic; }
#reset-btn {
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 5px;
  padding: 2px 10px;
  cursor: pointer;
}
#reset-btn:hover { border-color: var(--accent); color: var(--accent); }

.layer {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.layer:hover { background: var(--panel); }
.layer input { display: none; }
.layer .key {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: bold;
  width: 18px; height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 4px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
}
.layer .body { flex: 1; }
.layer .name { font-size: 13.5px; }
.layer .desc { display: block; font-size: 11px; color: var(--muted); line-height: 1.3; }
.layer.on .key { background: var(--accent); color: #fff; border-color: var(--accent); }
.layer.off .name { color: var(--muted); text-decoration: line-through; }

/* ---- sound pill ---- */
.sound-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.sound-pill em { color: var(--muted); font-size: 12px; }
.sound-pill input { accent-color: var(--accent); }
.sound-pill:has(input:checked) { border-color: var(--accent); }

/* ---- contact-frame code ---- */
.pseudo-box {
  background: #2b2019;
  color: #f2e8d8;
  border-radius: 8px;
  padding: 10px 14px 12px;
}
.pseudo-box h4 { margin: 0 0 6px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--gold); }
.pseudo-box pre {
  margin: 0;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.pseudo-box .hl { color: #f0a35e; }
.pseudo-box .off { color: #6f6355; text-decoration: line-through; }

/* ---- responsive ---- */
@media (max-width: 980px) {
  header { flex-direction: column; align-items: stretch; gap: 8px; padding-right: 12px; }
  .funsmith-badge { top: 10px; right: 12px; }
  .title-block { padding-right: 160px; }
  .stage-col { min-width: 100%; }
  .side-col { min-width: 100%; }
}
@media (max-width: 640px) {
  header { padding: 10px 12px 0; }
  .funsmith-badge { font-size: 12px; padding: 5px 10px; gap: 5px; }
  .title-block { padding-right: 152px; }
  h1 { font-size: 20px; }
  .subtitle { font-size: 13px; }
  main { padding: 10px 10px 24px; gap: 12px; }
  .phase-cards { gap: 6px; }
  .phase-card p { display: none; }
  .attack-btn { font-size: 13px; padding: 7px 12px; }
}
