/* ===== リセット & 基本設定 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:    #0d1117;
  --bg-panel:   #161b22;
  --bg-card:    #1f2937;
  --bg-card2:   #263040;
  --accent:     #f0b429;
  --accent2:    #38bdf8;
  --accent3:    #a78bfa;
  --green:      #4ade80;
  --red:        #f87171;
  --text:       #e2e8f0;
  --text-muted: #94a3b8;
  --border:     rgba(255,255,255,0.08);
  --sky-top:    #0ea5e9;
  --sky-bot:    #bae6fd;
  --ground-top: #4ade80;
  --ground-bot: #166534;
  --radius:     14px;
  --shadow:     0 4px 24px rgba(0,0,0,0.5);
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ===== ヘッダー ===== */
#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: linear-gradient(90deg, #1e1b4b 0%, #1e3a5f 100%);
  border-bottom: 2px solid var(--accent);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 20px rgba(240,180,41,0.3);
}
.header-left { display: flex; align-items: center; gap: 14px; }
#game-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.4rem;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: 2px;
}
#level-badge {
  background: linear-gradient(135deg, var(--accent), #e67e22);
  color: #1a0a00;
  font-weight: 900;
  font-size: 0.85rem;
  padding: 3px 12px;
  border-radius: 99px;
  box-shadow: 0 0 12px rgba(240,180,41,0.6);
}
.header-stats { display: flex; gap: 18px; }
.stat-item {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.07);
  padding: 5px 14px; border-radius: 99px;
  font-size: 1rem; font-weight: 700;
  border: 1px solid var(--border);
  transition: background 0.2s;
}
.stat-item:hover { background: rgba(255,255,255,0.12); }

/* ===== メインレイアウト ===== */
#main-container {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
}

/* ===== 街パネル ===== */
#town-panel {
  display: flex; flex-direction: column;
  border-right: 2px solid var(--border);
  overflow: hidden;
  position: relative;
}
#town-name-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px;
  background: rgba(0,0,0,0.3);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
#town-stage-label {
  font-size: 0.75rem;
  background: var(--accent3);
  color: #fff;
  padding: 2px 10px; border-radius: 99px;
}

/* --- 空 --- */
#sky {
  position: relative;
  height: 160px;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bot));
  overflow: hidden;
  flex-shrink: 0;
}
#sun {
  position: absolute; top: 20px; right: 40px;
  width: 56px; height: 56px;
  background: radial-gradient(circle, #fff7a0 30%, #fbbf24 70%, transparent 100%);
  border-radius: 50%;
  box-shadow: 0 0 30px 10px rgba(251,191,36,0.5);
  animation: sunPulse 4s ease-in-out infinite;
}
@keyframes sunPulse {
  0%,100%{ box-shadow: 0 0 30px 10px rgba(251,191,36,0.5); }
  50%    { box-shadow: 0 0 50px 20px rgba(251,191,36,0.7); }
}
.cloud {
  position: absolute;
  background: rgba(255,255,255,0.85);
  border-radius: 50px;
  animation: cloudFloat linear infinite;
}
.cloud::before,.cloud::after {
  content:''; position:absolute;
  background: rgba(255,255,255,0.85);
  border-radius: 50%;
}
.cloud-1 { width:80px;height:28px;top:30px;left:-90px; animation-duration:28s; }
.cloud-1::before{ width:40px;height:40px;top:-20px;left:10px; }
.cloud-1::after { width:30px;height:30px;top:-14px;left:38px; }
.cloud-2 { width:60px;height:20px;top:60px;left:-70px; animation-duration:40s; animation-delay:-12s; }
.cloud-2::before{ width:30px;height:30px;top:-15px;left:8px; }
.cloud-2::after { width:22px;height:22px;top:-10px;left:30px; }
.cloud-3 { width:100px;height:30px;top:18px;left:-110px;animation-duration:55s;animation-delay:-30s; }
.cloud-3::before{ width:50px;height:50px;top:-25px;left:12px; }
.cloud-3::after { width:38px;height:38px;top:-18px;left:50px; }
@keyframes cloudFloat { from{left:-120px} to{left:calc(100% + 120px)} }

