:root {
  color-scheme: light;
  --accent: #c0396f;
  --accent-edge: #8f2450;
  --accent-text: #a42c5e;
  --tile1: #ffc4d8;
  --tile1-edge: #ef97b6;
  --tile2: #ffeda6;
  --tile2-edge: #ecd36d;
  --tile2-text: #6e5408;
  --tile3: #bdeed6;
  --tile3-edge: #8fd6b4;
  --tile3-text: #17694a;
  --ink: #5d2340;
  --ink-soft: #8c6176;
  --ink-faint: #c9adba;
  --line: #f6dfe8;
  --ground: #fdf1f6;
  --surface: #ffffff;
  --sticker: #ff7d9c;
  --check-edge: #62bf95;
  --tile1-faint: #eb9dbb;
  --tile2-faint: #8f7a2c;
  --day-off: #e4d3db;
  --save-off: #f3c9d9;
  --mark-2: #2fa877;
  --chart-line: #c0396f;
  --chart-goal: #17694a;
  --chart-grid: #f8e8ef;
  --chart-cursor: #5d2340;
  --display: "Jua", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --body: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--display);
  font-size: 17px;
  line-height: 1.5;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

h1, h2, p { margin: 0; font-weight: 400; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.logo {
  margin: 0;
  font-size: 52px;
  line-height: 1.15;
  color: var(--accent);
}

.center-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto;
  padding: 40px 24px;
}
.center-screen p { font-family: var(--body); color: var(--ink-soft); }
.center-screen .primary { margin-top: 12px; }
.center-screen .error { color: var(--accent-text); }

.primary {
  display: block;
  width: 100%;
  min-height: 54px;
  padding: 12px 20px;
  border: 0;
  border-radius: 20px;
  background: var(--accent);
  box-shadow: 0 4px 0 var(--accent-edge);
  color: #fff;
  font-size: 18px;
  text-align: center;
  text-decoration: none;
}
.link-button { line-height: 30px; }

.quiet {
  min-height: 44px;
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-size: 16px;
}

.icon-button {
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--accent-text);
  font-size: 26px;
  line-height: 1;
}
.icon-button:disabled { color: var(--line); cursor: default; }

.error {
  color: var(--accent-text);
  font-family: var(--body);
  font-size: 15px;
  font-weight: 600;
}
.error:empty, .status:empty { display: none; }

/* 앱 틀 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 18px 0;
}

.save {
  min-height: 42px;
  padding: 6px 22px;
  border: 0;
  border-radius: 99px;
  background: var(--accent);
  box-shadow: 0 3px 0 var(--accent-edge);
  color: #fff;
  font-size: 16px;
}
.save:disabled {
  background: var(--save-off);
  box-shadow: none;
  color: #fff;
  cursor: default;
}

.status {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 5;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 190px);
  padding: 6px 14px;
  pointer-events: none;
  border-radius: 16px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  line-height: 1.3;
  text-align: center;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px calc(92px + env(safe-area-inset-bottom));
}

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  min-height: 60px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 17px;
}
.tabs button[aria-current="page"] {
  color: var(--accent-text);
  box-shadow: inset 0 3px 0 var(--accent);
}

/* 기록 화면 */
.day-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
}
.day-title { text-align: center; }
.day-title h1 { font-size: 17px; line-height: 1.3; }
.day-title .quiet { min-height: 26px; padding: 0 4px; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }

#record-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px 12px;
  padding-bottom: 6px;
}

.field-label {
  display: block;
  font-size: 16px;
}

.weight-field {
  grid-column: 1 / -1;
  display: block;
  padding: 14px 18px 12px;
  border-radius: 26px;
  background: var(--tile1);
  box-shadow: 0 6px 0 var(--tile1-edge);
  color: var(--accent-text);
  text-align: center;
}
.weight-entry {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}
.weight-entry input {
  width: 2.24em;
  max-width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0;
  background: none;
  color: var(--accent-text);
  font-size: 70px;
  line-height: 1.15;
  text-align: center;
}
.weight-entry input::placeholder { color: var(--tile1-faint); }
.weight-field:focus-within { box-shadow: 0 6px 0 var(--tile1-edge), 0 0 0 3px var(--accent); }
.weight-unit { font-size: 24px; }

