/* ワタシの電卓 - 見た目(色は config.js で変更できます) */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--c-bg); }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--c-number);
  --fs: 18px;
  overscroll-behavior: none;
}
body.fs-s { --fs: 16px; }
body.fs-m { --fs: 18px; }
body.fs-l { --fs: 22px; }

button { font: inherit; color: inherit; }

#app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 640px; margin: 0 auto;
  background: var(--c-bg);
}

/* 上部バー */
#topbar {
  display: flex; background: var(--c-bar); color: var(--c-barText);
  padding-top: env(safe-area-inset-top);
  flex: none;
}
#topbar button {
  flex: 1; border: 0; background: transparent; color: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 2px 6px; cursor: pointer;
}
#topbar button:active { background: rgba(255,255,255,.15); }
#topbar .ic { font-size: 20px; line-height: 1.1; }
#topbar .lb { font-size: 11px; }

/* 行リスト */
#list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 0 0; }
.row {
  display: grid; grid-template-columns: 2.6em minmax(0, 1fr) auto;
  align-items: start; border-bottom: 1px solid var(--c-line);
  font-size: var(--fs);
}
.row.active { background: var(--c-activeRow); }
.num {
  color: var(--c-rowNum); text-align: right; padding: 0 .5em 0 0;
  font-size: .72em; line-height: 3.47; font-variant-numeric: tabular-nums;
  user-select: none; cursor: pointer;
}
.cell { position: relative; min-width: 0; }
.hl, .cell textarea {
  font: inherit; font-size: 1em; line-height: 2.5; letter-spacing: 0;
  padding: 0 .3em; margin: 0; border: 0;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-all;
}
.hl { min-height: 2.5em; pointer-events: none; }
.cell textarea {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background: transparent; resize: none; outline: none; overflow: hidden;
  color: transparent; -webkit-text-fill-color: transparent;
  caret-color: var(--c-number);
}
.hl .t { color: var(--c-text); }
.hl .tax { color: var(--c-text); font-weight: 700; }
.hl .n { color: var(--c-number); }
.hl .nb { color: var(--c-numberBare); }
.hl .o { color: var(--c-operator); font-weight: 600; }
.hl .r { color: var(--c-ref); }
.res {
  white-space: pre-line; text-align: right; padding: 0 .6em 0 .3em; line-height: 2.5;
  max-width: 48vw; overflow-wrap: anywhere; color: var(--c-result);
  font-variant-numeric: tabular-nums; font-weight: 600; min-width: 1em;
}
.res.err { color: var(--c-error); font-size: .62em; font-weight: 500; line-height: 4; }
.filler { min-height: 35vh; }

/* 合計・税バー */
#total {
  flex: none; background: var(--c-totalBg); padding: 6px 14px 7px;
  border-top: 1px solid var(--c-line);
}
.cat-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 3px; }
#catSeg { display: flex; }
#catSeg button {
  border: 1px solid var(--c-keyOpText); background: transparent; color: var(--c-keyOpText);
  padding: 4px 14px; font-size: .8rem; margin-left: -1px; touch-action: none;
}
#catSeg button:first-child { border-radius: 7px 0 0 7px; margin-left: 0; }
#catSeg button:last-child { border-radius: 0 7px 7px 0; }
#catSeg button:only-child { border-radius: 7px; }
#catSeg button.on { background: var(--c-keyOpText); color: #fff; }
#total .tl { font-size: .8rem; opacity: .75; white-space: nowrap; }
#sumRows.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 18px; }
#sumRows.grid1 { display: block; }
.sumrow { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; min-width: 0; }
.sumrow .sl { font-size: .74rem; opacity: .75; white-space: nowrap; }
.sumrow .sv { font-size: 1rem; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.sumrow.main .sv { font-size: 1.15rem; }
#sumRows.grid1 .sumrow { justify-content: flex-end; }
#sumRows.grid1 .sumrow .sv { font-size: 1.5rem; }
.res.taxed::before { content: "税"; font-size: .6em; font-weight: 700; color: var(--c-keyOpText); border: 1px solid var(--c-keyOpText); border-radius: 4px; padding: 0 3px; margin-right: 6px; vertical-align: middle; }
/* ABCキーボードのときだけ出す帯(「123」で計算キーに戻る) */
#taxbar {
  flex: none; display: none; gap: 8px; align-items: center;
  padding: 6px 10px; background: var(--c-padBg);
}
body.native #taxbar { display: flex; }
#taxbar .grow { flex: 1; }
.taxbtn {
  border: 0; border-radius: 8px; padding: 7px 18px; cursor: pointer;
  background: var(--c-keyOpBg); color: var(--c-keyOpText); font-weight: 700; touch-action: none;
}
.taxbtn:active, .taxbtn.down { filter: brightness(.9); }
.taxbtn[hidden] { display: none; }

