:root {
  color-scheme: light;
  --paper: #fffaf0;
  --paper-deep: #f7e7c6;
  --ink: #2b251d;
  --muted: #736651;
  --line: #dfc895;
  --green: #4f8f63;
  --green-deep: #2f6844;
  --yellow: #f2c75c;
  --red: #c65b4a;
  --board: #173b31;
  --board-deep: #0d2823;
  --chalk: #fff7dc;
  --dust: 1;
  --crumble: 0;
  --shadow: 0 18px 44px rgba(101, 75, 32, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
}

body {
  background:
    linear-gradient(180deg, rgba(79, 143, 99, 0.15), transparent 360px),
    repeating-linear-gradient(90deg, rgba(223, 200, 149, 0.2) 0 1px, transparent 1px 72px),
    var(--paper);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
  line-height: 1.7;
  margin: 0;
  min-width: 0;
}

a {
  color: inherit;
}

.site-header,
.site-footer {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1120px;
  padding: 14px 18px;
}

.brand,
.site-footer a,
.related-list a {
  color: var(--green-deep);
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.site-header p {
  color: var(--muted);
  margin: 0;
}

.app-shell {
  display: grid;
  gap: 14px;
  margin: 0 auto;
  max-width: 1120px;
  padding: 0 18px 36px;
}

.mode-toolbar,
.chalk-panel,
.input-panel,
.metrics-panel,
.result-panel,
.related-panel,
.prompt-panel {
  background: rgba(255, 253, 250, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 14px;
}

.mode-toolbar {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
}

.mode-titlebar {
  background: #fff7e4;
  border: 1px solid rgba(115, 102, 81, 0.18);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.eyebrow {
  color: var(--green-deep);
  font-size: 0.76rem;
  font-weight: 900;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2.1rem, 5.5vw, 4.6rem);
  line-height: 1.05;
  margin-bottom: 6px;
}

h2 {
  font-size: clamp(1.3rem, 3vw, 2rem);
  margin-bottom: 8px;
}

.lead {
  color: var(--green-deep);
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  font-weight: 900;
  margin: 0;
}

.control-panel {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

fieldset {
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  min-width: 0;
  padding: 8px 10px;
}

legend {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  padding: 0 4px;
}

label {
  font-weight: 800;
}

button {
  align-items: center;
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 900;
  justify-content: center;
  min-height: 40px;
  padding: 8px 12px;
}

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

#start-button {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.play-layout {
  display: grid;
  gap: 12px;
}

.chalk-panel {
  --state: var(--green);
  background: #fff7e4;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.chalk-panel[data-state="crumbling"],
.chalk-panel[data-state="dust"] {
  --state: var(--yellow);
}

.chalk-panel[data-state="dustout"] {
  --state: var(--red);
}

.chalk-panel[data-state="copied"],
.chalk-panel[data-state="complete"] {
  --state: var(--green);
}

.status-strip {
  align-items: center;
  background: rgba(23, 59, 49, 0.08);
  border: 1px solid rgba(47, 104, 68, 0.24);
  border-left: 6px solid var(--state);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-height: 48px;
  padding: 6px 12px;
}

#status-code {
  color: var(--green-deep);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

#status-message {
  font-size: 1rem;
  font-weight: 900;
  white-space: nowrap;
}

#status-message::before,
#status-help::before {
  color: rgba(81, 70, 51, 0.45);
  content: "·";
  margin-right: 8px;
}

#status-help {
  color: var(--muted);
  min-width: 0;
}

.chalk-stage {
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.07), transparent 22%),
    linear-gradient(180deg, var(--board), var(--board-deep));
  border: 10px solid #8b673f;
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px rgba(255, 250, 240, 0.08);
  display: grid;
  height: clamp(330px, 47vh, 520px);
  overflow: hidden;
  place-items: center;
  position: relative;
}

.chalk-canvas {
  display: block;
  height: 100%;
  inset: 0;
  position: absolute;
  width: 100%;
  z-index: 1;
}

.chalk-board-lines {
  background:
    linear-gradient(transparent 92%, rgba(255,255,255,0.08) 93%, transparent 100%),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,0.06), transparent 25%);
  background-size: 100% 68px, auto;
  inset: 0;
  opacity: 0.42;
  position: absolute;
  z-index: 0;
}

