/* ==========================================================
   QUEST - 自己成長レベルアップシステム  メインスタイル
   ----------------------------------------------------------
   ▸ 色やフォントを変えたい場合は :root の CSS変数 を編集
   ▸ レイアウト調整は .app / .panel / .status-panel あたり
   ▸ アニメーションは末尾の @keyframes を参照
   ========================================================== */

/* ---------- CSS変数(カラー & トークン) ---------- */
:root {
  /* ベース(ダーク) */
  --bg-0: #06070d;         /* 一番奥の背景 */
  --bg-1: #0b0d18;         /* パネル背景 */
  --bg-2: #121527;         /* カード・入力欄 */
  --bg-3: #1a1f38;         /* ホバー */

  /* テキスト */
  --text-1: #e6e9f5;       /* メインテキスト */
  --text-2: #a3a9c2;       /* サブテキスト */
  --text-3: #5d6485;       /* 注釈・無効 */

  /* アクセントカラー(青/紫系) */
  --accent: #5b8cff;       /* メインアクセント(青) */
  --accent-2: #8a6bff;     /* セカンダリ(紫) */
  --accent-3: #20e0ff;     /* シアン(光) */
  --success: #45e6a8;
  --warning: #ffb347;
  --danger:  #ff5577;

  /* ゴールド (ゲーム内通貨) — 黄金色の輝き */
  --gold:        #ffcb47;     /* 金 */
  --gold-light:  #fff0a0;     /* 金(光) */
  --gold-deep:   #c08a1e;     /* 金(影) */
  --glow-gold:   0 0 20px rgba(255, 203, 71, 0.45);

  /* ボーダー */
  --border: rgba(120, 140, 200, 0.15);
  --border-strong: rgba(120, 140, 200, 0.35);

  /* シャドウ・グロー */
  --glow-accent: 0 0 24px rgba(91, 140, 255, 0.45);
  --glow-purple: 0 0 24px rgba(138, 107, 255, 0.45);

  /* フォント */
  --font-display: "Orbitron", "Rajdhani", system-ui, sans-serif;
  --font-body: "Rajdhani", "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", "Menlo", monospace;

  /* レイアウト */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

/* ---------- リセット ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-0);
  color: var(--text-1);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  position: relative;
  letter-spacing: 0.02em;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select {
  font-family: inherit;
  color: inherit;
}

ul {
  list-style: none;
}

/* ---------- 背景装飾 ---------- */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(91,140,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91,140,255,0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: -1px -1px;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse at center, black 40%, transparent 90%);
}

.bg-glow {
  position: fixed;
  width: 560px;
  height: 560px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}
.bg-glow--1 {
  background: var(--accent);
  top: -180px;
  left: -160px;
}
.bg-glow--2 {
  background: var(--accent-2);
  bottom: -200px;
  right: -180px;
}

/* ---------- アプリ全体のコンテナ ---------- */
.app {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ---------- ヘッダー ---------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.brand-mark {
  font-size: 28px;
  color: var(--accent-3);
  text-shadow: 0 0 12px var(--accent-3);
  animation: pulse 2.4s ease-in-out infinite;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.3em;
  color: var(--text-1);
}

.brand-sub {
  display: inline-block;
  margin-left: 10px;
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--text-3);
  font-weight: 500;
}