/* キーパッド(5列×4行) */
#pad {
  flex: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--c-padBg);
}
body.native #pad { display: none; }
body.native #taxbar { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
#pad button {
  position: relative; min-width: 0; padding: 0;
  height: clamp(50px, 8.2vh, 66px); border: 0; border-radius: 9px; font-size: 1.3rem;
  background: var(--c-keyBg); color: var(--c-keyText);
  box-shadow: 0 1px 0 rgba(0,0,0,.22); touch-action: none; user-select: none; cursor: pointer;
}
#pad button.op { background: var(--c-keyOpBg); color: var(--c-keyOpText); font-weight: 700; }
#pad button.sub { background: var(--c-keySubBg); color: var(--c-keySubText); font-size: 1.05rem; }
#pad button.unit { background: var(--c-keySubBg); color: var(--c-keySubText); font-size: 1.05rem; font-weight: 700; }
#pad button.longlabel .kl { font-size: .72rem; }
#pad button.soon { opacity: .6; }
#pad button.down { filter: brightness(.88); transform: translateY(1px); }
/* フリックの目印:中央に文字があるキーは小さく控えめに、ないキー(演算子・単位)は読みやすく */
#pad .fm { position: absolute; font-size: .55rem; font-weight: 400; opacity: .55; line-height: 1; pointer-events: none; white-space: nowrap; }
#pad .fm.fu { top: 4px; left: 0; right: 0; text-align: center; }
#pad .fm.fd { bottom: 4px; left: 0; right: 0; text-align: center; }
#pad .fm.fl { left: 5px; top: 50%; transform: translateY(-50%); }
#pad .fm.fr { right: 5px; top: 50%; transform: translateY(-50%); }
#pad button.nolabel .fm { font-size: .82rem; font-weight: 700; opacity: 1; }
#pad button.nolabel .fm.fu { top: 3px; }
#pad button.nolabel .fm.fd { bottom: 3px; }
#pad button.nolabel .fm.fl { left: 4px; }
#pad button.nolabel .fm.fr { right: 4px; }

/* トースト */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 64px); /* 上部に出す(キーや税ボタンに重ならないように) */
  background: rgba(40,40,40,.92); color: #fff; padding: 9px 14px; border-radius: 20px;
  font-size: .9rem; display: flex; gap: 12px; align-items: center; z-index: 30; max-width: 92vw;
}
#toast[hidden] { display: none; }
#toast button { border: 0; background: transparent; color: #ffd27a; font-weight: 700; padding: 2px 4px; }

/* オーバーレイ */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; }
.overlay[hidden] { display: none; }
.sheet { background: var(--c-bg); display: flex; flex-direction: column; max-height: 100%; }
.sheet.side { width: min(86vw, 360px); height: 100%; padding-top: env(safe-area-inset-top); }
.sheet.full { width: 100%; max-width: 640px; margin: 0 auto; height: 100%; padding-top: env(safe-area-inset-top); }
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--c-bar); color: var(--c-barText); padding: 10px 14px; flex: none;
}
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.close { border: 1px solid rgba(255,255,255,.5); background: transparent; color: inherit; border-radius: 8px; padding: 5px 12px; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); line-height: 1.7; font-size: .95rem; }
.sheet-body h3 { margin: 20px 0 6px; font-size: 1rem; color: var(--c-bar); border-bottom: 1px solid var(--c-line); padding-bottom: 4px; }
.sheet-body p { margin: 4px 0; }
.about { display: flex; gap: 14px; align-items: center; margin-top: 14px; }
.about img { border-radius: 14px; }
.about-name { font-size: 1.3rem; font-weight: 700; }
.about-sub { opacity: .8; }
.about-ver { font-size: .8rem; opacity: .6; }
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; border: 1px solid var(--c-bar); background: transparent; border-radius: 8px; padding: 8px; color: var(--c-bar); }
.seg button.on { background: var(--c-bar); color: var(--c-barText); }
#noteList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#noteList li { display: flex; align-items: center; border-bottom: 1px solid var(--c-line); }
#noteList li.cur { background: var(--c-activeRow); }
#noteList .nt { flex: 1; text-align: left; border: 0; background: transparent; padding: 12px 14px; min-width: 0; }
#noteList .nt b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#noteList .nt small { opacity: .6; }
#noteList .del { border: 0; background: transparent; color: var(--c-error); font-size: 1.1rem; padding: 12px 16px; }
.wide { margin: 10px; border: 0; border-radius: 8px; padding: 12px; background: var(--c-bar); color: var(--c-barText); }

/* スプラッシュ */
#splash {
  position: fixed; inset: 0; z-index: 100; background: var(--c-splashBg); color: var(--c-splashText);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  opacity: 1; transition: opacity var(--splash-fade) ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
#splash img { border-radius: 22px; margin-bottom: 14px; }
#splash h1 { margin: 0; font-size: 1.9rem; letter-spacing: .08em; }
#splash p { margin: 0; opacity: .85; }

