:root {
  --kachi: #0d2536;   /* 褐返し: ページの地 */
  --ai: #17405c;      /* 藍: 布 */
  --thread: #f3ecd9;  /* 生成りの糸: 文字と線 */
  --yamabuki: #f2b92f;/* 山吹: 選択と囲み */
  --gutter: clamp(16px, 3vw, 40px);
  font-family: "Klee One", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--kachi);
  color: var(--thread);
  line-height: 1.8;
}

h1, h2, p { margin: 0; }

.play {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(280px, 360px);
  gap: var(--gutter);
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: var(--gutter);
}

.board { width: min(calc(100vh - 2 * var(--gutter)), calc(100vw - 360px - 3 * var(--gutter))); }
.board { width: min(calc(100svh - 2 * var(--gutter)), calc(100vw - 360px - 3 * var(--gutter))); }

#cloth {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  touch-action: none;
  cursor: crosshair;
  box-shadow: 0 2px 0 #0a1c2a, 0 14px 36px rgba(0, 8, 18, 0.45);
}

h1 {
  font-size: 2.5rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.04em;
}

.night { font-size: 0.95rem; }

.round {
  margin-top: 1.4rem;
  font-size: 1.15rem;
  font-weight: 600;
}

/* 残りの糸は、そのまま運針の長さで見せる */
.thread {
  height: 8px;
  margin-top: 0.6rem;
  background-image: repeating-linear-gradient(90deg, rgba(243, 236, 217, 0.18) 0 14px, transparent 14px 23px);
  border-radius: 4px;
}

.thread-fill {
  height: 100%;
  width: 100%;
  background-image: repeating-linear-gradient(90deg, var(--thread) 0 14px, transparent 14px 23px);
  transition: width 0.18s linear;
}

.thread-text { font-size: 0.9rem; margin-top: 0.25rem; }

.score-line {
  margin-top: 1rem;
  line-height: 1.1;
  font-weight: 600;
}

.score-label, .score-unit { font-size: 1.15rem; }
.score { font-size: 3.2rem; font-variant-numeric: lining-nums; }

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.1em;
  font-size: 0.92rem;
}

.counts:empty { display: none; }

.status {
  min-height: 3.4em;
  margin-top: 0.8rem;
  font-size: 0.98rem;
  line-height: 1.7;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

button, .button {
  font: inherit;
  font-weight: 600;
  color: var(--thread);
  background: transparent;
  /* ボタンの枠も運針の線で揃える */
  border: 1.5px dashed rgba(243, 236, 217, 0.75);
  border-radius: 5px;
  padding: 0.4em 0.95em;
  text-decoration: none;
  cursor: pointer;
}

button.primary {
  background: var(--thread);
  color: var(--kachi);
  border: 1.5px solid var(--thread);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

:focus-visible {
  outline: 2.5px solid var(--yamabuki);
  outline-offset: 3px;
}

.howto {
  margin-top: 1.4rem;
  font-size: 0.9rem;
  line-height: 1.7;
}

.howto h2 { font-size: 0.98rem; font-weight: 600; }
.howto ul { margin: 0.25rem 0 0; padding-left: 1.15em; }

/* 結果 */
.results {
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--gutter);
  outline: none;
}

.results-total {
  font-size: 1.6rem;
  font-weight: 600;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.6rem;
  margin-top: 1.2rem;
}

.card { margin: 0; min-width: 0; }

.card canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
}

.card figcaption { margin-top: 0.5rem; overflow-wrap: anywhere; }
.card strong { display: block; font-size: 1.15rem; font-weight: 600; line-height: 1.5; }
.card .meta { display: block; font-size: 0.88rem; }
.card p { margin-top: 0.25rem; font-size: 0.95rem; line-height: 1.7; }

.results .actions { margin-top: 1.8rem; }

.gallery {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2.4rem var(--gutter) 1rem;
}

.gallery h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.credit {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.6rem var(--gutter) 3rem;
  font-size: 0.86rem;
}

.credit a { color: inherit; }

/* 名前をつける */
dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1.5px dashed rgba(243, 236, 217, 0.7);
  border-radius: 6px;
  background: var(--ai);
  color: var(--thread);
  padding: 1.4rem;
}

dialog::backdrop { background: rgba(4, 16, 26, 0.55); }
dialog h2 { font-size: 1.3rem; font-weight: 600; line-height: 1.5; }
.dialog-score { font-size: 0.95rem; margin-bottom: 0.8rem; }

dialog label {
  display: block;
  margin-top: 0.7rem;
  font-size: 0.92rem;
  font-weight: 600;
}

dialog input,
dialog textarea {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.45em 0.6em;
  font: inherit;
  color: var(--thread);
  background: rgba(4, 22, 36, 0.55);
  border: 1px solid rgba(243, 236, 217, 0.5);
  border-radius: 4px;
  resize: vertical;
}

dialog input::placeholder,
dialog textarea::placeholder { color: rgba(243, 236, 217, 0.72); }

dialog .actions { margin-top: 1.1rem; }

@media (max-width: 860px) {
  .play {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    min-height: 0;
    gap: 0.9rem;
  }
  .board { width: 100%; order: 1; }
  .panel { display: contents; }
  .panel header { order: 0; }
  .panel header h1 { font-size: 1.9rem; }
  .round { order: 2; margin-top: 0; }
  .thread { order: 3; margin-top: 0; }
  .thread-text { order: 4; margin-top: -0.7rem; }
  .score-line { order: 5; margin-top: 0; }
  .counts { order: 6; margin-top: -0.6rem; }
  .status { order: 7; margin-top: 0; }
  .actions { order: 8; margin-top: 0; }
  .howto { order: 9; margin-top: 0.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .thread-fill { transition: none; }
}