.meta-chip {
  display: inline-block;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* header-meta: chipとFIELDリンクを横並びに */
.header-meta {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* HOMEからFIELDへの導線リンク */
.field-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  white-space: nowrap;
  padding: 8px 16px 8px 12px;
  background:
    linear-gradient(135deg, rgba(91, 140, 255, 0.18), rgba(138, 107, 255, 0.12));
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  color: var(--text-1);
  text-decoration: none;
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.field-link::before {
  /* 光の走るアクセント */
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
  transition: left 0.6s ease;
}
.field-link:hover {
  transform: translateY(-1px);
  border-color: var(--accent-3);
  box-shadow: var(--glow-accent);
}
/* TOWNリンクは環境力カラー(緑)で区別 */
.field-link--town {
  background: linear-gradient(135deg, rgba(69, 230, 168, 0.18), rgba(91, 140, 255, 0.10));
  border-color: #45e6a8;
}
.field-link--town:hover {
  border-color: #6affc0;
  box-shadow: 0 0 18px -4px #45e6a8;
}
.field-link:hover::before {
  left: 110%;
}
.field-link-icon {
  font-size: 18px;
  color: var(--accent-3);
  text-shadow: 0 0 8px var(--accent-3);
  line-height: 1;
}
.field-link-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
}
.field-link-sub {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.2em;
}

/* ============================================================
   STATUS PANEL  (Lv / EXP / 日次ステータス)
   ============================================================ */
.status-panel {
  position: relative;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  padding: 28px;
  margin-bottom: 28px;
  background:
    linear-gradient(135deg, rgba(91,140,255,0.08), rgba(138,107,255,0.04)),
    var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* 装飾的なコーナーカット */
.status-panel::before,
.status-panel::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  opacity: 0.7;
}
.status-panel::before {
  top: 10px; left: 10px;
  border-right: none;
  border-bottom: none;
}
.status-panel::after {
  bottom: 10px; right: 10px;
  border-left: none;
  border-top: none;
}

.status-main {
  display: flex;
  gap: 28px;
  align-items: center;
}

/* ========== アバター(ドット絵) ========== */
.avatar-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-right: 24px;
  border-right: 1px solid var(--border);
}

.avatar-slot {
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* ドット絵をくっきり表示(ぼかさない) */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 0 10px rgba(91,140,255,0.35));
  animation: avatarFloat 3s ease-in-out infinite;
}

.avatar-rank {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent-3);
  text-shadow: 0 0 12px rgba(32,224,255,0.4);
}

/* ふわふわ浮遊するアニメ */
@keyframes avatarFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* 進化した瞬間の光る演出 */
.avatar-slot.avatar-evolve {
  animation: avatarFloat 3s ease-in-out infinite, avatarEvolve 1.2s ease-out;
}
@keyframes avatarEvolve {
  0% {
    filter: drop-shadow(0 0 10px rgba(91,140,255,0.35)) brightness(1);
    transform: scale(1);
  }
  30% {
    filter: drop-shadow(0 0 40px rgba(32,224,255,1)) brightness(2.5);
    transform: scale(1.25);
  }
  100% {
    filter: drop-shadow(0 0 10px rgba(91,140,255,0.35)) brightness(1);
    transform: scale(1);
  }
}

.level-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 20px 0 4px;
  border-right: 1px solid var(--border);
}

.level-block .label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--text-3);
}

.level-value {
  font-family: var(--font-display);
  font-size: 72px;
  font-weight: 900;
  line-height: 1;
  color: var(--text-1);
  background: linear-gradient(180deg, #ffffff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(91,140,255,0.35);
}

.exp-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exp-info {
  font-family: var(--font-display);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.exp-current {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent-3);
}
.exp-sep {
  color: var(--text-3);
  font-size: 18px;
}
.exp-required {
  font-size: 20px;
  color: var(--text-2);
}
.exp-label {
  margin-left: 6px;
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.25em;
}

/* EXPバー */
.exp-bar {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  overflow: hidden;
}

.exp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3));
  background-size: 200% 100%;
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 12px var(--accent), 0 0 24px rgba(91,140,255,0.4);
  animation: barFlow 4s linear infinite;
}

.exp-bar-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  transform: translateX(-100%);
  animation: shine 3.5s ease-in-out infinite;
  pointer-events: none;
}

.exp-meta {
  font-size: 12px;
  color: var(--text-2);
  letter-spacing: 0.1em;
}
.exp-meta strong {
  color: var(--accent-3);
  font-family: var(--font-mono);
  font-size: 13px;
}

/* サイドステータスカード */
.status-side {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 14px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.2s, transform 0.2s;
}
.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.stat-card-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.25em;
  color: var(--text-3);
  margin-bottom: 6px;
}
.stat-card-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--text-1);
}
.stat-card-value .unit {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
  margin-left: 4px;
}

