/* ===============================
   カラー / 基本設定
================================ */
:root {
  --cream: #fff9f0;
  --paper: #ffffff;
  --ink: #5b4636;         /* やわらかいこげ茶 */
  --ink-soft: #8a7563;
  --primary: #ff9db0;     /* やさしいピンク */
  --primary-deep: #f97088;
  --accent: #ffd66b;      /* たまごイエロー */
  --mint: #8fd6c4;        /* ミントグリーン */
  --sky: #9ec9f0;         /* そらいろ */
  --line: #f0e4d4;
  --shadow: 0 10px 30px rgba(155, 120, 90, 0.15);
  --radius: 22px;
}

* { box-sizing: border-box; }

html {
  background-color: var(--cream);
}

body {
  margin: 0;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro",
    "Rounded Mplus 1c", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background-color: var(--cream);
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.container {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ===============================
   背景装飾（ふわふわ）
================================ */
.bg-decor { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(6px); opacity: 0.45; }
.blob-1 { width: 220px; height: 220px; background: var(--accent); top: -60px; left: -50px; }
.blob-2 { width: 180px; height: 180px; background: var(--mint); bottom: 40px; right: -40px; }
.blob-3 { width: 140px; height: 140px; background: var(--sky); top: 40%; left: -60px; }

/* ===============================
   ヘッダー
================================ */
.site-header {
  position: relative;
  z-index: 2;
  padding: 22px 0;
}
.header-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-mark {
  display: inline-flex;
  background: var(--paper);
  border-radius: 50%;
  padding: 4px;
  box-shadow: var(--shadow);
}
.logo-text h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
.logo-text p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* 投稿ボタン */
.btn-post {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  padding: 14px 26px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(249, 112, 136, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn-post:hover { background: var(--primary-deep); transform: translateY(-2px); }
.btn-post:active { transform: translateY(0); }
.btn-post-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  background: rgba(255,255,255,0.35);
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
}

/* ===============================
   メイン / カード
================================ */
.main-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-top: 8px;
  padding-bottom: 48px;
}
.card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 26px 22px;
  box-shadow: var(--shadow);
  border: 3px solid #fff;
}
.section-head { margin-bottom: 20px; text-align: center; }
.section-title {
  margin: 0;
  font-size: 1.3rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.title-emoji { font-size: 1.3rem; }
.section-sub {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* ===============================
   ランキング
================================ */
.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ranking-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--cream);
  border-radius: 18px;
  padding: 14px 16px;
}
.rank-badge {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  background: var(--sky);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.08);
}
.rank-1 { background: #ffcf4d; }
.rank-2 { background: #c9d3dc; }
.rank-3 { background: #e6b98a; }

.rank-body { flex: 1; min-width: 0; }
.rank-words {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 8px;
}
.wrong-word {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary-deep);
}
.arrow { color: var(--ink-soft); font-size: 0.9rem; }
.correct-word {
  font-size: 0.92rem;
  color: var(--ink-soft);
}
.correct-word b { color: var(--ink); font-weight: 700; }

.rank-footer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

/* 横棒グラフ */
.bar-row { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.bar-track {
  flex: 1;
  height: 16px;
  background: #efe6d8;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-count {
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  min-width: 52px;
  text-align: right;
}
.bar-count small { font-weight: 500; color: var(--ink-soft); }

.rank-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.rank-btn {
  padding:8px 4px 0 0;
  text-align:right;
}

.btn-relate {
  border: 2px solid var(--primary);
  background: #fff;
  color: var(--primary-deep);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-relate:hover {
  background: var(--primary);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(249, 112, 136, 0.3);
}
.btn-relate:active { transform: translateY(0); }
.btn-relate.is-pressed,
.btn-relate:disabled {
  background: #8f8f8f;
  border-color: #8f8f8f;
  color: #fff;
  cursor: default;
  box-shadow: none;
  transform: none;
}

/* ===============================
   円グラフ
================================ */
.chart-grid {
  display: grid;
  gap: 24px;
}
.chart-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.chart-canvas-box {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1 / 1;
}
.chart-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
}
.chart-legend li {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  color: var(--ink);
}
.legend-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-val { color: var(--ink-soft); font-size: 0.8rem; }

/* ===============================
   フッター
================================ */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 26px 0 34px;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

/* ===============================
   モーダル
================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(91, 70, 54, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.modal-overlay.is-open { opacity: 1; visibility: visible; }

.modal {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--paper);
  border-radius: 24px;
  padding: 30px 24px 24px;
  box-shadow: 0 20px 50px rgba(91, 70, 54, 0.35);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal-overlay.is-open .modal { transform: translateY(0) scale(1); }

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 34px; height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--cream);
  color: var(--ink-soft);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}
.modal-close:hover { background: var(--line); }

.modal-head { text-align: center; margin-bottom: 20px; }
.modal-emoji { font-size: 2rem; }
.modal-head h2 { margin: 6px 0 4px; font-size: 1.2rem; }
.modal-head p { margin: 0; font-size: 0.82rem; color: var(--ink-soft); }

/* フォーム */
.post-form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label {
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.req {
  font-size: 0.68rem;
  background: var(--primary);
  color: #fff;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
}
.form-row input,
.form-row select,
.form-row textarea {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 11px 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 157, 176, 0.25);
}
.form-row textarea { resize: vertical; }

.word-suggest {
  margin-top: 4px;
  padding: 10px 12px;
  background: #fff8f0;
  border: 2px dashed var(--accent);
  border-radius: 14px;
}
.word-suggest-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.word-suggest-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btn-suggest {
  border: 2px solid var(--primary);
  background: #fff;
  color: var(--primary-deep);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.btn-suggest:hover {
  background: rgba(255, 157, 176, 0.15);
  transform: translateY(-1px);
}

.form-message {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  min-height: 1.2em;
  color: var(--mint);
  text-align: center;
}
.form-message.is-error { color: var(--primary-deep); }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.btn-cancel,
.btn-submit {
  flex: 1;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 13px;
  border-radius: 999px;
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn-cancel { background: var(--cream); color: var(--ink-soft); }
.btn-cancel:hover { background: var(--line); }
.btn-submit {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(249, 112, 136, 0.4);
}
.btn-submit:hover { background: var(--primary-deep); transform: translateY(-2px); }
.btn-submit:disabled,
.btn-cancel:disabled,
.modal-close:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* データ送信中 */
.submission-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
}
.submission-overlay[hidden] {
  display: none;
}
.submission-overlay p {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}
.submission-overlay .loading-spinner {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
}

/* ローディングスピナー */
.loading-spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* セクション読み込み中 */
.section-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 16px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
  list-style: none;
}
.card.is-loading {
  position: relative;
}
.card.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.55);
  border-radius: inherit;
  pointer-events: none;
}

.ranking-empty {
  list-style: none;
  text-align: center;
  padding: 32px 16px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
}
.ranking-empty.is-error { color: var(--primary-deep); }

.chart-empty {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
}

/* ===============================
   レスポンシブ
================================ */
@media (min-width: 720px) {
  .header-inner {
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
  .logo-text h1 { font-size: 1.55rem; }
  .card { padding: 32px 30px; }
  .chart-wrap { flex-direction: row; justify-content: center; gap: 40px; }
  .chart-legend { flex-direction: column; justify-content: center; }
}

@media (min-width: 1000px) {
  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-grid .chart-canvas-box {
    max-width: 150px;
  }
}