/* --- 建物エリア --- */
#buildings-area {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  min-height: 130px;
  background: linear-gradient(180deg, #87ceeb22 0%, transparent 100%);
  flex-wrap: wrap;
}
.building {
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer;
  transition: transform 0.2s;
  animation: buildingAppear 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
}
.building:hover { transform: translateY(-4px) scale(1.05); }
.building-emoji { font-size: 2.6rem; line-height: 1; }
.building-name { font-size: 0.6rem; color: var(--text-muted); margin-top: 2px; text-align:center; }
@keyframes buildingAppear {
  from { opacity:0; transform: translateY(30px) scale(0.5); }
  to   { opacity:1; transform: translateY(0) scale(1); }
}

/* --- 地面 --- */
#ground {
  background: linear-gradient(180deg, var(--ground-top), var(--ground-bot));
  padding: 4px 0 6px;
  flex-shrink: 0;
}
#road {
  height: 14px;
  background: repeating-linear-gradient(90deg, #374151 0px, #374151 30px, #4b5563 30px, #4b5563 40px, #374151 40px, #374151 70px, #fbbf24 70px, #fbbf24 75px);
  margin: 0;
}
#trees-row { display:flex; gap:8px; padding:4px 16px; }
.tree { font-size: 1.3rem; }

/* --- 発展ゲージ --- */
#progress-section { padding: 10px 16px 6px; }
#progress-label {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--text-muted); margin-bottom: 6px;
}
#progress-bar-bg {
  height: 14px; border-radius: 99px;
  background: rgba(255,255,255,0.08);
  position: relative; overflow: hidden;
  border: 1px solid var(--border);
}
#progress-bar-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, #4ade80, #22d3ee, var(--accent));
  width: 0%;
  transition: width 0.7s cubic-bezier(0.4,0,0.2,1);
}
#progress-glow {
  position:absolute;top:0;left:0;right:0;bottom:0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.2) 50%, transparent 100%);
  animation: shimmer 2s infinite;
}
@keyframes shimmer { 0%{transform:translateX(-100%)} 100%{transform:translateX(100%)} }

/* --- 建設メニュー --- */
#build-menu {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
#build-menu-title {
  font-size: 0.82rem; font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}
#build-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.build-item {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.build-item:hover:not(.locked) { border-color: var(--accent); background: var(--bg-card2); transform: translateY(-2px); }
.build-item.locked { opacity: 0.45; cursor: not-allowed; }
.build-item.built { border-color: var(--green); }
.build-item .b-emoji { font-size: 1.8rem; }
.build-item .b-name { font-size: 0.65rem; margin-top: 3px; text-align:center; }
.build-item .b-cost { font-size: 0.65rem; color: var(--accent); }
.build-item .b-lock { position:absolute;top:4px;right:4px;font-size:0.7rem; }
.build-item .b-built { position:absolute;top:4px;right:4px;font-size:0.7rem;color:var(--green); }

/* ===== クイズパネル ===== */
#quiz-panel {
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* --- タブ --- */
#quiz-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1; padding: 12px 8px;
  background: none; border: none;
  color: var(--text-muted);
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.85rem; font-weight: 700;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display:none; flex:1; overflow-y:auto; flex-direction:column; }
.tab-content.active { display:flex; }

/* --- 問題カード --- */
#tab-content-quiz { padding: 14px; gap: 12px; }
#question-card {
  background: linear-gradient(135deg, #1e3a5f 0%, #1e1b4b 100%);
  border: 1px solid rgba(56,189,248,0.3);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  box-shadow: 0 4px 20px rgba(56,189,248,0.15);
}
#question-category-badge {
  display: inline-block;
  background: var(--accent2);
  color: #0c1a2e;
  font-size: 0.72rem; font-weight: 700;
  padding: 2px 10px; border-radius: 99px;
  margin-bottom: 8px;
}
#question-text {
  font-size: 0.95rem; line-height: 1.7;
  font-weight: 500;
}
#difficulty-stars { font-size: 0.8rem; color: var(--accent); margin-top: 6px; }