/* --- ゴールドカード (黄金色のアクセント) --- */
.stat-card--gold {
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(255, 203, 71, 0.10), transparent 55%),
    var(--bg-2);
  border-color: rgba(255, 203, 71, 0.25);
}
.stat-card--gold:hover {
  border-color: rgba(255, 203, 71, 0.55);
  box-shadow: var(--glow-gold);
}
.stat-card--gold .stat-card-label {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 203, 71, 0.35);
}
.stat-card--gold .stat-card-value {
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 60%, var(--gold-deep));
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.stat-card--gold .gold-icon {
  font-family: var(--font-display);
  font-size: 20px;
  margin-right: 4px;
  /* グラデで透明にならないよう色を再指定 */
  -webkit-text-fill-color: var(--gold);
  filter: drop-shadow(0 0 6px rgba(255, 203, 71, 0.55));
}
.stat-card--gold .unit {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  -webkit-text-fill-color: var(--gold-deep);
  color: var(--gold-deep);
}

/* ゴールド増加アニメ (将来の戦闘実装で使う) */
@keyframes goldPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); filter: drop-shadow(0 0 12px var(--gold)); }
  100% { transform: scale(1); }
}
.stat-card--gold.gold-gain .stat-card-value {
  animation: goldPop 0.5s ease;
}

/* ============================================================
   PANEL (共通パネル)
   ============================================================ */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  margin-bottom: 24px;
}

.panel-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--text-1);
}

.panel-sub {
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.05em;
}

/* ============================================================
   タスクフォーム
   ============================================================ */
.task-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 16px;
}
.task-form #taskName { grid-column: 1 / -1; }
.task-form #taskSub:disabled { opacity: 0.45; cursor: not-allowed; }

.input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text-1);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91,140,255,0.18);
}
.input::placeholder {
  color: var(--text-3);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%23a3a9c2' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ボタン共通 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.15em;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
  white-space: nowrap;
}
.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: var(--glow-accent);
}
.btn-primary:hover {
  box-shadow: 0 0 32px rgba(91,140,255,0.6);
}

.btn-ghost {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  color: var(--text-2);
}
.btn-ghost:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.btn-danger {
  background: transparent;
  border: 1px solid rgba(255,85,119,0.4);
  color: var(--danger);
}
.btn-danger:hover {
  background: rgba(255,85,119,0.1);
}

/* フィルタタブ */
.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filter-tab {
  padding: 6px 14px;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.15em;
  font-weight: 600;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all 0.2s;
}
.filter-tab:hover {
  color: var(--text-1);
  border-color: var(--border-strong);
}
.filter-tab.active {
  background: rgba(91,140,255,0.15);
  border-color: var(--accent);
  color: var(--accent-3);
  box-shadow: 0 0 12px rgba(91,140,255,0.2);
}

/* ============================================================
   タスクリスト
   ============================================================ */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  transition: transform 0.2s, border-color 0.2s, background 0.2s;
  animation: slideIn 0.3s ease-out;
}
.task-item:hover {
  background: var(--bg-3);
  border-color: var(--border-strong);
  border-left-color: var(--accent-3);
}

/* タスクが完了されて消えるアニメ */
.task-item.completing {
  animation: completeOut 0.6s ease-in forwards;
}

.task-cat {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.15em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(91,140,255,0.12);
  color: var(--accent-3);
  border: 1px solid rgba(91,140,255,0.25);
}

/* カテゴリ別カラーは state.categories の color から
   インラインstyleで個別に適用される (UI._catBadge 参照) */

.task-name {
  font-size: 16px;
  color: var(--text-1);
  word-break: break-word;
}

.task-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}

.task-actions {
  display: flex;
  gap: 6px;
}

.btn-complete {
  padding: 8px 16px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 12px rgba(91,140,255,0.3);
  transition: all 0.15s;
}
.btn-complete:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 22px rgba(91,140,255,0.6);
}

