:root {
  --bg: #f7f4fb;
  --surface: #ffffff;
  --surface-soft: #f3ecff;
  --surface-2: #faf8fe;
  --text: #231b2f;
  --muted: #6f647d;
  --border: #ddd6ea;
  --accent: #7f5af0;
  --accent-strong: #6946df;
  --accent-soft: rgba(127, 90, 240, 0.08);
  --danger: #e15b64;
  --shadow: 0 10px 26px rgba(44, 24, 71, 0.08);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
}

body.dark {
  --bg: #121018;
  --surface: #1b1724;
  --surface-soft: #221b2d;
  --surface-2: #18141f;
  --text: #f5f1fb;
  --muted: #c0b6cf;
  --border: #372d47;
  --accent: #a78bfa;
  --accent-strong: #9274f8;
  --accent-soft: rgba(167, 139, 250, 0.12);
  --danger: #f07a84;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 24px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

main {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin-top: 0;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h1 {
  font-size: 2rem;
  margin-bottom: 0.45rem;
}

h2 {
  font-size: 1.35rem;
  margin-bottom: 0.65rem;
}

h3 {
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
}

h4 {
  font-size: 0.98rem;
  margin-bottom: 0.35rem;
}

p {
  margin: 0.5rem 0;
}

a {
  color: var(--accent-strong);
}

.language-selector {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#languageSelect,
#reminderDelay,
#lifeStageSelect,
#categorySelect,
#energyTypeSelect,
input,
select,
button {
  font: inherit;
}

#languageSelect,
#reminderDelay,
#lifeStageSelect,
#categorySelect,
#energyTypeSelect,
input {
  width: 100%;
  min-height: 46px;
  padding: 0.72rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

#languageSelect {
  width: auto;
  min-width: 180px;
}

input:focus,
select:focus,
#languageSelect:focus,
#lifeStageSelect:focus,
#categorySelect:focus,
#energyTypeSelect:focus,
#reminderDelay:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(127, 90, 240, 0.16);
}

button {
  min-height: 44px;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}

button:hover {
  background: var(--accent-strong);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#resetBtn {
  background: var(--danger);
}

#resetBtn:hover {
  background: #cc4a55;
}

.helper-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.9rem;
  margin-bottom: 0.9rem;
}

.helper-controls button {
  width: auto;
  min-width: 180px;
}

.context-panel,
.template-panel,
#entryForm,
.insight-panel,
#weeklySummary,
#monthlySummary,
#wellbeingNotice,
#privacyNotice {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.context-panel,
.template-panel,
.insight-panel {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}

.field-group {
  display: block;
  margin-bottom: 0.9rem;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-group > span {
  display: block;
  margin-bottom: 0.28rem;
  font-weight: 700;
}

.field-group > small {
  display: block;
  margin-bottom: 0.42rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

#entryForm {
  padding: 1rem;
}

#entryForm button {
  width: 100%;
  margin-top: 0.25rem;
}

.template-header h3 {
  margin-bottom: 0.25rem;
}

.template-header p {
  margin-top: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.template-btn {
  width: 100%;
  min-height: 0;
  padding: 0.85rem;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
}

.template-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
}

.template-btn strong {
  display: block;
  margin-bottom: 0.22rem;
  color: var(--text);
}

.template-btn small {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

#todaySpendingsLabel {
  margin-top: 1.4rem;
  margin-bottom: 0.4rem;
}

#totalPercent {
  margin-bottom: 0.6rem;
  font-weight: 700;
}

#progressBarContainer {
  width: 100%;
  height: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.75rem 0 0.55rem;
}

#progressBar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: 999px;
  transition: width 0.25s ease-in-out;
}

#feedbackLine {
  margin-bottom: 0.95rem;
  color: var(--muted);
  font-style: italic;
}

#entryList {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

#entryList li {
  padding: 0.9rem 1rem;
  margin-bottom: 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.entry-meta {
  display: block;
  margin-top: 0.32rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.entry-note {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.87rem;
}

.insight-panel h3,
#weeklySummary h2,
#monthlySummary h2 {
  margin-bottom: 0.65rem;
}

