/* ============================================================
   小小商店長・基礎樣式
   大字、暖色、低年級友善；不載入外部字型。
   ============================================================ */
:root {
  --ink: #332d26;
  --ink-soft: #5f574c;
  --muted: #7a7062;
  --paper: #fffaf0;
  --cream: #f7eedc;
  --cream-2: #efe1c7;
  --white: #fffdf8;
  --orange: #e2604a;
  --orange-dark: #b84332;
  --peach: #f6b39b;
  --gold: #f7c45f;
  --gold-dark: #c99327;
  --green: #5aa469;
  --green-dark: #3d7d4b;
  --blue: #4a7fb5;
  --blue-dark: #2f5e8d;
  --pink: #e88b9b;
  --brown: #8a5a2b;
  --line: #e6d8be;
  --shadow: 0 12px 30px rgba(91, 66, 37, .13);
  --shadow-soft: 0 5px 16px rgba(91, 66, 37, .1);
  --radius: 24px;
  --radius-sm: 14px;
  --topbar-h: 76px;
  --font: "PingFang TC", "PingFang HK", "Microsoft JhengHei", "Noto Sans TC", "Heiti TC", "Apple LiGothic", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  min-width: 320px;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(247, 196, 95, .16), transparent 26rem),
    radial-gradient(circle at 88% 18%, rgba(90, 164, 105, .12), transparent 24rem),
    var(--paper);
  line-height: 1.65;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue-dark); text-underline-offset: .18em; }
h1, h2, h3, p { margin: 0 0 .65em; }
h1 { line-height: 1.18; letter-spacing: -.02em; }
h2 { line-height: 1.25; }
ul, ol { margin: 0; padding-left: 1.3em; }
[hidden] { display: none !important; }
:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }
::selection { background: var(--gold); color: var(--ink); }

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 200;
  padding: .7rem 1.1rem;
  border-radius: 0 0 12px 12px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}
.skip-link:focus { top: 0; }