.btn-delete {
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: 14px;
  transition: all 0.15s;
}
.btn-delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* クエストの分類変更ボタン */
.btn-editcat {
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: 14px;
  line-height: 1;
  transition: all 0.15s;
}
.btn-editcat:hover {
  border-color: var(--accent);
  color: var(--accent-3);
}

/* 分類変更モーダル (cat-overlay/cat-card を流用) */
.task-edit-card { max-width: 420px; }
.task-edit-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
  margin: 6px 0 4px;
  word-break: break-word;
}
.task-edit-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 16px 0 20px;
}
.task-edit-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.task-edit-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--text-2);
}
.task-edit-field .select { width: 100%; }
.task-edit-actions { text-align: right; }

.empty-msg {
  text-align: center;
  padding: 20px;
  color: var(--text-3);
  font-size: 14px;
  font-style: italic;
}

/* ============================================================
   統計グラフ
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}
.chart-card:nth-child(3) {
  grid-column: span 2;
}

.chart-title {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--text-2);
  margin-bottom: 12px;
  font-weight: 600;
}

.chart-card canvas {
  max-height: 220px;
}

/* ============================================================
   成長ログ
   ============================================================ */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.log-list::-webkit-scrollbar {
  width: 6px;
}
.log-list::-webkit-scrollbar-track {
  background: transparent;
}
.log-list::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border-radius: 3px;
}

.log-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.log-item .log-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}
.log-item .log-name {
  color: var(--text-1);
  word-break: break-word;
}
.log-item .log-exp {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--success);
  font-size: 13px;
}

/* ============================================================
   フッター
   ============================================================ */
.app-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px dashed var(--border);
}

/* ============================================================
   レベルアップ演出
   ============================================================ */
.levelup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,7,13,0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  animation: fadeIn 0.3s ease-out;
}

/* ★ 重要: hidden属性がついているときは絶対に表示しない */
.levelup-overlay[hidden],
.toast[hidden] {
  display: none !important;
}

.levelup-card {
  position: relative;
  text-align: center;
  padding: 60px 80px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(91,140,255,0.12), rgba(138,107,255,0.08));
  border: 1px solid var(--accent);
  box-shadow: 0 0 80px rgba(91,140,255,0.6), inset 0 0 40px rgba(91,140,255,0.1);
  animation: cardPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* リング以外のカード内要素を前面に出す(ボタンを押せるようにするため) */
.levelup-card > *:not(.levelup-rings) {
  position: relative;
  z-index: 2;
}

/* リングはあくまで装飾。クリック判定を完全に無効化する */
.levelup-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.levelup-rings span {
  position: absolute;
  top: 50%; left: 50%;
  width: 100px; height: 100px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: ringExpand 1.6s ease-out infinite;
  opacity: 0;
  pointer-events: none;       /* ★ ここが重要: クリックを通す */
}
.levelup-rings span:nth-child(2) { animation-delay: 0.4s; }
.levelup-rings span:nth-child(3) { animation-delay: 0.8s; }

/* CONTINUEボタンには確実にクリックを通す */
#levelUpClose {
  position: relative;
  z-index: 10;
  pointer-events: auto !important;
  cursor: pointer;
}

.levelup-title {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 900;
  letter-spacing: 0.1em;
  background: linear-gradient(180deg, #fff, var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 40px rgba(32,224,255,0.6);
  margin-bottom: 18px;
  animation: glowPulse 1.5s ease-in-out infinite;
}

.levelup-level {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-3);
  margin-bottom: 8px;
}

.levelup-msg {
  font-size: 15px;
  color: var(--text-2);
  letter-spacing: 0.1em;
  margin-bottom: 30px;
}

/* ============================================================
   トースト通知
   ============================================================ */
.toast {
  position: fixed;
  top: 30px;
  right: 30px;
  padding: 14px 22px;
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.1em;
  box-shadow: var(--glow-accent);
  z-index: 1000;
  animation: toastIn 0.4s ease-out;
}
.toast.hide {
  animation: toastOut 0.4s ease-in forwards;
}

