:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e8eaf0;
  --muted: #8b8fa8;
  --green: #4ade80;
  --orange: #fb923c;
  --red: #f87171;
  --gray: #6b7280;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --twitter: #1d9bf0;
  --ad-bg: #12141e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.container { max-width: 760px; margin: 0 auto; padding: 0 1.5rem; }

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.6rem 0;
  text-align: center;
}
header h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); margin-top: 0.3rem; font-size: 0.9rem; }

/* ── 広告 ── */
.ad-wrap {
  background: var(--ad-bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0;
}
.ad-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1.5rem;
  position: relative;
  text-align: center;
}
.ad-label {
  position: absolute;
  top: 0; left: 1.5rem;
  font-size: 0.65rem;
  color: var(--muted);
  background: var(--ad-bg);
  padding: 0 4px;
}
.ad-placeholder {
  background: #1e2130;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-horizontal .ad-placeholder { height: 90px; max-width: 728px; margin: 0 auto; }
.ad-rect .ad-placeholder        { height: 250px; max-width: 300px; margin: 0 auto; }
@media (max-width: 600px) {
  .ad-horizontal .ad-placeholder { height: 50px; }
}

/* ── Main ── */
main { padding: 1.8rem 0 3.5rem; display: flex; flex-direction: column; gap: 1.4rem; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}
.card h2 { font-size: 1.05rem; font-weight: 700; }
.card h3 { font-size: 0.95rem; font-weight: 700; }
.section-note { font-size: 0.8rem; color: var(--muted); margin-top: -1rem; }

/* ── Form ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}
@media (max-width: 500px) { .form-grid { grid-template-columns: 1fr; } }

.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; font-weight: 500; }
.field.required label::after { content: ' *'; color: var(--red); }
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.15s;
}
.field input:focus { outline: none; border-color: var(--accent); }

.form-actions { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.btn-primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  min-width: 140px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-save {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-save:hover { border-color: var(--accent); color: var(--text); }

/* ── Verdict ── */
.verdict-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.3rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.verdict-banner.good  { background: rgba(74,222,128,0.08); border-color: var(--green); }
.verdict-banner.avg   { background: rgba(251,146,60,0.08);  border-color: var(--orange); }
.verdict-banner.bad   { background: rgba(248,113,113,0.08); border-color: var(--red); }
.verdict-icon  { font-size: 2.2rem; line-height: 1; flex-shrink: 0; }
.verdict-title { font-size: 1.05rem; font-weight: 800; }
.verdict-desc  { font-size: 0.85rem; color: var(--muted); margin-top: 0.15rem; }

/* ── Metrics ── */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.7rem; }
@media (max-width: 600px) { .metrics { grid-template-columns: repeat(2, 1fr); } }
.metric {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 0.7rem;
  text-align: center;
}
.metric.highlight { border-color: var(--accent); background: rgba(99,102,241,0.08); }
.metric-label { display: block; font-size: 0.7rem; color: var(--muted); margin-bottom: 0.25rem; }
.metric-value { display: block; font-size: 1.3rem; font-weight: 800; }
.metric-value.green { color: var(--green); }
.metric-value.up    { color: var(--green); }
.metric-value.down  { color: var(--red); }

/* ── Bar chart ── */
.bar-container {
  display: grid;
  grid-template-columns: 5.5rem 1fr 3.2rem;
  align-items: center;
  gap: 0.45rem 0.65rem;
}
.bar-label { font-size: 0.8rem; color: var(--muted); text-align: right; }
.bar-track {
  background: var(--bg);
  border-radius: 6px;
  height: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill { height: 100%; transition: width 0.6s ease; min-width: 2px; }
.bar-fill.green  { background: var(--green); }
.bar-fill.orange { background: var(--orange); }
.bar-fill.red    { background: var(--red); }
.bar-fill.gray   { background: var(--gray); }
.bar-pct { font-size: 0.78rem; color: var(--muted); text-align: left; }

/* ── Comparison ── */
.comparison-section { display: flex; flex-direction: column; gap: 0.7rem; }
.comparison-grid {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem;
}
.comp-item { flex: 1; text-align: center; }
.comp-label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.35rem; }
.comp-value { display: block; font-size: 1.7rem; font-weight: 800; }
.comp-value.you { color: var(--accent); }
.comp-value.avg { color: var(--muted); }
.comp-divider { font-size: 0.9rem; color: var(--muted); font-weight: 700; flex-shrink: 0; }
.comp-note { font-size: 0.72rem; color: var(--muted); }

