/* ═══════════════════════════════════════════════
   文字ひろい ─ 活版印刷の「文選」をモチーフにした配色
   鉄紺の活字棚 × 和紙の作業面 × 朱の印
   ═══════════════════════════════════════════════ */

:root {
  --tetsu:      #24313A;  /* 鉄紺: 背景（活字棚） */
  --tetsu-deep: #19232A;  /* 濃鉄: 文選箱まわり */
  --paper:      #F6F4ED;  /* 和紙: 作業面 */
  --paper-dim:  #ECE9DF;  /* 和紙の影 */
  --sumi:       #2B2620;  /* 墨: 文字 */
  --shu:        #C94D32;  /* 朱: 主要アクション */
  --shu-deep:   #A83A22;
  --gin:        #9BA7AE;  /* 銀鼠: 暗い面のラベル */
  --line:       #D8D3C6;  /* 紙面の罫線 */
  --mincho: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --gothic: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 90% at 50% -10%, #2C3B46 0%, var(--tetsu) 55%);
  color: var(--sumi);
  font-family: var(--gothic);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--shu);
  outline-offset: 2px;
}

/* ── ヘッダー ─────────────────────────── */

.site-header { padding: 20px 24px 14px; }

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-family: var(--mincho);
  font-weight: 700; font-size: 30px;
  color: var(--paper);
  background: var(--shu);
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25), 0 3px 10px rgba(0,0,0,.35);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--mincho);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: .18em;
  color: var(--paper);
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 13px;
  letter-spacing: .08em;
  color: var(--gin);
}

/* ── 作業台 ─────────────────────────── */

.workbench {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  gap: 16px;
  padding: 0 24px 16px;
  align-items: start;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.panel {
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(0,0,0,.30);
  padding: 16px;
}

.hint {
  margin: 12px 2px 12px;
  font-size: 14px;
  color: #5D564B;
}
.hint strong { color: var(--shu-deep); }

.note { margin: 8px 2px 0; font-size: 13px; color: #7A7365; min-height: 1.4em; }

/* ── タブ ─────────────────────────── */

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.tab {
  padding: 10px 4px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #6B6457;
  background: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: background .15s, color .15s;
}

.tab:hover { background: #E4E0D3; }

.tab.is-active {
  color: var(--paper);
  background: var(--sumi);
  border-color: var(--sumi);
}

.tabpane { display: none; }
.tabpane.is-active { display: block; }

/* ── 手書きキャンバス（米字格） ───────── */

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 400px;
  margin: 0 auto;
}

#handCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #FDFCF8;
  border: 2px solid #C9C2B2;
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
}

/* ── ボタン ─────────────────────────── */

.btnrow {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.btn {
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--sumi);
  background: #fff;
  border: 1.5px solid #B9B2A0;
  border-radius: 8px;
  transition: background .15s;
}

.btn:hover { background: var(--paper-dim); }
.btn:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  border-color: #46545E;
  color: var(--gin);
}
.btn-ghost:hover { background: rgba(255,255,255,.06); }

.btn-more {
  display: block;
  width: 100%;
  margin-top: 12px;
}

/* ── 部首 ─────────────────────────── */

.selected-radicals {
  font-family: var(--mincho);
  font-size: 20px;
  color: var(--shu-deep);
  letter-spacing: .2em;
}

.radical-grid {
  margin-top: 12px;
  max-height: 430px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #FDFCF8;
  padding: 8px;
}

.radical-group-label {
  font-size: 12px;
  font-weight: 700;
  color: #8A8272;
  letter-spacing: .1em;
  padding: 8px 4px 4px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 6px;
}

.radical-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
  margin-bottom: 6px;
}

.radical-btn {
  aspect-ratio: 1;
  font-family: var(--mincho);
  font-size: 22px;
  color: var(--sumi);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  display: grid;
  place-items: center;
  transition: background .12s;
}

.radical-btn:hover { background: var(--paper-dim); border-color: var(--line); }

.radical-btn.is-selected {
  background: var(--shu);
  color: #fff;
  border-color: var(--shu-deep);
}

.radical-btn:disabled {
  opacity: .18;
  cursor: default;
}
.radical-btn:disabled:hover { background: transparent; border-color: transparent; }

/* ── 画数 ─────────────────────────── */

.strokes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
  margin-top: 4px;
}

.stroke-btn {
  padding: 12px 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--sumi);
  background: #FDFCF8;
  border: 1.5px solid var(--line);
  border-radius: 8px;
}

.stroke-btn:hover { background: var(--paper-dim); }

.stroke-btn.is-selected {
  background: var(--sumi);
  color: var(--paper);
  border-color: var(--sumi);
}

/* ── 記号 ─────────────────────────── */

.symbol-cats { display: flex; flex-direction: column; gap: 6px; }

