/* 폰을 기본으로 쓰고, 넓은 화면은 min-width 로 더한다. */
:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #15191e;
  --muted: #566170;
  --line: #dde2e8;
  --field: #aab3bf;
  --accent: #0d6657;
  --accent-soft: #e2f1ed;
  --warn: #8a4600;
  --tap: 44px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--bg);
  color: var(--ink);
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Noto Sans CJK KR", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: rgba(13, 102, 87, 0.14);
}
::selection { background: #bfe3da; color: var(--ink); }
[hidden] { display: none !important; }
a, button, input, select, textarea, label { touch-action: manipulation; }
a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.site, .top, main, .foot { max-width: 860px; margin-inline: auto; padding-inline: 16px; }

.site a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}
.top { padding-top: 12px; padding-bottom: 14px; }
.site + .top { padding-top: 0; }
.top h1 { margin: 0 0 2px; font-size: 1.4rem; line-height: 1.3; letter-spacing: -0.01em; text-wrap: balance; }
.top p { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* 첫 화면 */
.search { margin-bottom: 8px; }
.search input { background-color: var(--surface); }
.sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.group { margin: 18px 0 6px; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.tools {
  margin: 0; padding: 0; list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.tools li + li { border-top: 1px solid var(--line); }
.tools a {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 52px;
  padding: 8px 14px;
  color: inherit;
  text-decoration: none;
}
.tools a:active { background: var(--accent-soft); }
.tools strong { font-size: 1rem; font-weight: 600; line-height: 1.35; }
.tools span { display: none; color: var(--muted); font-size: 0.875rem; line-height: 1.45; }
.no-result { margin: 14px 2px; color: var(--muted); }

/* 입력 */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  overflow: clip;
}
.single, .pan, .recipe-in, .recipe-out { min-width: 0; padding: 14px; }
.pan { margin: 0; border: 0; }
.pan + .pan, .recipe-out { border-top: 1px solid var(--line); }
legend { float: left; width: 100%; padding: 0; margin-bottom: 8px; font-weight: 700; font-size: 1.05rem; }
legend + * { clear: both; }
.field { min-width: 0; margin-bottom: 10px; }
.single > :last-child, .pan > :last-child { margin-bottom: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: start; }
.field-row .field { margin-bottom: 10px; }
.single > .field-row:last-child .field, .pan > .field-row:last-child .field { margin-bottom: 0; }
label { display: block; margin-bottom: 3px; color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
input, select, textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--field);
  border-radius: 8px;
  background-color: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px 아래면 아이폰이 입력할 때 화면을 확대한다 */
}
input[type="date"] { -webkit-appearance: none; appearance: none; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; }
select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23566170' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3.5 6 4.5 4.5L12.5 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
textarea { resize: vertical; line-height: 1.7; }
@media (max-width: 400px) {
  .field-row:has(input[type="date"]) { grid-template-columns: 1fr; gap: 0; }
}

/* 결과: 폰에서는 입력하는 동안 화면 아래에 붙어 있다 */
.result {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  background: var(--accent-soft);
  border-top: 1px solid #bcdcd4;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 -4px 14px rgba(21, 25, 30, 0.07);
}
.result-main {
  margin: 0;
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.result-sub { margin: 1px 0 0; color: #3f4a57; font-size: 0.85rem; line-height: 1.45; font-variant-numeric: tabular-nums; }
.result-warn, .problem { margin: 6px 0 0; color: var(--warn); font-size: 0.85rem; line-height: 1.45; }
.result.empty .result-main { color: #3f4a57; font-size: 1.1rem; }
.result-main:empty, .result-sub:empty { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  .result { position: static; box-shadow: none; }
}

.recipe-out-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.recipe-out h2 { margin: 0; font-size: 1rem; }
button.ghost {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 4px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
button.ghost:active { background: var(--accent-soft); }
button.ghost:disabled { opacity: 0.45; cursor: default; }
button.ghost[aria-pressed="true"] { background: var(--accent); color: #fff; }
.periods { display: flex; gap: 8px; }

/* 표 */
table { width: 100%; border-collapse: collapse; }
th { padding: 4px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; font-weight: 600; text-align: left; }
td { padding: 7px 0; border-bottom: 1px solid #edf0f3; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.num { padding-left: 10px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.num { font-weight: 700; }
td.same { color: var(--muted); font-weight: 400; }
.note { display: block; color: var(--muted); font-size: 0.8rem; }
.flag { margin-left: 4px; color: var(--muted); font-size: 0.75rem; font-weight: 400; }
#detail { overflow-x: auto; }
#table td:first-child { min-width: 2.2em; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.summary div { min-width: 0; }
.summary dt { color: #3f4a57; font-size: 0.78rem; }
.summary dd { margin: 0; color: var(--accent); font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.summary dd.small { font-size: 0.8rem; font-weight: 700; }

/* 순위 */
.ranking h2 { margin: 22px 0 6px; font-size: 1.15rem; line-height: 1.35; }
.ranking h2:first-child { margin-top: 4px; }
.ranks { margin: 8px 0 0; padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ranks li { display: grid; grid-template-columns: 2em minmax(0, 1fr); padding: 10px 14px 10px 8px; }
.ranks li + li { border-top: 1px solid var(--line); }
.rank-no { color: var(--muted); font-size: 0.9rem; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; line-height: 1.5; }
.rank-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; }
.rank-head a { display: inline-block; padding: 9px 0; margin: -9px 0; font-weight: 700; word-break: break-all; }
.rank-gain { color: var(--accent); font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rank-body p { margin: 2px 0 0; font-size: 0.92rem; line-height: 1.5; }
.rank-body .rank-meta { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.rank-meta span { white-space: nowrap; }
.guide code, .hint code { font-size: 0.9em; }

/* 설명글 */
.guide { padding: 26px 0 6px; }
.guide h2 { margin: 26px 0 6px; font-size: 1.15rem; line-height: 1.35; text-wrap: balance; }
.guide h2:first-child { margin-top: 0; }
.guide h3 { margin: 16px 0 2px; font-size: 1rem; }
.guide p { max-width: 42rem; margin: 6px 0; }
.guide ul { max-width: 42rem; margin: 6px 0; padding-left: 1.2em; }
.guide li { margin: 4px 0; }
.formula { padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-weight: 700; }
.table-wrap { max-width: 34rem; margin: 10px 0; padding: 4px 12px; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.sizes td:first-child { font-weight: 700; }
.muted { color: var(--muted); font-size: 0.9rem; }
.policy h2 { margin: 22px 0 4px; font-size: 1.1rem; }
.policy p { max-width: 42rem; margin: 4px 0; }

.foot { padding-top: 10px; padding-bottom: max(24px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 0.85rem; }
.foot p { margin: 4px 0; }
.foot a { display: inline-flex; align-items: center; min-height: var(--tap); }
@media (max-width: 400px) {
  .table-wrap .num { white-space: normal; }
  #table .num { padding-left: 6px; font-size: 0.82rem; }
}

/* 넓은 화면: 칸을 나란히 두고, 결과는 제자리에 둔다 */
@media (min-width: 720px) {
  .top { padding-top: 24px; padding-bottom: 16px; }
  .site + .top { padding-top: 4px; }
  .top h1 { font-size: 1.6rem; }
  .single, .pan, .recipe-in, .recipe-out { padding: 16px; }
  .pans, .recipe { display: grid; grid-template-columns: 1fr 1fr; }
  .pan + .pan, .recipe-out { border-top: 0; border-left: 1px solid var(--line); }
  .result { position: static; padding: 14px 16px; box-shadow: none; }
  .result-main { font-size: 1.5rem; }
  .summary dd { font-size: 1.25rem; }
  .tools { display: grid; grid-template-columns: 1fr 1fr; }
  .tools li + li { border-top: 0; }
  .tools li { border-bottom: 1px solid var(--line); }
  .tools li:nth-child(odd) { border-right: 1px solid var(--line); }
  .tools li:nth-last-child(1), .tools li:nth-last-child(2):nth-child(odd) { border-bottom: 0; }
  .tools a { height: 100%; min-height: 76px; }
  .tools span { display: block; }
  .tools a:hover { background: var(--accent-soft); }
  .tools strong { color: var(--accent); }
}