/* ============================================================
   キーフレーム
   ============================================================ */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.92); }
}

@keyframes shine {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
}

@keyframes barFlow {
  0% { background-position: 0% 0%; }
  100% { background-position: 200% 0%; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes completeOut {
  0% { opacity: 1; transform: translateX(0); }
  40% { opacity: 1; transform: translateX(20px); box-shadow: 0 0 32px var(--accent); }
  100% { opacity: 0; transform: translateX(120%); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cardPop {
  0% { opacity: 0; transform: scale(0.7) rotate(-2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes ringExpand {
  0% { width: 100px; height: 100px; opacity: 0.8; }
  100% { width: 400px; height: 400px; opacity: 0; }
}

@keyframes glowPulse {
  0%, 100% { filter: brightness(1) drop-shadow(0 0 20px rgba(32,224,255,0.5)); }
  50% { filter: brightness(1.2) drop-shadow(0 0 40px rgba(32,224,255,0.9)); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(120%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(120%); }
}

/* ============================================================
   レスポンシブ (狭い画面)
   ============================================================ */
@media (max-width: 880px) {
  .app { padding: 20px 14px 60px; }
  .status-panel {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 20px;
  }
  .status-main {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  .level-block {
    flex-direction: row;
    justify-content: space-between;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0 0 12px;
  }
  .level-value { font-size: 48px; }
  .avatar-block {
    flex-direction: row;
    justify-content: center;
    gap: 16px;
    padding-right: 0;
    padding-bottom: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .avatar-slot { width: 72px; height: 72px; }
  .status-side { grid-template-columns: 1fr 1fr; }
  /* スマホ: 日付と長いサブ表記を隠し、FIELDボタンを大きく見やすく */
  .meta-chip { display: none; }
  .brand-sub { display: none; }
  .field-link { padding: 9px 18px; gap: 8px; }
  .field-link-sub { display: none; }
  .field-link-icon { font-size: 22px; }
  .field-link-label { font-size: 17px; }
  .task-form { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .chart-card:nth-child(3) { grid-column: span 1; }
  .task-item { grid-template-columns: auto 1fr auto; }
  .task-date { display: none; }
  .levelup-card { padding: 40px 30px; }
  .levelup-title { font-size: 38px; }
}

/* ============================================================
   カテゴリ分類 UI (フィルタ行 + カテゴリ管理モーダル)
   ============================================================ */

/* フィルタタブ行 + 「カテゴリ管理」ボタン */
.filter-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.filter-row .filter-tabs {
  margin-bottom: 0;
  flex: 1;
}
.manage-cat-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: 11px;
}

/* フィルタタブ内: 色ドットと件数バッジ */
.filter-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
  box-shadow: 0 0 6px currentColor;
}
.filter-count {
  display: inline-block;
  min-width: 17px;
  margin-left: 7px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  border-radius: 999px;
  background: rgba(120,140,200,0.18);
  color: var(--text-1);
}
.filter-tab.active .filter-count {
  background: rgba(91,140,255,0.3);
  color: #fff;
}

/* ---- カテゴリ管理モーダル ---- */
.cat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,7,13,0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.25s ease-out;
}
.cat-overlay[hidden] { display: none !important; }

.cat-card {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 26px 28px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(18,21,39,0.98), rgba(11,13,24,0.98));
  border: 1px solid var(--border-strong);
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), inset 0 0 40px rgba(91,140,255,0.05);
  animation: cardPop 0.4s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.cat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cat-card-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-1);
}
.cat-close-btn { padding: 6px 14px; font-size: 11px; }

.cat-card-note {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
  margin-bottom: 18px;
}

/* カテゴリ一覧 */
.cat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}
.cat-row {
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.cat-main {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
}

/* カラーピッカー (丸く小さく) */
.cat-color {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
.cat-color::-webkit-color-swatch-wrapper { padding: 0; }
.cat-color::-webkit-color-swatch { border: none; border-radius: 50%; }
.cat-color::-moz-color-swatch { border: none; border-radius: 50%; }

/* カテゴリ名 入力 */
.cat-name {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--text-1);
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}
.cat-name:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91,140,255,0.18);
}

.cat-use {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

.cat-row-actions {
  display: inline-flex;
  gap: 4px;
}
.cat-mini-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-1);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
}
.cat-mini-btn:hover:not(:disabled) {
  background: var(--bg-3);
  color: var(--text-1);
  border-color: var(--border-strong);
}
.cat-mini-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.cat-mini-btn.cat-del:hover:not(:disabled) {
  background: rgba(255,85,119,0.12);
  border-color: rgba(255,85,119,0.4);
}

/* 新規追加行 */
.cat-add {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.cat-add-name { padding: 9px 12px; font-size: 14px; }
.cat-add .btn { padding: 9px 16px; font-size: 12px; }

/* スマホ向け調整 */
@media (max-width: 640px) {
  .filter-row { flex-direction: column; }
  .manage-cat-btn { align-self: flex-end; }
  .cat-card { padding: 20px 16px; }
  .cat-add { grid-template-columns: auto 1fr; }
  .cat-add .btn { grid-column: 1 / -1; }
}

/* ============================================================
   タスクのグループ表示 (カテゴリ → サブカテゴリ)
   ============================================================ */
.group-header {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  animation: none; /* タスクのslideInを継承しない */
}
.group-header:hover { background: rgba(120,140,200,0.07); }

.group-header--cat {
  margin-top: 10px;
  padding: 8px;
}
.group-header--cat:first-child { margin-top: 0; }
.group-header--sub { padding: 5px 8px; }

.group-caret {
  width: 14px;
  font-size: 10px;
  color: var(--text-3);
  flex-shrink: 0;
  text-align: center;
}
.group-bar {
  width: 4px;
  height: 16px;
  border-radius: 2px;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}
.group-subdot {
  width: 7px; height: 7px;
  border-radius: 50%;
  opacity: 0.85;
  flex-shrink: 0;
}
.group-label {
  font-family: var(--font-display);
  letter-spacing: 0.06em;
}
.group-header--cat .group-label { font-size: 14px; font-weight: 700; color: var(--text-1); }
.group-header--sub .group-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.group-header.is-muted .group-label { color: var(--text-3); font-style: italic; }
.group-count {
  font-family: var(--font-mono);
  font-size: 10px;
  min-width: 18px;
  padding: 1px 6px;
  text-align: center;
  border-radius: 999px;
  background: rgba(120,140,200,0.15);
  color: var(--text-2);
}

/* ============================================================
   カテゴリ管理: サブカテゴリ編集
   ============================================================ */
.cat-subs {
  margin-top: 10px;
  padding: 10px 8px 4px;
  border-top: 1px dashed var(--border);
}
.cat-subs-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-3);
}
.cat-sub-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}
.cat-sub-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
}
.cat-sub-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.cat-sub-name {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 13px;
  font-family: var(--font-body);
  color: var(--text-1);
  outline: none;
  min-width: 0;
  transition: border-color 0.2s;
}
.cat-sub-name:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91,140,255,0.18);
}
.cat-sub-add {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  padding-left: 8px;
}
.cat-sub-new { flex: 1; padding: 7px 10px; font-size: 13px; min-width: 0; }
.cat-sub-add-btn { padding: 7px 12px; font-size: 11px; white-space: nowrap; }

