* { box-sizing: border-box; }
:root {
  --bg: #fffefb;
  --ink: #222;
  --muted: #6b7280;
  --brand: #ff6b6b;
  --brand-2: #ffd166;
  --surface: #ffffff;
  --border: #e5e7eb;
}
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "YuGothic", "Meiryo", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #fff6f6, #fffefb 30%);
}
.app-header, .app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.app-footer { border-top: 1px solid var(--border); border-bottom: none; }
.app-header h1 { font-size: 20px; margin: 0; }
nav button.linklike {
  background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px 8px; font-size: 14px;
}

main { max-width: 960px; margin: 0 auto; padding: 16px; }
.screen.hidden { display: none; }
.controls-row { display: flex; gap: 8px; align-items: center; margin: 8px 0 12px; }
.controls-row .spacer { flex: 1; }

/* セット管理 */
.sets-panel { margin: 12px 0 20px; padding: 12px 14px; background: #fffaf2; border: 1px solid var(--border); border-radius: 10px; }
.sets-panel h3 { margin: 0 0 10px; font-size: 16px; }
.sets-container { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.set-box { border: 1px solid var(--border); background: #ffffff; border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.set-box header { display: flex; gap: 6px; align-items: center; }
.set-box input.set-name { flex: 1; padding: 4px 6px; font-size: 14px; }
.set-box .set-actions { display: flex; gap: 6px; }
.set-box button { font-size: 12px; padding: 6px 8px; }
.set-kana-preview { font-size: 12px; color: var(--muted); line-height: 1.4; max-height: 4.2em; overflow: hidden; }

button { border: 1px solid var(--border); background: var(--surface); padding: 10px 14px; border-radius: 8px; cursor: pointer; font-size: 16px; }
button.primary { background: var(--brand); color: white; border-color: #ff8b8b; }
button.secondary { background: #f3f4f6; }
button.linklike { border: none; background: none; color: #2563eb; text-decoration: underline; padding: 4px 6px; }
button.success { background: #34d399; color: #083344; border-color: #10b981; }
button.warn { background: #fde68a; color: #7c2d12; border-color: #f59e0b; }
button:active { transform: translateY(1px); }

.kana-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(302px, 1fr)); gap: 12px; }
.kana-group { border: 1px solid var(--border); background: var(--surface); padding: 10px; border-radius: 8px; }
.kana-group h3 { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.kana-rows { display: flex; flex-direction: column; gap: 6px; }
.kana-row { display: flex; flex-wrap: wrap; gap: 8px; overflow: visible; }
.kana-break { flex-basis: 100%; height: 0; }
.kana-item { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fafafa; }

.game { display: grid; gap: 12px; justify-items: center; }
.card {
  width: clamp(240px, 60vw, 520px);
  height: clamp(320px, 65vh, 720px);
  perspective: 1200px;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}
.card-inner.no-anim { transition: none; }
.card.hiddenfast { opacity: 0; }
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  border-radius: 16px;
  border: 2px solid var(--brand-2);
  background: white;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
  padding: 24px;
}
.card-front { background: #fff; }
.card-back { transform: rotateY(180deg); background: #fffef7; }
.card-big { font-size: clamp(120px, 22vw, 220px); font-weight: 800; }
.card-word { font-size: clamp(40px, 6vw, 64px); font-weight: 700; margin-bottom: 12px; text-align: center; }
.card-back-content {
  display: grid;
  grid-template-rows: auto 1fr;
  justify-items: center;
  align-content: stretch;
  gap: 8px;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.card-word { text-align: center; line-height: 1.2; overflow-wrap: anywhere; max-width: 100%; }
.card-illustration {
  font-size: clamp(100px, 18vw, 200px);
  text-align: center;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.card-illustration img { max-width: 100%; max-height: 100%; object-fit: contain; }

.toolbar { display: flex; gap: 8px; }
.status { color: var(--muted); display: flex; gap: 12px; align-items: center; }

.checkbox { display: inline-flex; gap: 6px; align-items: center; }

.result { display: grid; justify-items: center; gap: 12px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.result-emoji { font-size: clamp(72px, 14vw, 160px); }
.result-title { font-size: clamp(24px, 5vw, 36px); margin: 8px 0; }
.result-percent { color: var(--muted); }

/* スマホ最適化 */
@media (max-width: 480px) {
  main { padding: 8px; }
  .card { width: calc(100vw - 16px); height: calc(100vh - 200px); }
  .card-face { padding: 12px; border-radius: 12px; }
  .toolbar { flex-wrap: wrap; justify-content: center; }
}