/* --- 仕訳エリア --- */
#journal-entry-area {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: start;
}
.journal-side { display:flex; flex-direction:column; gap:6px; }
.journal-label {
  text-align:center;
  font-size: 0.75rem; font-weight: 700;
  padding: 5px;
  border-radius: 8px;
}
#debit-side .journal-label { background: rgba(74,222,128,0.15); color: var(--green); border: 1px solid rgba(74,222,128,0.3); }
#credit-side .journal-label { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
#journal-divider {
  display:flex; align-items:center; justify-content:center;
  font-size: 1.3rem; padding-top: 30px;
  color: var(--text-muted);
}
.journal-slot {
  background: rgba(255,255,255,0.04);
  border: 2px dashed rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 48px;
  display: flex; align-items:center; justify-content:space-between;
  transition: all 0.2s;
  position: relative;
  cursor: pointer;
}
.journal-slot:hover { border-color: rgba(255,255,255,0.3); background: rgba(255,255,255,0.07); }
.journal-slot.filled { border-style: solid; border-color: rgba(255,255,255,0.25); background: rgba(255,255,255,0.08); }
.journal-slot.correct { border-color: var(--green); background: rgba(74,222,128,0.1); }
.journal-slot.wrong   { border-color: var(--red);   background: rgba(248,113,113,0.1); animation: shake 0.4s; }
.slot-account { font-size: 0.85rem; font-weight: 700; }
.slot-amount  { font-size: 0.8rem; color: var(--accent); font-weight: 700; }
.slot-remove  { font-size: 0.7rem; color: var(--text-muted); cursor:pointer; padding:2px 4px; }
.slot-remove:hover { color: var(--red); }
@keyframes shake {
  0%,100%{transform:translateX(0)}
  20%{transform:translateX(-6px)}
  60%{transform:translateX(6px)}
}