@media (max-width: 640px) {
  .cat-sub-add { flex-direction: column; }
}

/* ============================================================
   モバイル表示の修正 + ボトムタブナビ (LINE風)
   ============================================================ */

/* --- 修正2: 統計チャートが右にはみ出す問題 ---
   グリッド項目は既定 min-width:auto で中身(canvas)より縮まないため、
   min-width:0 を与え、canvasは container 幅に収める。 */
.chart-card { min-width: 0; }
.chart-card canvas { max-width: 100%; }
.stats-grid { min-width: 0; }

/* --- タブページ: PC では全部見える(従来どおり縦並び) --- */
.tab-page { display: block; }
.tabbar { display: none; }

@keyframes tabFade { from { opacity: 0.25; } to { opacity: 1; } }

/* ============================================================
   スマホ (<= 880px): セクションをタブで切り替え + ボトムバー
   ============================================================ */
@media (max-width: 880px) {
  .tab-page { display: none; }
  .tab-page.is-active { display: block; animation: tabFade 0.22s ease; }

  /* タブバーのぶんだけ下に余白 (ホームインジケータも考慮) */
  .app { padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px)); }

  .tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    background: rgba(9, 11, 20, 0.96);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-strong);
    padding: 6px 2px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .tabbar-btn {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-3);
    padding: 5px 2px;
    font-family: var(--font-display, sans-serif);
    transition: color 0.15s;
  }
  .tabbar-ico { font-size: 21px; line-height: 1; opacity: 0.7; transition: transform 0.15s, opacity 0.15s; }
  .tabbar-label { font-size: 10px; letter-spacing: 0.06em; }
  .tabbar-btn.is-active { color: var(--accent-3); }
  .tabbar-btn.is-active .tabbar-ico { opacity: 1; transform: translateY(-2px); }

  /* --- 修正1: クエスト名が縦書きになる問題 ---
     項目を「バッジ＋名前 / 日付＋操作」の2段に積み、
     名前が1文字幅に潰れて縦になるのを防ぐ。 */
  .task-item {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "cat  name"
      "date actions";
    gap: 8px 10px;
    align-items: center;
  }
  .task-item .task-cat    { grid-area: cat;  align-self: center; }
  .task-item .task-name   { grid-area: name; align-self: center; min-width: 0; }
  .task-item .task-date   { grid-area: date; align-self: center; }
  .task-item .task-actions{ grid-area: actions; justify-self: end; }
}