.chalk-text {
  align-items: center;
  color: var(--chalk);
  display: flex;
  filter: none;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  font-size: clamp(1.55rem, 4.2vw, 3.15rem);
  font-weight: 900;
  inset: 0;
  justify-content: center;
  line-height: 1.45;
  margin: 0;
  opacity: 0;
  padding: 28px;
  pointer-events: none;
  position: absolute;
  text-align: center;
  text-shadow:
    1px 0 rgba(255,255,255,0.18),
    0 0 10px rgba(255,255,255,0.16);
  white-space: pre-wrap;
  z-index: 2;
}

.chalk-panel[data-waiting="true"] .chalk-text {
  opacity: 0.94;
}

.chalk-panel[data-complete="true"] .chalk-text {
  color: #dff6dc;
  opacity: 1;
}

.chalk-guide {
  background: rgba(255, 253, 250, 0.12);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  bottom: 14px;
  color: rgba(255,255,255,0.76);
  font-size: 0.84rem;
  margin: 0;
  padding: 5px 12px;
  position: absolute;
  z-index: 3;
}

.chalk-meter {
  background: rgba(23, 59, 49, 0.12);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.chalk-meter span {
  background: linear-gradient(90deg, var(--green), #e9d58a);
  display: block;
  height: 100%;
  width: calc((1 - var(--crumble)) * 100%);
}

.input-panel {
  display: grid;
  gap: 6px;
  padding-top: 12px;
}

.start-guide,
.result-guide {
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

.start-guide {
  background: #fff7e4;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: #514633;
  font-size: 0.84rem;
  line-height: 1.35;
  padding: 5px 9px;
}

#typing-input,
#share-text {
  background: #fffdfa;
  border: 2px solid rgba(79, 143, 99, 0.58);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  line-height: 1.55;
  min-height: 78px;
  padding: 9px 12px;
  resize: vertical;
  width: 100%;
}

#typing-input:disabled {
  background: #f3ead7;
  color: var(--muted);
}

#typing-input:focus,
#share-text:focus {
  border-color: var(--green);
  outline: 3px solid rgba(79, 143, 99, 0.18);
}

.action-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#match-note,
.copy-note {
  color: var(--muted);
  margin: 0;
}

.metrics-panel dl,
.result-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 0;
}

.metrics-panel div,
.result-grid div {
  background: #fff7e4;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

dd {
  font-size: 1.18rem;
  font-weight: 900;
  margin: 0;
}

.metrics-panel p,
.result-grid p,
.share-block span {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
  margin: 6px 0 0;
}

.result-panel,
.related-panel,
.prompt-panel {
  display: grid;
  gap: 12px;
}

.result-panel[hidden],
.metrics-panel[hidden] {
  display: none;
}

.result-panel.is-highlighted {
  animation: result-panel-highlight 1100ms ease-out 1;
}

.share-block {
  display: grid;
  gap: 4px;
}

.related-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.related-list a,
.related-list span {
  background: #fff7e4;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
}

details {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

summary {
  cursor: pointer;
  font-weight: 900;
}

@keyframes result-panel-highlight {
  0% { box-shadow: 0 0 0 rgba(79, 143, 99, 0); }
  28% { box-shadow: 0 0 0 5px rgba(79, 143, 99, 0.18); }
  100% { box-shadow: var(--shadow); }
}

@media (prefers-reduced-motion: reduce) {
  .result-panel.is-highlighted {
    animation: none;
  }
}

@media (max-width: 760px) {
  .site-header,
  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell {
    padding: 0 10px 30px;
  }

  .mode-toolbar,
  .chalk-panel,
  .input-panel,
  .metrics-panel,
  .result-panel,
  .related-panel,
  .prompt-panel {
    padding: 12px;
  }

  .control-panel,
  .action-row,
  .related-list {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  .chalk-stage {
    border-width: 8px;
    height: clamp(300px, 40vh, 340px);
  }

  .metrics-panel dl,
  .result-grid {
    grid-template-columns: 1fr;
  }
}