.symbol-cat-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--sumi);
  background: #FDFCF8;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  text-align: left;
}

.symbol-cat-btn .sample {
  font-weight: 400;
  color: #8A8272;
  font-size: 16px;
  letter-spacing: .1em;
  overflow: hidden;
  white-space: nowrap;
}

.symbol-cat-btn:hover { background: var(--paper-dim); }

.symbol-cat-btn.is-selected {
  background: var(--sumi);
  color: var(--paper);
  border-color: var(--sumi);
}
.symbol-cat-btn.is-selected .sample { color: var(--gin); }

/* ── 候補 ─────────────────────────── */

.panel-result { min-height: 480px; display: flex; flex-direction: column; }

.result-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--sumi);
  padding-bottom: 8px;
}

.result-head h2 {
  margin: 0;
  font-family: var(--mincho);
  font-size: 18px;
  letter-spacing: .2em;
}

.result-count { font-size: 13px; color: #8A8272; margin-left: 8px; letter-spacing: .05em; }

.reading-strip {
  margin: 0;
  font-size: 14px;
  color: #5D564B;
  min-height: 1.5em;
  flex: 1;
}
.reading-strip b {
  font-family: var(--mincho);
  font-size: 18px;
  color: var(--shu-deep);
  margin-right: 6px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 6px;
  padding-top: 12px;
  align-content: start;
  flex: 1;
}

.result-grid .placeholder {
  grid-column: 1 / -1;
  margin: 40px auto;
  max-width: 32em;
  text-align: center;
  color: #8A8272;
  font-size: 14px;
}

.group-label {
  grid-column: 1 / -1;
  font-size: 12px;
  font-weight: 700;
  color: #8A8272;
  letter-spacing: .1em;
  padding-top: 8px;
  border-bottom: 1px dashed var(--line);
}

.char-btn {
  aspect-ratio: 1;
  font-family: var(--mincho);
  font-weight: 500;
  font-size: 32px;
  line-height: 1;
  color: var(--sumi);
  background: #FDFCF8;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  transition: background .12s, border-color .12s;
}

.char-btn:hover {
  background: #fff;
  border-color: var(--shu);
  box-shadow: 0 2px 8px rgba(201,77,50,.25);
}

.char-btn:active { transform: translateY(1px); }

/* ── 文選箱（トレイ） ───────────────── */

.tray-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--tetsu-deep);
  box-shadow: 0 -6px 18px rgba(0,0,0,.35);
  border-top: 1px solid #31414C;
}

.tray {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.tray-label {
  writing-mode: vertical-rl;
  font-family: var(--mincho);
  font-size: 12px;
  letter-spacing: .3em;
  color: var(--gin);
  border-right: 1px solid #3A4A55;
  padding-right: 8px;
  flex-shrink: 0;
}

.tray-blocks {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 2px;
  min-height: 56px;
  align-items: center;
}

.tray-empty { color: #5C6B74; font-size: 13px; white-space: nowrap; }

.tray-block {
  width: 48px; height: 48px;
  flex-shrink: 0;
  font-family: var(--mincho);
  font-size: 26px;
  color: var(--sumi);
  background: linear-gradient(160deg, #FFFDF6, #EDE9DC);
  border: 1px solid #B9B2A0;
  border-bottom-width: 3px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  animation: pickup .18s ease-out;
}

.tray-block:hover { background: #FFF3EF; border-color: var(--shu); }

@keyframes pickup {
  from { transform: translateY(-8px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.tray-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.btn-copy {
  padding: 14px 26px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .2em;
  color: #fff;
  background: var(--shu);
  border: none;
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.3), 0 3px 0 var(--shu-deep);
}

.btn-copy:hover { background: #D65A3E; }
.btn-copy:active { transform: translateY(2px); box-shadow: inset 0 0 0 2px rgba(255,255,255,.3), 0 1px 0 var(--shu-deep); }

/* ── クレジット・トースト ───────────── */

.credit {
  margin: 0;
  padding: 8px 24px 12px;
  font-size: 11px;
  color: #5C6B74;
  background: var(--tetsu-deep);
}
.credit a { color: #7E909B; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translate(-50%, 16px);
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 700;
  color: var(--paper);
  background: var(--sumi);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 100;
}

.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ── レスポンシブ ───────────────────── */

@media (max-width: 900px) {
  .workbench { grid-template-columns: 1fr; padding: 0 12px 12px; }
  .tabbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tab { font-size: 14px; letter-spacing: .04em; padding: 9px 2px; }
  .site-header { padding: 14px 16px 10px; }
  .brand-text h1 { font-size: 21px; }
  .panel { padding: 12px; }
  .panel-result { min-height: 300px; }
  .radical-grid { max-height: 300px; }
  .tray-bar { padding: 8px 12px; gap: 8px; }
  .btn-copy { padding: 12px 18px; }
  .toast { bottom: 130px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