/* 長さの画面 */
#unitbar { flex: none; display: flex; gap: 6px; align-items: center; padding: 5px 10px; background: var(--c-totalBg); border-bottom: 1px solid var(--c-line); }
#unitbar[hidden] { display: none; }
#unitbar .ul { font-size: .7rem; opacity: .75; margin-right: 2px; white-space: nowrap; }
#unitbar button { border: 1px solid var(--c-keyOpText); background: transparent; color: var(--c-keyOpText); border-radius: 7px; padding: 4px 10px; font-weight: 700; font-size: .92rem; white-space: nowrap; cursor: pointer; touch-action: none; }
#unitbar button.on { background: var(--c-keyOpText); color: #fff; }
#unitbar { flex-wrap: wrap; }
#cfgnote { flex: none; display: block; width: 100%; text-align: right; border: 0; border-bottom: 1px solid var(--c-line); background: var(--c-totalBg); color: var(--c-keyOpText); font-size: .72rem; padding: 3px 12px; cursor: pointer; text-decoration: underline; }
#cfgnote[hidden] { display: none; }
.tmbox { margin-top: 8px; }
.tmrow { display: flex; align-items: center; gap: 8px; margin: 6px 0; flex-wrap: wrap; }
.tmrow > span { min-width: 4.5em; font-size: .85rem; }
.tmrow .seg { flex: 1; min-width: 200px; }
.tmrow input, .tmrow select { font: inherit; padding: 6px; border: 1px solid var(--c-bar); border-radius: 8px; background: transparent; color: inherit; }
.tmrow input { width: 5.5em; }
#tmCalInfo { font-size: .8rem; margin: 2px 0; }
#foodbar { flex: none; display: flex; gap: 8px; align-items: center; padding: 5px 10px; background: var(--c-totalBg); border-bottom: 1px solid var(--c-line); }
#foodbar[hidden] { display: none; }
#foodbar .ul { font-size: .7rem; opacity: .75; white-space: nowrap; }
#foodbar select { flex: 1; min-width: 0; font: inherit; font-size: .95rem; padding: 4px 6px; border: 1px solid var(--c-keyOpText); border-radius: 7px; background: transparent; color: inherit; }
.foodrow { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.foodrow .fname { flex: 1; min-width: 0; font: inherit; padding: 6px; border: 1px solid var(--c-bar); border-radius: 8px; background: transparent; color: inherit; }
.foodrow .fgram { width: 4.6em; font: inherit; padding: 6px; border: 1px solid var(--c-bar); border-radius: 8px; background: transparent; color: inherit; }
.foodrow .fu { font-size: .8rem; white-space: nowrap; }
.foodrow .fdel { border: 1px solid var(--c-error); color: var(--c-error); background: transparent; border-radius: 8px; padding: 6px 8px; font: inherit; font-size: .8rem; cursor: pointer; }
.tmtoday { border: 1px solid var(--c-bar); background: transparent; color: var(--c-bar); border-radius: 8px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.tmtoday:disabled { opacity: .45; cursor: default; }
#unitbar .modeseg { margin-left: auto; display: flex; gap: 0; }
#unitbar .modeseg button { border-radius: 0; padding: 4px 8px; font-size: .8rem; }
#unitbar .modeseg button:first-child { border-radius: 7px 0 0 7px; }
#unitbar .modeseg button:last-child { border-radius: 0 7px 7px 0; border-left: 0; }

/* 上部バーの下の小さなお知らせ(自動保存) */
#savenote { flex: none; font-size: .62rem; text-align: right; padding: 1px 10px; background: var(--c-bar); color: var(--c-barText); opacity: .85; }

/* お知らせを合計欄のすぐ上に出す(コピー・貼り付けのとき。上の方には出さない) */
#toast.low { top: auto; }

/* 貼り付けの画面 */
.sheet.paste { width: 100%; max-width: 560px; margin: auto; border-radius: 12px; overflow: hidden; max-height: 92%; }
#pasteText { width: 100%; box-sizing: border-box; font: inherit; font-size: 16px; padding: 8px; border: 1px solid var(--c-bar); border-radius: 8px; background: var(--c-bg); color: inherit; resize: vertical; }
#pasteInfo { min-height: 1.4em; font-size: .85rem; color: var(--c-error); }
.btnrow { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.btnrow .wide { margin: 0; padding: 10px 18px; }
.btnrow .tmtoday { padding: 10px 16px; font-size: .95rem; }

/* 設定の開閉式の項目(円・長さ・容量・時間・食材) */
details.cfg { margin-top: 14px; border-bottom: 1px solid var(--c-line); }
details.cfg > summary { cursor: pointer; list-style: none; font-size: 1rem; font-weight: 700; color: var(--c-bar); padding: 6px 0 4px; }
details.cfg > summary::-webkit-details-marker { display: none; }
details.cfg > summary::before { content: "▸"; display: inline-block; width: 1.2em; transition: transform .15s; }
details.cfg[open] > summary::before { transform: rotate(90deg); }
details.cfg > *:last-child { margin-bottom: 12px; }
details.cfg h4 { margin: 12px 0 6px; font-size: .9rem; }