/* ============================================================
   クエストセット (よく使うクエストのまとまり)
   ============================================================ */
.quest-sets { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.qs-empty { color: var(--text-3, #9aa0bf); font-size: 13px; line-height: 1.6; margin: 4px 0 10px; }

.qs-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border, #20243a);
  border-radius: 10px;
}
.qs-card-main { min-width: 0; flex: 1 1 200px; }
.qs-card-top { display: flex; align-items: center; gap: 8px; }
.qs-card-name { font-family: var(--font-display, sans-serif); font-weight: 700; color: var(--text-1, #fff); }
.qs-card-count {
  font-size: 11px; color: var(--accent-3, #5b8cff);
  border: 1px solid rgba(91,140,255,0.4); border-radius: 20px; padding: 1px 8px;
}
.qs-card-preview {
  display: block; margin-top: 4px;
  color: var(--text-3, #9aa0bf); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.qs-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.qs-add { padding: 8px 14px; font-size: 13px; white-space: nowrap; }
.qs-iconbtn {
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border, #20243a); background: transparent;
  color: var(--text-2, #c7cce0); cursor: pointer; font-size: 14px;
}
.qs-iconbtn:hover { border-color: var(--accent-3, #5b8cff); color: #fff; }
.qs-del:hover { border-color: #ff6b6b; color: #ff8a8a; }
.newset-btn { width: 100%; }

/* セット編集モーダルの中身 */
.qs-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.qs-label { font-size: 12px; color: var(--text-3, #9aa0bf); letter-spacing: 0.06em; }
.qs-items-head { margin-bottom: 8px; }
.qs-items { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.qs-item-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; }
.qs-item-name { min-width: 0; }
.qs-item-cat { max-width: 130px; }
.qs-item-remove {
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border, #20243a); background: transparent;
  color: var(--text-2, #c7cce0); cursor: pointer;
}
.qs-item-remove:hover { border-color: #ff6b6b; color: #ff8a8a; }
.qs-addrow { width: 100%; }

@media (max-width: 480px) {
  .qs-card-actions { width: 100%; }
  .qs-add { flex: 1; }
  .qs-item-cat { max-width: 110px; }
}
