:root {
  color-scheme: light dark;
  --ink: #222;
  --line: #cfd6e0;
  --accent: #d92828;
  --tehon: rgba(30, 40, 70, 0.07);
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  margin: 0;
  padding: 1.5rem 1rem 3rem;
  max-width: 960px;
  margin-inline: auto;
  line-height: 1.6;
}

header h1 { font-size: 1.6rem; margin: 0 0 .2rem; }
.lead { color: #778; margin: 0 0 1.4rem; }

/* --- お手本ピッカー --- */
.tehon-picker { margin-bottom: 1.4rem; }
.tehon-picker-head,
.samples-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
  font-size: .95rem;
  color: #556;
  font-weight: 600;
}
.kana-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  max-width: 320px;
}
.kana-cell {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}
.kana-cell:hover:not(:disabled) { background: #eef3fb; }
.kana-cell.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.kana-cell.blank { border: none; background: none; cursor: default; }

/* --- サンプル --- */
.sample-ctl { display: flex; gap: .4rem; }
.samples {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.2rem;
}
.pad { flex: 1 1 240px; min-width: 220px; max-width: 320px; }
.pad-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .35rem;
  font-size: .88rem;
  color: #667;
}

/* お手本グリフを後ろ、書き取りSVGを前に重ねる */
.pad-canvas { position: relative; }
.tehon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(70vw, 260px);
  line-height: 1;
  color: var(--tehon);
  pointer-events: none;
  user-select: none;
  overflow: hidden;
}
.canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  touch-action: none;
}
.result-canvas { border-color: #e6b8b8; }

/* --- アクション --- */
.actions {
  display: flex;
  gap: .6rem;
  justify-content: center;
  margin: 1.2rem 0;
}
button {
  font: inherit;
  padding: .5em 1.2em;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover:not(:disabled) { background: #f1f4f9; }
button:disabled { opacity: .45; cursor: default; }
button.mini { padding: .25em .7em; font-size: .85rem; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: #b81f1f; }

/* --- 結果 + 重み --- */
.result {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  justify-content: center;
  align-items: flex-start;
}
.result .pad { max-width: 360px; }
.weights { flex: 1 1 240px; max-width: 320px; }
.weights-head { font-size: .9rem; font-weight: 600; color: #556; margin-bottom: .5rem; }
.weight-row {
  display: grid;
  grid-template-columns: 4rem 1fr;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
  font-size: .85rem;
  color: #667;
}
.weight-row input[type="range"] { width: 100%; }

.export-bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-top: .6rem;
  font-size: .85rem;
  color: #667;
  flex-wrap: wrap;
}
.export-bar .sep { margin-left: .3rem; }
button.save { background: #1f7a4d; border-color: #1f7a4d; color: #fff; }
button.save:hover:not(:disabled) { background: #185f3c; }

/* --- ギャラリー --- */
.gallery { margin-top: 2.4rem; }
.gallery-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .7rem;
  font-size: .95rem;
  font-weight: 600;
  color: #556;
  border-top: 1px solid var(--line);
  padding-top: 1.2rem;
}
.gallery-empty { color: #99a; font-size: .9rem; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .8rem;
}
.gallery-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.gallery-item .thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: #fdfdff;
  cursor: pointer;
  aspect-ratio: 1 / 1;
}
.gallery-item .thumb:hover { background: #f0f4ff; }
.gallery-item .thumb svg { width: 100%; height: 100%; display: block; }
.gi-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .25rem .5rem;
  font-size: .8rem;
  color: #667;
  border-top: 1px solid var(--line);
}
.gi-del {
  border: none;
  background: none;
  color: #b55;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 .2rem;
}
.gi-del:hover { color: #d92828; }

footer { margin-top: 2rem; text-align: center; color: #99a; }
footer code { font-size: .85em; }