/* ── Simulation ── */
.sim-section { display: flex; flex-direction: column; gap: 0.7rem; }
.sim-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.7rem; }
@media (max-width: 500px) { .sim-grid { grid-template-columns: 1fr; } }
.sim-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
  text-align: center;
}
.sim-icon  { font-size: 1.4rem; margin-bottom: 0.25rem; }
.sim-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem; }
.sim-value { font-size: 1.15rem; font-weight: 800; }
.sim-value.green { color: var(--green); }
.sim-value.red   { color: var(--red); }
.sim-sub   { font-size: 0.7rem; color: var(--muted); margin-top: 0.15rem; }

/* ── iDeCo ── */
.ideco-section { display: flex; flex-direction: column; gap: 0.8rem; }
.ideco-controls label { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--muted); }
.ideco-controls select, .furusato-controls select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.4rem 0.7rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.ideco-result {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.ideco-card {
  flex: 1;
  min-width: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  text-align: center;
}
.ideco-card.green { border-color: var(--green); background: rgba(74,222,128,0.06); }
.ideco-label { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.3rem; }
.ideco-value { font-size: 1.1rem; font-weight: 800; }
.ideco-value.green { color: var(--green); }
.ideco-arrow { color: var(--muted); font-size: 1.2rem; flex-shrink: 0; }

/* ── ふるさと納税 ── */
.furusato-section { display: flex; flex-direction: column; gap: 0.8rem; }
.furusato-controls label { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--muted); }
.furusato-result {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
}
.furusato-main { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }
.furusato-label { font-size: 0.82rem; color: var(--muted); }
.furusato-value { font-size: 1.6rem; font-weight: 800; color: var(--orange); }
.furusato-note { font-size: 0.75rem; color: var(--muted); margin-top: 0.4rem; }

/* ── 月別記録 ── */
.history-section { display: flex; flex-direction: column; gap: 0.8rem; }
.history-chart { display: flex; flex-direction: column; gap: 0.5rem; }
.history-row {
  display: grid;
  grid-template-columns: 5rem 1fr 3.2rem;
  align-items: center;
  gap: 0.5rem 0.7rem;
}
.history-month { font-size: 0.78rem; color: var(--muted); text-align: right; }
.history-track {
  background: var(--bg);
  border-radius: 6px;
  height: 22px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}
.history-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.5s ease;
}
.history-pct { font-size: 0.78rem; color: var(--muted); }
.history-empty { font-size: 0.85rem; color: var(--muted); text-align: center; padding: 1rem; }

/* ── Breakdown ── */
.breakdown-section { display: flex; flex-direction: column; gap: 0.7rem; }
.breakdown-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.breakdown-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.65rem;
  font-size: 0.75rem;
}
.breakdown-table td { padding: 0.5rem 0.65rem; border-bottom: 1px solid var(--border); }
.breakdown-table tr:last-child td { border-bottom: none; }
.breakdown-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.breakdown-table .row-net td  { color: var(--green); font-weight: 700; }
.breakdown-table .row-total td { color: var(--muted); font-size: 0.8rem; }

/* ── Advice ── */
.advice-section { display: flex; flex-direction: column; gap: 0.7rem; }
.advice-list { list-style: none; display: flex; flex-direction: column; gap: 0.55rem; }
.advice-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.86rem;
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  line-height: 1.55;
}
.advice-list li::before { content: '💡'; flex-shrink: 0; }

/* ── Canvas / Share ── */
.canvas-section { display: flex; flex-direction: column; gap: 0.9rem; border-top: 1px solid var(--border); padding-top: 1.2rem; }
#share-canvas {
  width: 100%;
  max-width: 380px;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.share-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}
.share-buttons button {
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-size: 0.87rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.share-buttons button:hover { opacity: 0.85; }
.btn-share-img { background: var(--accent); color: #fff; }
.btn-twitter   { background: var(--twitter); color: #fff; }
.btn-download  { background: var(--green); color: #000; }
.btn-copy      { background: var(--surface); color: var(--text); border: 1px solid var(--border) !important; }

.share-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
}
.share-text-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
}
.share-text-box pre { white-space: pre-wrap; font-size: 0.85rem; color: var(--muted); font-family: inherit; }

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border);
  padding: 1.3rem 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.hidden { display: none !important; }