#weight-error { grid-column: 1 / -1; }

.meal-field {
  display: block;
  min-width: 0;
  min-height: 124px;
  padding: 12px 14px;
  border-radius: 24px;
  background: var(--tile2);
  box-shadow: 0 6px 0 var(--tile2-edge);
  color: var(--tile2-text);
}
.meal-field textarea {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 0;
  border: 0;
  outline: 0;
  overflow: hidden;
  resize: none;
  background: none;
  font-size: 16px;
  line-height: 1.4;
}
.meal-field textarea::placeholder { color: var(--tile2-faint); }
.meal-field:focus-within { box-shadow: 0 6px 0 var(--tile2-edge), 0 0 0 3px var(--accent); }

.exercise-toggle {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 124px;
  padding: 10px;
  border-radius: 24px;
  background: var(--tile3);
  box-shadow: 0 6px 0 var(--tile3-edge);
  color: var(--tile3-text);
  cursor: pointer;
}
.exercise-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.check {
  order: 2;
  width: 46px;
  height: 46px;
  border: 3px dashed var(--check-edge);
  border-radius: 50%;
  background: none;
}
.exercise-toggle input:checked + .check {
  border: 0;
  background: var(--sticker) center / 27px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M9 15.5S2 11 2 6.5C2 3 6.5 2 9 5.5 11.5 2 16 3 16 6.5 16 11 9 15.5 9 15.5z' fill='%23fff'/%3E%3C/svg%3E");
  transform: rotate(-8deg);
}
.exercise-toggle input:focus-visible + .check {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.block {
  margin-top: 20px;
  padding: 16px 20px 20px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 6px 0 var(--line);
}
.block h2 { font-size: 18px; }

#view-calendar .block { margin-top: 8px; padding-top: 10px; }

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -8px 4px;
}

.weekdays, .calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  text-align: center;
}
.weekdays {
  color: var(--ink-soft);
  font-size: 14px;
  margin-bottom: 2px;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 1px;
  min-height: 64px;
  padding: 6px 0 4px;
  border: 0;
  border-radius: 16px;
  background: none;
  font-size: 16px;
  line-height: 1.3;
}
.day-cell:disabled { color: var(--day-off); cursor: default; }
.day-cell.today { color: var(--accent); }
.day-cell[aria-current="date"] { background: var(--tile1); color: var(--accent-text); }
.day-cell .marks {
  display: flex;
  gap: 3px;
  height: 13px;
  align-items: center;
}

.day-weight {
  min-height: 15px;
  color: var(--accent-text);
  font-size: 12px;
  line-height: 15px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.mark-exercise {
  display: inline-block;
  width: 13px;
  height: 13px;
  background: var(--mark-2);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M3 9.5l4 4 8-9' fill='none' stroke='%23000' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M3 9.5l4 4 8-9' fill='none' stroke='%23000' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.legend {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 14px;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.range { display: flex; padding: 3px; border-radius: 12px; background: var(--ground); }
.range button {
  min-height: 34px;
  padding: 2px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-soft);
  font-size: 15px;
}
.range button[aria-pressed="true"] { background: var(--surface); color: var(--accent-text); }

.chart {
  position: relative;
  min-height: 72px;
}
.chart svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
  overflow: visible;
}
.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.c-line { fill: none; stroke: var(--chart-line); }
.c-dot { fill: var(--chart-line); stroke: var(--surface); }
.c-goal { stroke: var(--chart-goal); }
.c-grid { stroke: var(--chart-grid); }
.c-cursor { stroke: var(--chart-cursor); }
.chart text {
  font-family: var(--body);
  font-size: 12px;
  fill: var(--ink-soft);
}
.chart .value-text { fill: var(--ink); font-weight: 700; font-size: 13px; }
.chart-tip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
}
.chart-empty {
  padding: 16px 0;
  color: var(--ink-soft);
  font-size: 16px;
}

.goal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  font-size: 16px;
}
.goal-row .quiet { flex: none; margin-left: auto; text-decoration: underline; text-underline-offset: 3px; }

