:root {
  --bg: #F8F3EA;
  --primary: #5B4636;
  --accent: #2F4A3A;
  --card: #FFFFFF;
  --border: #D8CBBB;
  --text: #2A2420;
  --muted: #7A6B5D;
  --soft: #EFE6D8;
  --ok-bg: #E6EFE8;
  --ok: #2F4A3A;
  --warn-bg: #FBEDE3;
  --warn: #9A4A1F;
  --danger: #8E3B2E;
  --radius: 14px;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* 헤더 */
.app-header {
  background: var(--primary);
  color: #FBF6EE;
  padding: calc(18px + env(safe-area-inset-top)) 16px 18px;
  border-bottom: 4px solid #3F3026;
}
.header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; max-width: 720px; margin: 0 auto; }
.app-header h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; font-family: "Nanum Myeongjo", "AppleMyungjo", "Batang", serif; }
.lead { margin: 4px 0 0; font-size: 15px; opacity: .9; }
.ios-hint { max-width: 720px; margin: 12px auto 0; font-size: 14px; background: rgba(255,255,255,.12); padding: 10px 12px; border-radius: 10px; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

h2 { font-size: 20px; margin: 4px 0 12px; color: var(--primary); }
h3 { font-size: 17px; margin: 0 0 8px; color: var(--primary); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 0 rgba(91,70,54,.06);
}

.field-label { display: block; font-weight: 700; margin: 4px 0 6px; font-size: 15px; color: var(--primary); }
.field-label + textarea { margin-bottom: 10px; }

textarea, select, input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: #FFFDF9;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.6; }
textarea:focus, select:focus { outline: 3px solid rgba(47,74,58,.25); border-color: var(--accent); }

.row { margin: 8px 0; }
.help { font-size: 14px; color: var(--muted); margin: 6px 0 10px; }

/* 버튼 */
.btn {
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  min-height: 52px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #FFF9F0; flex: 1 1 auto; }
.btn-secondary { background: var(--soft); color: var(--primary); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-copy { background: var(--accent); color: #fff; width: 100%; font-size: 17px; min-height: 56px; }
.btn-copy.is-done { background: #4D7A5F; }
.btn-danger { background: transparent; color: var(--danger); border-color: #D9B3AA; }
.btn-install { background: #FBF6EE; color: var(--primary); min-height: 44px; padding: 8px 14px; flex: none; font-size: 15px; }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btn-row .btn-ghost { flex: 0 0 auto; }

.file-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.text-link { color: var(--accent); font-weight: 700; font-size: 15px; }

/* 결과 */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.info-label { display: block; font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.info-block { margin-top: 12px; }
.chip {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 15px;
}
.chip-type { background: var(--primary); color: #FFF9F0; }
.chip-pos { background: var(--ok-bg); color: var(--ok); }
.chip-neg { background: var(--warn-bg); color: var(--warn); }
.chip-mix { background: #F3EBD2; color: #7A5A12; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-list .chip { font-weight: 600; font-size: 14px; }
.chip-kw { background: #E3ECE5; color: var(--accent); }

.draft { border-left: 5px solid var(--accent); }
.best-card { background: #F1F6F2; border-color: #B9CDBF; }
.best-card .draft { margin-bottom: 0; }
.draft-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.draft-title { font-weight: 800; color: var(--accent); }
.char-count { font-size: 13px; color: var(--muted); }
.draft-text { min-height: 150px; background: #FFFEFB; font-size: 16px; }

.validate { font-size: 14px; margin: 8px 0 10px; padding: 8px 10px; border-radius: 10px; }
.validate:empty { display: none; }
.validate.ok { background: var(--ok-bg); color: var(--ok); }
.validate.bad { background: var(--warn-bg); color: var(--warn); }
.validate .bad-char { display: inline-block; background: #fff; border: 1px solid #E5C4AE; border-radius: 6px; padding: 0 6px; margin: 2px 4px 2px 0; font-family: ui-monospace, monospace; }
.validate .btn { margin-top: 6px; }

.problems { margin: 6px 0 0; padding-left: 20px; }
.problems li { margin: 2px 0; }
.problems.none { list-style: none; padding-left: 0; color: var(--ok); font-weight: 700; }

.quote {
  white-space: pre-wrap;
  background: #FBF7F0;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 4px 0 10px;
  font-size: 15px;
}
.quote.empty { color: var(--muted); font-style: italic; }

.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.item-no { font-weight: 800; color: var(--primary); }
.sub-label { font-size: 13px; color: var(--muted); font-weight: 700; margin-top: 10px; display: block; }

.stat-list { margin: 0; padding-left: 20px; }
.stat-list li { margin: 2px 0; }

.guide-section ul { margin: 0; padding-left: 20px; }
.guide-section li { margin: 4px 0; white-space: pre-wrap; }

.history-item .meta { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.history-reply { margin-top: 10px; }

.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 700; min-height: 44px; }
.switch-row input { width: 24px; height: 24px; accent-color: var(--accent); }

.empty-state { text-align: center; color: var(--muted); padding: 24px 8px; }

.notice {
  margin: 20px 0 8px;
  padding: 12px 14px;
  background: #EFE6D8;
  border-radius: 12px;
  color: var(--primary);
  font-size: 14px;
  text-align: center;
  font-weight: 600;
}

/* 하단 탭바 */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #FFFBF5;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 20;
  box-shadow: 0 -4px 14px rgba(91,70,54,.08);
}
.tab-btn {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
}
.tab-ico { font-size: 20px; line-height: 1; }
.tab-btn.is-active { color: var(--primary); }
.tab-btn.is-active .tab-ico { color: var(--accent); }
.tab-btn.is-active::after { content: ""; width: 26px; height: 3px; border-radius: 3px; background: var(--accent); margin-top: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 30;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 720px) {
  body { font-size: 16px; }
  .tab-btn { font-size: 13px; }
}
