:root {
  --paper: #f6f2ea;
  --paper-deep: #efe9dc;
  --ink: #1d1a17;
  --ink-soft: #57503f;
  --line: #d8d0bf;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
  line-height: 1.8;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 20px 64px;
}

header { text-align: center; margin-bottom: 28px; }

h1 {
  font-size: 30px;
  letter-spacing: 0.35em;
  margin: 0;
  font-weight: 600;
}

.tagline {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
  letter-spacing: 0.2em;
}

.input-wrap { position: relative; }

/* テキストエリアの背後に同じ字送りの層を敷き、紋様に入らない部分だけ色づける */
#input-backdrop {
  position: absolute;
  inset: 0;
  padding: 12px 14px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 16px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  color: transparent;
  background: #fffdf8;
  border-radius: 4px;
  pointer-events: none;
  overflow: hidden;
}
#input-backdrop .dropped {
  background: rgba(186, 56, 44, 0.14);
  border-radius: 2px;
}

textarea {
  position: relative;
  display: block;
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  resize: vertical;
}
textarea:focus { outline: 2px solid #b8a97f; }

.hint, .note {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 8px 2px 0;
}
.hint.center { text-align: center; }
#word-count { text-align: right; margin-top: 4px; min-height: 1em; }

.style-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.style-gallery label {
  display: block;
  padding: 8px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  text-align: center;
  background: #fffdf8;
  transition: border-color 0.15s, background 0.15s;
}
.style-gallery label:hover { border-color: var(--ink-soft); }
.style-gallery label:has(input:checked) {
  border-color: var(--ink);
  background: var(--paper-deep);
}
.style-gallery label:has(input:focus-visible) {
  outline: 2px solid #b8a97f;
  outline-offset: 1px;
}
/* radio は視覚的にのみ隠す（display:none だとキーボード操作を殺すため） */
.style-gallery input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.style-gallery canvas {
  width: 100%;
  max-width: 104px;
  height: auto;
  margin: 0 auto;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}
.style-gallery .name {
  display: block;
  font-size: 13px;
  letter-spacing: 0.12em;
  margin-top: 2px;
}
.style-gallery .fit {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}
.style-gallery .fit.over { color: #ba382c; }

.glyph-wrap {
  margin: 20px auto 0;
  max-width: 520px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--paper-deep);
  border-radius: 4px;
  box-shadow: 0 1px 10px rgba(60, 50, 30, 0.12);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 18px;
}

button {
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.12em;
  padding: 9px 22px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink-soft);
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
button:hover { background: var(--paper-deep); }

/* 主操作：墨で塗った一点 */
button.primary {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
  padding: 10px 30px;
}
button.primary:hover { background: #000; }

/* 副次操作：枠を持たず、下線で示す */
button.quiet {
  border-color: transparent;
  color: var(--ink-soft);
  padding: 8px 14px;
}
button.quiet:hover {
  background: transparent;
  color: var(--ink);
  border-bottom-color: var(--ink-soft);
}

/* 共有パネル：主操作を押したときだけ開く */
#share-panel {
  max-width: 460px;
  margin: 16px auto 0;
  padding: 16px 18px 12px;
  background: var(--paper-deep);
  border-radius: 5px;
}
.share-link {
  display: flex;
  gap: 6px;
  align-items: center;
}
.share-targets {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
}
.share-targets button { letter-spacing: 0.16em; }
#share-panel .hint { text-align: center; margin-top: 6px; }

#card-link {
  flex: 1;
  font-size: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fffdf8;
  color: var(--ink-soft);
}

.legend-title {
  font-size: 15px;
  letter-spacing: 0.25em;
  margin: 36px 0 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  font-weight: 600;
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 14px 10px;
}

.legend figure { margin: 0; text-align: center; }
.legend canvas {
  width: 76px;
  height: 76px;
  margin: 0 auto;
  box-shadow: none;
  background: transparent;
  border-radius: 0;
}
.legend figcaption {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.card-lead {
  text-align: center;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
}

.decoded-text {
  text-align: center;
  font-size: 20px;
  margin: 24px 0;
  letter-spacing: 0.08em;
}

a { color: var(--ink); }

/* 言語切替：ヘッダ右上に控えめに */
.lang-picker {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-top: 10px;
}
.lang-picker button {
  font-size: 12px;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border: none;
  color: var(--ink-soft);
  opacity: 0.7;
}
.lang-picker button[aria-pressed="true"] {
  opacity: 1;
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
}
.lang-picker button:hover { background: transparent; opacity: 1; }

/* 例文ボタン */
.input-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}
button.shuffle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 4px 8px;
}
button.shuffle svg { transition: transform 0.4s ease; }
button.shuffle:hover svg { transform: rotate(-180deg); }

footer {
  margin-top: 56px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  text-align: center;
}
footer a {
  font-size: 11.5px;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
}