/* 내기 화면 */
.bet-empty {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 24px;
}
.bet-empty h1 { font-size: 28px; line-height: 1.3; color: var(--accent-text); }
.bet-empty p { font-family: var(--body); color: var(--ink-soft); }
.bet-empty .primary { margin-top: 8px; }

.bet-period {
  padding-top: 8px;
  color: var(--ink-soft);
  font-size: 15px;
}
.bet-headline {
  margin-top: 2px;
  color: var(--accent-text);
  font-size: 28px;
  line-height: 1.3;
}

.score {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 18px;
}
.side {
  min-width: 0;
  padding: 14px 16px;
  border-radius: 24px;
  background: var(--tile1);
  box-shadow: 0 6px 0 var(--tile1-edge);
  color: var(--accent-text);
}
.side.other {
  background: var(--tile3);
  box-shadow: 0 6px 0 var(--tile3-edge);
  color: var(--tile3-text);
}
.who { display: block; font-size: 18px; }
.amount {
  display: block;
  font-size: 52px;
  line-height: 1.15;
}
.amount small { font-size: 20px; margin-left: 3px; }
.verb, .goal-line { display: block; font-size: 15px; }
.goal-line:empty { display: none; }

.tug {
  position: relative;
  height: 76px;
  margin-top: 20px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 6px 0 var(--line);
}
.rope {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 32px;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--tile1) 0 50%, var(--tile3) 50% 100%);
}
.tug-line {
  position: absolute;
  top: 24px;
  height: 28px;
  left: 50%;
  border-left: 2px solid var(--ink-faint);
  transform: translateX(-1px);
}
.knot {
  position: absolute;
  top: 19px;
  left: 50%;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--sticker) center / 20px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M9 15.5S2 11 2 6.5C2 3 6.5 2 9 5.5 11.5 2 16 3 16 6.5 16 11 9 15.5 9 15.5z' fill='%23fff'/%3E%3C/svg%3E");
  box-shadow: 0 3px 0 var(--tile1-edge);
  transition: left 800ms cubic-bezier(.3, 1.3, .5, 1);
}

.bet-note {
  margin-top: 18px;
  padding: 0 4px;
  color: var(--ink-soft);
  font-family: var(--body);
  font-size: 14px;
}
#bet-edit { text-decoration: underline; text-underline-offset: 3px; }

/* 테마 고르기 */
.settings-label { color: var(--ink-soft); font-size: 15px; }
.themes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.theme-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 84px;
  padding: 10px 2px 8px;
  border: 0;
  border-radius: 16px;
  background: var(--ground);
  color: var(--ink);
  font-size: 15px;
}
.theme-choice[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--accent); }
.theme-choice i {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}
.swatch-jelly { background: linear-gradient(135deg, #ffc4d8 50%, #bdeed6 50%); }
.swatch-scale { background: #3f4fc2; }
.swatch-planner { background: linear-gradient(135deg, #ffd65a 50%, #ff96b4 50%); }
.swatch-game { background: linear-gradient(90deg, #e8413c 33%, #ffd95e 33% 66%, #3a53c5 66%); border-radius: 0 !important; }
.swatch-receipt { background: #fff; box-shadow: inset 0 0 0 2px #2b2b2b; border-radius: 4px !important; }
.swatch-cat { background: #ffbe73; }

/* 작은 창 */
dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: 26px;
  color: var(--ink);
}
dialog::backdrop { background: rgba(93, 35, 64, .4); }
dialog form, .settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
dialog h2 { font-size: 22px; color: var(--accent-text); }
dialog p { color: var(--ink-soft); font-family: var(--body); font-size: 15px; }
dialog .field-label { font-size: 15px; color: var(--ink-soft); }
.field { display: block; }
.field input {
  width: 100%;
  min-height: 50px;
  margin-top: 4px;
  padding: 10px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--ground);
  font-family: var(--body);
  font-size: 16px;
}
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.dialog-actions .primary { width: auto; min-width: 88px; min-height: 46px; font-size: 16px; }
.dialog-actions #goal-clear { margin-right: auto; }

.wide {
  min-height: 50px;
  padding: 10px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--ground);
  text-align: left;
}

@media (max-width: 359px) {
  .weight-entry input { font-size: 58px; }
  .amount { font-size: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .knot { transition: none; }
}