/* --- 選択肢 --- */
#choices-area { display:flex; flex-direction:column; gap:8px; }
#choices-title { font-size: 0.75rem; color: var(--text-muted); }
#choices-grid {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.choice-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.82rem; font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.choice-chip:hover { background: var(--bg-card2); transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,0.3); }
.choice-chip.cat-assets   { border-color: #38bdf8; color: #38bdf8; }
.choice-chip.cat-liab     { border-color: #f87171; color: #f87171; }
.choice-chip.cat-equity   { border-color: #a78bfa; color: #a78bfa; }
.choice-chip.cat-revenue  { border-color: #4ade80; color: #4ade80; }
.choice-chip.cat-expense  { border-color: #fb923c; color: #fb923c; }
.choice-chip.used { opacity: 0.3; cursor: not-allowed; pointer-events:none; }

/* --- ボタン --- */
#action-buttons { display:flex; gap:8px; flex-wrap:wrap; }
.btn-primary,.btn-secondary,.btn-accent {
  padding: 10px 20px; border:none; border-radius: 10px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.9rem; font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), #e67e22); color:#1a0a00; flex:1; }
.btn-primary:hover { transform:translateY(-2px); box-shadow:0 4px 16px rgba(240,180,41,0.5); }
.btn-secondary { background: rgba(255,255,255,0.08); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: rgba(255,255,255,0.14); }
.btn-accent { background: linear-gradient(135deg, var(--accent2), var(--accent3)); color:#fff; flex:1; }
.btn-accent:hover { transform:translateY(-2px); box-shadow:0 4px 16px rgba(56,189,248,0.4); }
button:disabled { opacity:0.4; cursor:not-allowed; transform:none !important; }

/* --- フィードバック --- */
#feedback-area {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
#feedback-icon { font-size: 2rem; text-align:center; margin-bottom:6px; }
#feedback-message { font-size: 1rem; font-weight: 700; text-align:center; margin-bottom:6px; }
#feedback-explanation { font-size: 0.82rem; color: var(--text-muted); line-height:1.7; }
#feedback-reward { margin-top:8px; text-align:center; font-size:0.85rem; color:var(--accent); font-weight:700; }

/* ===== 勘定科目一覧タブ ===== */
#tab-content-accounts { padding:12px; }
#accounts-list-container { display:flex; flex-direction:column; gap:12px; }
.account-group { background: var(--bg-card); border-radius: var(--radius); overflow:hidden; border:1px solid var(--border); }
.account-group-header {
  display:flex; align-items:center; gap:8px;
  padding: 10px 14px;
  font-weight: 700; font-size: 0.9rem;
}
.account-group-body { display:flex; flex-wrap:wrap; gap:6px; padding: 10px 14px; }
.account-tag {
  padding: 4px 10px; border-radius: 99px;
  font-size: 0.78rem; font-weight: 700;
  border: 1px solid currentColor;
}

/* ===== 実績タブ ===== */
#tab-content-ranking { padding:12px; }
#achievements-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.achievement-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--border);
  display:flex; flex-direction:column; align-items:center; gap:6px;
  text-align:center;
  transition: all 0.2s;
}
.achievement-card.unlocked { border-color: var(--accent); background: linear-gradient(135deg, rgba(240,180,41,0.1), rgba(230,126,34,0.05)); }
.achievement-card .ach-icon { font-size: 2rem; }
.achievement-card .ach-name { font-size: 0.78rem; font-weight:700; }
.achievement-card .ach-desc { font-size: 0.68rem; color: var(--text-muted); }
.achievement-card.locked-ach { opacity:0.4; filter:grayscale(1); }

/* ===== モーダル ===== */
.modal {
  position:fixed; inset:0; z-index:200;
  background: rgba(0,0,0,0.75);
  display:flex; align-items:center; justify-content:center;
  animation: fadeIn 0.2s;
}
.modal-content {
  background: linear-gradient(135deg, #1e1b4b, #1e3a5f);
  border-radius: 20px;
  padding: 30px 36px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 60px rgba(240,180,41,0.4);
  text-align:center;
  max-width: 420px; width: 90%;
  display:flex; flex-direction:column; gap:14px;
}
.modal-content h2 { font-size: 1.6rem; color: var(--accent); }
#levelup-fireworks { font-size: 2.2rem; letter-spacing:4px; animation: bounce 0.5s infinite alternate; }
@keyframes bounce { from{transform:translateY(0)} to{transform:translateY(-8px)} }
#levelup-new-level { font-size: 2.5rem; font-weight:900; color:var(--accent); font-family:'Orbitron',sans-serif; }
#levelup-town-name { font-size: 1.1rem; color:var(--accent2); }
#unlocked-buildings { display:flex; justify-content:center; gap:10px; flex-wrap:wrap; margin-top:4px; }
.unlocked-building { font-size:0.85rem; background:rgba(255,255,255,0.1); padding:6px 12px; border-radius:99px; }

/* ===== トースト ===== */
#toast-container {
  position:fixed; bottom:20px; left:50%; transform:translateX(-50%);
  display:flex; flex-direction:column; align-items:center; gap:8px;
  z-index:300; pointer-events:none;
}
.toast {
  background: var(--bg-card2);
  border-radius: 99px;
  padding: 10px 20px;
  font-size: 0.88rem; font-weight:700;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: toastIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes toastIn { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }
.toast-success { border-color: var(--green); color: var(--green); }
.toast-error   { border-color: var(--red);   color: var(--red); }
.toast-info    { border-color: var(--accent2); color: var(--accent2); }

/* ===== コインアニメ ===== */
#coin-animation-container { position:fixed; pointer-events:none; z-index:250; }
.coin-fly {
  position:fixed; font-size:1.4rem;
  animation: coinFly 1s ease-out forwards;
  pointer-events:none;
}
@keyframes coinFly {
  0%  { opacity:1; transform: translateY(0) scale(1); }
  100%{ opacity:0; transform: translateY(-80px) scale(0.5); }
}

/* ===== スクロールバー ===== */
::-webkit-scrollbar { width:5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius:99px; }

/* ===== レスポンシブ ===== */
@media (max-width: 768px) {
  #main-container { grid-template-columns: 1fr; }
  #town-panel { max-height: 60vh; }
  .header-stats { gap: 8px; }
  .stat-item { padding: 4px 8px; font-size:0.85rem; }
  #build-list { grid-template-columns: repeat(4, 1fr); }
}