.insight-panel ul,
#weeklySummary ul,
#monthlySummary ul {
  margin: 0;
  padding-left: 1.15rem;
}

.insight-panel li,
#weeklySummary li,
#monthlySummary li {
  margin-bottom: 0.42rem;
  border: none;
  padding: 0;
  background: transparent;
}

.load-map-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 0.5rem;
}

.load-map-grid > div {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.toggles {
  margin: 1.25rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.switch input {
  display: none;
}

.switch .slider {
  position: relative;
  width: 42px;
  height: 22px;
  background: #c9c2d8;
  border-radius: 999px;
  transition: background 0.2s ease;
  flex: 0 0 auto;
}

.switch .slider::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

#percentHelper ul {
  padding-left: 1.15rem;
  margin-top: 0.5rem;
}

#percentHelper li {
  margin-bottom: 0.3rem;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.2rem 0;
}

footer {
  text-align: center;
  color: var(--muted);
}

#supportText a {
  font-weight: 700;
}

@media (max-width: 640px) {
  body {
    padding: 16px;
  }

  main {
    max-width: 100%;
  }

  .template-grid,
  .load-map-grid {
    grid-template-columns: 1fr;
  }

  .helper-controls {
    flex-direction: column;
  }

  .helper-controls button {
    width: 100%;
  }

  #languageSelect {
    width: 100%;
  }
}

.context-panel,
.template-panel,
.insight-panel,
#weeklySummary,
#monthlySummary,
#wellbeingNotice,
#privacyNotice,
#entryForm {
  position: relative;
  overflow: hidden;
}

.context-panel::before,
.template-panel::before,
.insight-panel::before,
#weeklySummary::before,
#monthlySummary::before,
#wellbeingNotice::before,
#privacyNotice::before,
#entryForm::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 4px;
}

.context-panel::before {
  background: var(--accent);
}

.template-panel::before {
  background: #8b6ff5;
}

#entryForm::before {
  background: #6fda9c;
}

.insight-panel::before {
  background: #7db8ff;
}

#weeklySummary::before,
#monthlySummary::before {
  background: #f0b35f;
}

#wellbeingNotice::before {
  background: #f48aa8;
}

#privacyNotice::before {
  background: #8f8f8f;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.template-btn {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  min-height: 0;
  box-shadow: none;
}

.template-btn:hover {
  border-color: var(--accent);
  background: var(--surface);
  transform: translateY(-1px);
}

.template-btn strong {
  display: block;
  margin-bottom: 0.15rem;
  font-size: 0.93rem;
  line-height: 1.2;
}

.template-btn small {
  display: block;
  font-size: 0.77rem;
  color: var(--muted);
  line-height: 1.25;
}

@media (max-width: 640px) {
  .template-grid {
    grid-template-columns: 1fr;
  }
}

#wellbeingNotice,
#privacyNotice {
  background: transparent;
  box-shadow: none;
}

#weeklySummary,
#monthlySummary {
  box-shadow: none;
  background: var(--surface-2);
}

.controls-panel {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: var(--shadow);
}

.controls-header h3 {
  margin-bottom: 0.2rem;
}

.controls-header p {
  margin-top: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 0.9rem;
}

.control-card {
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.control-card h4 {
  margin-bottom: 0.55rem;
  font-size: 0.95rem;
}

.action-buttons {
  display: grid;
  gap: 0.65rem;
}

.action-buttons button {
  width: 100%;
  margin: 0;
}

.inline-label {
  display: block;
  margin-top: 0.8rem;
  margin-bottom: 0.35rem;
  font-size: 0.84rem;
  font-weight: 700;
}

.view-toggles {
  display: grid;
  gap: 0.8rem;
}

.control-card .switch {
  width: 100%;
  align-items: flex-start;
}

.control-card select {
  width: 100%;
  margin-top: 0.1rem;
}

@media (max-width: 700px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

.list-actions {
  margin-top: 0.6rem;
  display: flex;
  justify-content: center;
}

.secondary-btn {
  background: transparent;
  color: var(--accent-strong);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  min-height: 40px;
  box-shadow: none;
}

.secondary-btn:hover {
  background: var(--surface-soft);
  border-color: var(--accent);
}