.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }
main { flex: 1; width: min(1180px, 100%); margin: 0 auto; padding: 1.1rem clamp(.9rem, 2.6vw, 2rem) 2rem; }
main:focus { outline: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .45rem clamp(.7rem, 2.5vw, 1.8rem);
  padding-top: max(.45rem, env(safe-area-inset-top));
  background: rgba(255, 250, 240, .92);
  border-bottom: 1px solid rgba(230, 216, 190, .85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 48px;
  padding: .2rem .35rem;
  border: 0;
  border-radius: 16px;
  background: transparent;
  text-align: left;
}
.brand:hover { background: var(--cream); }
.brand-mark { width: 46px; height: 46px; flex: 0 0 auto; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 1.02rem; letter-spacing: .02em; }
.brand-text small { font-size: .68rem; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: .25rem; }

.icon-btn {
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .35rem .55rem;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 700;
}
.icon-btn svg { width: 23px; height: 23px; flex: 0 0 auto; }
.icon-btn:hover { background: var(--cream); color: var(--ink); }
.icon-btn:active { transform: translateY(1px); }
.icon-label { font-size: .68rem; }
.icon-btn.is-active { background: var(--gold); color: var(--ink); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 50px;
  padding: .65rem 1.15rem;
  border: 2px solid transparent;
  border-radius: 999px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--orange); color: #fff; box-shadow: 0 6px 0 var(--orange-dark); }
.btn-primary:hover { background: #ec6c57; }
.btn-primary:active { box-shadow: 0 2px 0 var(--orange-dark); }
.btn-soft { background: var(--cream); color: var(--ink); border-color: var(--line); }
.btn-soft:hover { background: var(--cream-2); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--cream); }
.btn-danger { background: #fff0ed; color: #a93625; border-color: #efb5aa; }
.btn-danger:hover { background: #ffe1da; }
.btn-link { background: transparent; border: 0; color: var(--blue-dark); text-decoration: underline; min-height: 44px; padding: .4rem .7rem; }
.btn-small { min-height: 44px; padding: .45rem .8rem; font-size: .85rem; }
.btn-hero { min-height: 58px; padding: .8rem 1.7rem; font-size: 1.12rem; }

.eyebrow {
  margin: 0 0 .25rem;
  color: var(--orange-dark);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .14em;
}
.muted { color: var(--muted); }
.small-note { font-size: .8rem; }

.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: .5rem .75rem calc(.5rem + env(safe-area-inset-bottom));
  background: #2f2a22;
  color: #f6ead3;
  text-align: center;
  font-size: .7rem;
  line-height: 1.6;
}
body { padding-bottom: calc(3.4rem + env(safe-area-inset-bottom)); }
.site-footer a { color: #ffd166; font-weight: 700; }

/* ------------------------------ 對話框 ------------------------------ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  background: rgba(35, 29, 22, .55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.modal-panel {
  width: min(620px, 100%);
  max-height: min(88dvh, 900px);
  overflow: auto;
  padding: clamp(1rem, 3vw, 1.6rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(24, 18, 12, .35);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .8rem;
}
.modal-head h2 { margin: 0; font-size: 1.3rem; }
.modal-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
.modal-foot { margin: 1rem 0 0; color: var(--muted); font-size: .72rem; text-align: center; }
.confirm-panel { width: min(460px, 100%); }
.intro-panel { width: min(700px, 100%); }
.intro-visual { margin: .4rem 0 .8rem; overflow: hidden; border-radius: 18px; background: var(--cream); }
.intro-visual img { width: 100%; height: 190px; object-fit: cover; }
.intro-story { font-size: 1.02rem; }
.intro-tips { padding: .8rem 1rem; border-radius: 16px; background: var(--cream); }
.intro-tips ul { margin: .2rem 0; }

/* ------------------------------ 設定 ------------------------------ */
.settings-group { padding: .8rem 0; border-top: 1px solid var(--line); }
.settings-group:first-of-type { border-top: 0; }
.settings-group h3 { margin: 0 0 .55rem; font-size: 1rem; color: var(--orange-dark); }
.switch-row, .range-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 52px;
  padding: .35rem 0;
}
.switch-row span, .range-row span { display: flex; flex-direction: column; min-width: 0; }
.switch-row b { font-size: .95rem; }
.switch-row small { color: var(--muted); font-size: .75rem; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  position: relative;
  width: 58px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #d9cdb8;
  transition: background .18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  transition: transform .18s ease;
}
.switch-row input:checked + .switch { background: var(--green); }
.switch-row input:checked + .switch::after { transform: translateX(24px); }
.switch-row input:focus-visible + .switch { outline: 4px solid var(--blue); outline-offset: 3px; }
.range-row { flex-wrap: wrap; }
.range-row input[type="range"] { flex: 1 1 160px; min-width: 120px; accent-color: var(--orange); min-height: 44px; }
.range-row output { min-width: 3.5rem; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.progress-note { min-height: 1.4em; margin: .35rem 0; color: var(--green-dark); font-size: .82rem; }

/* ------------------------------ 計算紙 ------------------------------ */
.scratch-overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(35, 29, 22, .5);
}
.scratch-panel {
  width: min(620px, 100%);
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}
#scratch-canvas {
  width: 100%;
  height: min(48dvh, 340px);
  touch-action: none;
  border: 2px dashed var(--line);
  border-radius: 16px;
  background:
    linear-gradient(rgba(74,127,181,.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74,127,181,.09) 1px, transparent 1px),
    #fffdf8;
  background-size: 28px 28px;
}

/* ------------------------------ 提示 ------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  z-index: 160;
  transform: translateX(-50%);
  width: min(92vw, 520px);
  padding: .75rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fffaf0;
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 700;
  font-size: .9rem;
}
.toast.is-error { background: #8f2f22; }

@media (max-width: 640px) {
  html { font-size: 17px; }
  .brand-text small { display: none; }
  .icon-label { display: none; }
  .icon-btn { padding: .3rem; }
  .topbar { gap: .2rem; }
  main { padding-top: .8rem; }
  .modal { padding: .55rem; }
  .modal-panel { max-height: 92dvh; border-radius: 20px; }
  .btn { min-height: 48px; }
}

@media print {
  .topbar, .site-footer, .certificate-actions, .skip-link, .toast { display: none !important; }
  body { background: #fff; }
  main { padding: 0; width: 100%; }
  .certificate { box-shadow: none; }
}
