:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --ink: #20231f;
  --muted: #6d706a;
  --line: #ded9cf;
  --paper: #fffdfa;
  --accent: #2f6f64;
  --accent-ink: #ffffff;
  --risk: #bd3b35;
  --urge: #c2842d;
  --clean: #2f6f64;
  --shadow: 0 24px 80px rgba(48, 42, 32, .10);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(32,35,31,.04) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--bg);
  color: var(--ink);
}

button, input, textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 56px) 18px;
  border-bottom: 1px solid var(--line);
}

.logout-button {
  position: absolute;
  top: 14px;
  right: clamp(14px, 3vw, 32px);
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 250, .7);
  color: var(--muted);
  font-size: 12px;
}

.logout-button:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.18;
}

h2 {
  font-size: 22px;
  line-height: 1.25;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 44vw) minmax(360px, 1fr);
  gap: clamp(18px, 3vw, 34px);
  padding: clamp(18px, 4vw, 56px);
}

.calendar-pane, .entry-pane, .login-panel {
  background: rgba(255, 253, 250, .88);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.calendar-pane {
  padding: clamp(16px, 3vw, 28px);
  position: sticky;
  top: 20px;
  align-self: start;
}

.month-toolbar {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.icon-button, .ghost-button, .ghost-link {
  min-height: 42px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.icon-button {
  width: 42px;
  font-size: 28px;
  line-height: 1;
}

.ghost-button, .ghost-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  padding: 0 16px;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.streak-line {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.icon-button:hover, .ghost-button:hover, .ghost-link:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: rgba(47, 111, 100, .07);
}

.weekday-row, .calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekday-row {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.weekday-row span {
  text-align: center;
  padding: 6px 0;
}

.calendar-grid {
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.day {
  aspect-ratio: 1 / .86;
  min-height: 62px;
  padding: 8px;
  background: rgba(255,255,255,.5);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: var(--ink);
  transition: background .16s ease, transform .16s ease, box-shadow .16s ease;
}

.day:hover {
  background: #fff;
  transform: translateY(-1px);
}

.day.is-empty {
  background: rgba(222,217,207,.22);
  cursor: default;
}

.day.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #fff;
}

.day.is-today strong {
  color: var(--accent);
}

.day strong {
  font-size: 14px;
  line-height: 1;
}

.day-markers {
  display: flex;
  gap: 4px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.clean { background: var(--clean); }
.dot.risk { background: var(--risk); }
.dot.urge { background: var(--urge); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 16px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.entry-pane {
  padding: clamp(18px, 3vw, 34px);
}

.entry-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.save-state {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.entry-form {
  display: grid;
  gap: 18px;
  margin-top: 22px;
}

.quick-log {
  display: grid;
  gap: 16px;
  padding: 18px;
  background: rgba(255, 253, 250, .7);
  border: 1px solid var(--line);
}

.detail-drawer {
  display: grid;
  gap: 16px;
  border-top: 1px solid var(--line);
  padding-top: 4px;
}

.detail-drawer summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
  min-height: 42px;
  display: flex;
  align-items: center;
}

.detail-drawer[open] {
  gap: 18px;
}

.detail-drawer[open] summary {
  margin-bottom: 10px;
}

.subheading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.subheading h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.subheading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.urge-section {
  display: grid;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.rule-box {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: rgba(47, 111, 100, .06);
  border: 1px solid rgba(47, 111, 100, .22);
}

.rule-box summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

.rule-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.check-row input {
  width: auto;
}

.urge-list {
  display: grid;
  gap: 10px;
}

.urge-item {
  display: grid;
  grid-template-columns: minmax(92px, .55fr) 1fr 1fr 1fr 42px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  background: rgba(247, 245, 240, .72);
  border: 1px solid var(--line);
}

.urge-item .remove-urge {
  width: 42px;
  min-height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--risk);
  font-size: 22px;
  line-height: 1;
}

label {
  display: grid;
  gap: 8px;
}

label > span, legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 12px 13px;
  border-radius: 0;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

textarea {
  resize: vertical;
}

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 100, .14);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  margin: 0;
}

.segmented legend {
  margin-right: 8px;
}

.segmented label {
  display: inline-flex;
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  min-width: 110px;
  padding: 11px 14px;
  text-align: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}

.segmented input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-top: 4px;
}

.actions button[type="submit"], .login-form button {
  min-height: 44px;
  padding: 0 24px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform .16s ease, filter .16s ease;
}

.actions button[type="submit"]:hover, .login-form button:hover {
  transform: translateY(-1px);
  filter: brightness(.96);
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.login-shell {
  width: min(92vw, 500px);
}

.login-panel {
  padding: clamp(28px, 6vw, 48px);
}

.login-panel h1 {
  margin-bottom: 14px;
}

.login-copy {
  color: var(--muted);
  line-height: 1.7;
  margin: 0 0 28px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--risk);
  font-size: 13px;
}

.urge-workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: clamp(18px, 3vw, 34px);
  padding: clamp(18px, 4vw, 56px);
}

.amount-panel {
  position: sticky;
  top: 20px;
  align-self: start;
  background: rgba(255, 253, 250, .9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: clamp(20px, 3vw, 30px);
}

.amount-input-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 8px;
  margin: 22px 0 14px;
  font-size: 26px;
  font-weight: 700;
}

.amount-input-row input {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0;
}

.quick-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.quick-amounts button, .filter-tabs button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-tabs button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.calm-copy {
  color: var(--muted);
  line-height: 1.7;
  margin: 0;
}

.option-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.option-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  padding: 18px;
  background: rgba(255, 253, 250, .88);
  border: 1px solid var(--line);
}

.option-item h3 {
  margin: 0 0 7px;
  font-size: 18px;
  letter-spacing: 0;
}

.option-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.option-category {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent) !important;
}

.option-price {
  display: grid;
  justify-items: end;
  gap: 4px;
  white-space: nowrap;
}

.option-price strong {
  font-size: 19px;
}

.option-price span {
  color: var(--accent);
  font-weight: 700;
}

.progress {
  grid-column: 1 / -1;
  height: 7px;
  background: rgba(47, 111, 100, .12);
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  background: var(--accent);
}

@media (max-width: 920px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .urge-workspace {
    grid-template-columns: 1fr;
  }

  .calendar-pane {
    position: static;
  }

  .amount-panel {
    position: static;
  }

  .form-grid, .form-grid.two {
    grid-template-columns: 1fr;
  }

  .urge-item {
    grid-template-columns: 1fr;
  }

  .urge-item .remove-urge {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 14px;
  }

  .calendar-pane, .entry-pane {
    padding: 16px;
  }

  .day {
    min-height: 48px;
    padding: 6px;
  }

  .segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .option-item {
    grid-template-columns: 1fr;
  }

  .option-price {
    justify-items: start;
  }

  .segmented legend {
    grid-column: 1 / -1;
  }

  .segmented span {
    min-width: 0;
    width: 100%;
  }
}
