:root {
  --green: #3f9b4a;
  --green-dark: #2f7a39;
  --green-soft: #eaf5eb;
  --bg: #f3f5f2;
  --card: #fff;
  --ink: #1f2420;
  --muted: #6b736c;
  --line: #e2e6e1;
  --alert: #e5484d;
  --alert-soft: #fdecec;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
.container {
  max-width: 600px;
  margin: 0 auto;
  background: var(--card);
  min-height: 100vh;
  box-shadow: 0 0 24px rgba(0,0,0,.05);
  display: flex;
  flex-direction: column;
}

/* header */
.hero {
  background: linear-gradient(135deg, #4caf50, var(--green-dark));
  color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 18px 16px;
  text-align: center;
}
.hero h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.02em; }
.hero p { margin: 6px 0 0; font-size: .88rem; opacity: .92; }
.home-btn {
  display: block;
  width: fit-content;
  margin: 0 auto 8px 0;
  padding: 6px 16px;
  background: #fff;
  border-radius: 999px;
  color: var(--green-dark);
  font-size: .88rem; font-weight: 700;
  text-decoration: none;
  line-height: 1.4;
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
.home-btn:hover, .home-btn:focus-visible { background: var(--green-soft); }
.home-btn:active { background: #d9ecdb; }

/* tabs (4×2 격자, 스크롤 없음) */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 8px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.tab {
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  padding: 8px 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font: inherit; font-size: .78rem; font-weight: 600;
  letter-spacing: -.03em; line-height: 1.25;
  color: #4a524b;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.tab-emoji { font-size: 1.3rem; line-height: 1.2; }
.tab.active { background: var(--green); border-color: var(--green); color: #fff; }
@media (min-width: 521px) {
  .tab { font-size: .9rem; padding: 10px 4px; }
}
@media (max-width: 340px) {
  .tab { font-size: .7rem; }
}
/* option panel */
.panel { padding: 20px 18px 22px; display: flex; flex-direction: column; gap: 12px; }
.panel-title { margin: 0 0 2px; font-size: 1.2rem; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.choice input { accent-color: var(--green); width: 18px; height: 18px; margin: 0; }
.choice:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.choice-body { flex: 1; display: flex; flex-direction: column; }
.choice-label { font-weight: 700; }
.choice-desc { font-size: .82rem; color: var(--muted); }
.choice-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--green-dark); }

.check {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  background: #f8f9f7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: .93rem;
  cursor: pointer;
}
.check input { accent-color: var(--green); width: 18px; height: 18px; margin: 0; }

.summary { margin: 4px 0 0; font-size: 1rem; }
.summary strong { color: var(--green-dark); font-size: 1.15rem; }
.hint { margin: -6px 0 0; font-size: .85rem; color: var(--muted); }

.start-btn {
  width: 100%;
  padding: 15px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font: inherit; font-size: 1.08rem; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(63,155,74,.28);
  transition: transform .08s, background .15s;
}
.start-btn:active { transform: scale(.98); background: var(--green-dark); }

/* custom */
.custom-row { display: flex; gap: 10px; }
.num { flex: 1; display: flex; align-items: center; gap: 8px; border: 1.5px solid var(--line); border-radius: var(--radius); padding: 6px 14px; }
.num input { width: 100%; border: 0; font: inherit; font-size: 1.8rem; font-weight: 700; text-align: right; outline: none; background: none; font-variant-numeric: tabular-nums; }
.num span { color: var(--muted); font-weight: 600; }
.num:focus-within { border-color: var(--green); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset { padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font: inherit; font-size: .88rem; cursor: pointer; }
.preset:active { background: var(--green-soft); }
.text-input { width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--radius); font: inherit; outline: none; }
.text-input:focus { border-color: var(--green); }

/* timers */
.timer-section { padding: 18px; background: #f8faf7; border-top: 1px solid var(--line); border-bottom: 8px solid #eef1ed; }
.timer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.timer-head h2 { margin: 0; font-size: 1.02rem; }
.wake-status { font-size: .78rem; color: var(--green-dark); white-space: nowrap; }
.link-btn {
  margin-left: auto;
  padding: 7px 12px; min-height: 36px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #f4f6f3; color: #333;
  font: inherit; font-size: .82rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.link-btn:active { background: #e9ece8; }
/* 두 번째 버튼(전체 삭제): 빨간 글자, 첫 버튼 바로 옆에 붙임 */
.link-btn + .link-btn { margin-left: 0; color: var(--alert); }
/* 첫 버튼이 숨겨져 있으면 전체 삭제가 오른쪽 끝으로 */
.link-btn[hidden] + .link-btn { margin-left: auto; }

@media (max-width: 520px) {
  /* 폰: 제목 줄 아래에 두 버튼을 가로로 나란히 꽉 차게 */
  .link-btn, .link-btn + .link-btn, .link-btn[hidden] + .link-btn {
    flex: 1 1 calc(50% - 5px); margin-left: 0; text-align: center;
  }
}
.timer-list { display: flex; flex-direction: column; gap: 10px; }
.empty { margin: 0; color: var(--muted); font-size: .9rem; }

.timer {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.timer-bar {
  position: absolute; left: 0; bottom: 0; height: 4px; width: 100%;
  background: var(--green);
  transform-origin: left; transform: scaleX(0);
  transition: transform .25s linear;
}
.timer-info { flex: 1; min-width: 0; }
.timer-title { font-weight: 700; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer-time { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.2; }
.timer-actions { display: flex; flex-direction: column; gap: 5px; }
.icon-btn {
  padding: 6px 10px; min-width: 76px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #f4f6f3; color: #333;
  font: inherit; font-size: .8rem; font-weight: 600;
  cursor: pointer;
}
.icon-btn:disabled { opacity: .55; cursor: default; }
.icon-btn.danger { color: var(--alert); }
.timer.paused .timer-time { color: var(--muted); }
.timer.paused .timer-bar { background: #b9c0b9; }
.timer.done { background: var(--alert-soft); border-color: #f3b5b7; }
.timer.done .timer-bar { background: var(--alert); }
.timer.ringing { animation: ring 1s ease-in-out infinite; border-color: var(--alert); }
.timer.ringing .icon-btn:nth-child(2) { background: var(--alert); border-color: var(--alert); color: #fff; }
@keyframes ring { 0%,100% { box-shadow: 0 0 0 0 rgba(229,72,77,.0); } 50% { box-shadow: 0 0 0 6px rgba(229,72,77,.25); } }

/* ads */
.ad { margin: 0 18px; }
.ad.ad-live { margin: 14px 18px; min-height: 90px; }
.ad.ad-placeholder {
  margin: 14px 18px;
  min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px dashed #cfd5ce; border-radius: 10px;
  color: #a3aba3; font-size: .8rem; letter-spacing: .1em;
  background: repeating-linear-gradient(45deg, #fafbfa, #fafbfa 8px, #f4f6f3 8px, #f4f6f3 16px);
}
.guide .ad { margin: 18px 0; }

/* guide */
.guide { padding: 6px 18px 26px; color: #444; }
.guide h2 { font-size: 1.15rem; color: var(--ink); border-bottom: 2px solid var(--green); padding-bottom: 6px; margin: 24px 0 10px; }
.guide p, .guide li { font-size: .93rem; color: #555; margin: 6px 0; }
.guide ul { padding-left: 20px; }
.note { background: var(--green-soft); padding: 10px 12px; border-radius: 10px; }
.food-tips { padding-bottom: 6px; }
.tip { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 8px 0; background: #fff; }
.tip summary { cursor: pointer; font-weight: 700; color: var(--green-dark); font-size: .95rem; }
.tip p { margin: 8px 0 2px; }
.time-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.time-table th, .time-table td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
.time-table th { background: #f6f8f5; color: var(--ink); }
.time-table td:first-child { font-weight: 700; white-space: nowrap; }

footer { margin-top: auto; text-align: center; padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); font-size: .8rem; color: #888; background: var(--bg); }
footer p { margin: 2px 0; }
footer a { color: #888; }
/* 링크 색 통일 (방문 전/후 모두 초록 계열, 음식 카드는 제외) */
.guide a:not(.food-card), .guide a:not(.food-card):visited { color: var(--green-dark); }
.guide a:not(.food-card):hover, .guide a:not(.food-card):focus-visible { color: var(--green); }

@media (prefers-reduced-motion: reduce) {
  .timer.ringing { animation: none; }
  .timer-bar { transition: none; }
}
.timer-phase { margin-top: 4px; font-size: .85rem; color: var(--green-dark); }
.food-card { word-break: keep-all; overflow-wrap: break-word; }
body { word-break: keep-all; overflow-wrap: break-word; }
.guide p { word-break: keep-all; overflow-wrap: break-word; }

/* 맨 위로 버튼 */
.to-top {
  position: fixed;
  right: max(16px, calc((100vw - 600px) / 2 + 16px));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%;
  background: var(--green); color: #fff;
  font: inherit; font-size: 1.4rem; font-weight: 700; line-height: 1;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  cursor: pointer;
  z-index: 50;
  -webkit-tap-highlight-color: transparent;
}
.to-top[hidden] { display: none; }
.to-top:active { background: var(--green-dark); transform: scale(.94); }
.to-top:focus-visible { outline: 3px solid var(--green-soft); outline-offset: 2px; }
