/* カラー剤計算機 — スマホ片手で使える大きめUI */
:root {
  --bg: #f6f4f9;
  --card: #ffffff;
  --ink: #241f2e;
  --muted: #6f6880;
  --line: #e4e0ec;
  --brand: #7c3aed;
  --brand-ink: #ffffff;
  --brand-soft: #f0e9ff;
  --ox: #0d9488;
  --ox-soft: #e2f6f3;
  --warn: #b45309;
  --danger: #d02f4b;
  --badge-ink: #7c3aed;
  --logo: url("logo.png");
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP",
    system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(36, 31, 46, 0.07);
}

/* 端末がダークモード（テーマ未指定のとき） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17141d;
    --card: #221e2b;
    --ink: #f3f0f8;
    --muted: #a9a1b8;
    --line: #362f45;
    --brand: #a78bfa;
    --brand-ink: #1b1524;
    --brand-soft: #2e2540;
    --ox: #5eead4;
    --ox-soft: #1e3a37;
    --warn: #fbbf24;
    --danger: #fb7185;
    --badge-ink: #f3f0f8;
    --logo: url("logo-white.png");
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

/* テーマを明示的にダーク指定されたとき */
:root[data-theme="dark"] {
  --bg: #17141d;
  --card: #221e2b;
  --ink: #f3f0f8;
  --muted: #a9a1b8;
  --line: #362f45;
  --brand: #a78bfa;
  --brand-ink: #1b1524;
  --brand-soft: #2e2540;
  --ox: #5eead4;
  --ox-soft: #1e3a37;
  --warn: #fbbf24;
  --danger: #fb7185;
  --badge-ink: #f3f0f8;
  --logo: url("logo-white.png");
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

/* 広東語（繁体字）表示のときは中文フォントを優先する */
:root[lang^="yue"],
:root[lang^="zh"] {
  --font: "PingFang HK", "Noto Sans HK", "Noto Sans TC", "Hiragino Sans CNS",
    "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

/* display を持つクラス（.sticky-bar / .gate-field など）に hidden 属性を効かせる */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  padding: 0 0 96px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
}

.header {
  padding: 20px 16px 14px;
  background: var(--brand);
  color: var(--brand-ink);
  text-align: center;
}

/* ブランド表記。ロゴ画像は加工せずそのまま使い、
   紫地やダークモードでも見えるよう白の台紙に載せる */
.brand {
  display: flex;
  justify-content: center;
  margin: 0 0 8px;
}

.brand-logo {
  display: block;
  width: 168px;
  aspect-ratio: 700 / 135;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

/* 紫のヘッダーは常に白版。アプリの白文字と揃う */
.header .brand-logo {
  background-image: url("logo-white.png");
}

/* フッターは背景色に合わせて黒版/白版を切り替える */
.footer .brand-logo {
  width: 132px;
  background-image: var(--logo);
}

.header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.header p {
  margin: 4px 0 0;
  font-size: 13px;
  opacity: 0.9;
}

.lang {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

.lang-btn {
  min-height: 34px;
  padding: 4px 16px;
  border: 2px solid var(--brand-ink);
  border-radius: 999px;
  background: transparent;
  color: var(--brand-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  opacity: 0.75;
  cursor: pointer;
}

.lang-btn[aria-pressed="true"] {
  background: var(--brand-ink);
  color: var(--brand);
  opacity: 1;
}

.lang-btn:focus-visible {
  outline: 3px solid var(--brand-ink);
  outline-offset: 2px;
}

.main {
  max-width: 620px;
  margin: 0 auto;
  padding: 14px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* タブ */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  min-height: 60px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.tab strong {
  font-size: 15px;
}

.tab small {
  font-size: 11px;
}

.tab[aria-selected="true"] {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--ink);
}

/* カード */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 17px;
}

.step-no {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 14px;
  font-weight: 700;
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

/* チップ（プリセットボタン） */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  flex: 1 1 auto;
  min-width: 72px;
  min-height: 52px;
  padding: 6px 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--brand-ink);
}

/* 入力まわり */
.custom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.custom-row label {
  color: var(--muted);
  font-size: 13px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.round {
  width: 46px;
  height: 46px;
  flex: none;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.round:active {
  background: var(--brand-soft);
}

.num-input {
  width: 88px;
  height: 46px;
  padding: 0 8px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

.num-input.big {
  width: 104px;
  font-size: 24px;
}

.num-input:focus,
.text-input:focus,
.chip:focus-visible,
.round:focus-visible,
.tab:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

.unit {
  color: var(--muted);
  font-size: 15px;
}

.ratio-view {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  text-align: center;
  font-size: 15px;
  color: var(--muted);
}

.ratio-view b {
  color: var(--ink);
  font-size: 20px;
}

/* 1剤の行 */
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.item:first-child {
  padding-top: 0;
}

.text-input {
  width: 100%;
  height: 46px;
  padding: 0 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}

.item-controls {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-controls .label {
  color: var(--muted);
  font-size: 13px;
  flex: none;
}

.item-badge {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--badge-ink);
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
}

.del-btn {
  width: 42px;
  height: 42px;
  flex: none;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
}

.add-btn {
  width: 100%;
  min-height: 50px;
  margin-top: 12px;
  border: 2px dashed var(--brand);
  border-radius: 12px;
  background: transparent;
  color: var(--brand);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* 結果 */
.result {
  border: 2px solid var(--brand);
}

.result-title {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 700;
}

.rrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.rrow .rname {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.rrow .rname small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.rrow .rgram {
  flex: none;
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.rrow .rgram span {
  font-size: 15px;
  font-weight: 700;
  margin-left: 2px;
}

.rrow.ox {
  background: var(--ox-soft);
  margin: 6px -14px 0;
  padding: 12px 14px;
  border-bottom: none;
  border-radius: 12px;
  color: var(--ox);
}

.rrow.sum {
  border-bottom: none;
  padding-top: 12px;
  color: var(--muted);
}

.rrow.sum .rgram {
  font-size: 24px;
  color: var(--ink);
}

.subtotal {
  margin: 8px 0 0;
  text-align: right;
  color: var(--muted);
  font-size: 13px;
}

.notice {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--warn);
  font-size: 13px;
}

.error {
  margin: 0;
  padding: 14px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--danger);
  font-weight: 700;
  text-align: center;
}

.steps-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 13px;
  color: var(--muted);
}

.steps-toggle .chip {
  min-width: 0;
  min-height: 38px;
  padding: 2px 12px;
  font-size: 14px;
}

/* 操作ボタン */
.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.action {
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.action:active {
  background: var(--brand-soft);
}

/* 保存レシピ */
.recipe {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}

.recipe-load {
  flex: 1;
  min-height: 44px;
  padding: 6px 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.recipe-load small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

/* つかいかた */
.how summary {
  cursor: pointer;
  font-weight: 700;
}

.how ol {
  padding-left: 1.2em;
}

.how-math {
  white-space: pre-line;
  padding: 10px;
  border-radius: 10px;
  background: var(--brand-soft);
  font-size: 14px;
  line-height: 1.9;
}

.how-note {
  color: var(--muted);
  font-size: 13px;
}

/* フッター */
.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 8px 8px;
  color: var(--muted);
  font-size: 12px;
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
}

.footer-lead {
  margin: 0;
  text-align: center;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.footer-link:active {
  background: var(--brand-soft);
}

.footer-link:focus-visible,
.brand-logo:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

a.brand-logo {
  cursor: pointer;
}

/* 下部固定バー */
.sticky-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 2px solid var(--brand);
  box-shadow: 0 -4px 14px rgba(36, 31, 46, 0.12);
}

.sticky-bar span {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}

.sticky-bar small {
  color: var(--muted);
  font-size: 11px;
}

.sticky-bar b {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.sticky-total b {
  color: var(--brand);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 10;
}

/* ===== はじめて使う人への登録画面 ===== */
body.gate-open {
  overflow: hidden;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: rgba(22, 16, 34, 0.72);
  backdrop-filter: blur(3px);
}

.gate-card {
  width: 100%;
  max-width: 460px;
  margin: auto;
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.gate-lang {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.gate-lang-btn {
  min-height: 34px;
  padding: 4px 16px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.gate-lang-btn[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--brand-ink);
}

.gate-title {
  margin: 0;
  font-size: 20px;
  text-wrap: balance;
}

.gate-lead {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.gate-q {
  margin: 6px 0 0;
  font-size: 15px;
}

.gate-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.gate-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 66px;
  padding: 10px 8px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.gate-option strong {
  font-size: 15px;
}

.gate-option small {
  font-size: 11px;
}

.gate-option[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--ink);
}

.gate-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gate-label {
  font-size: 14px;
  font-weight: 700;
}

.gate-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.gate-ig {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gate-at {
  font-size: 20px;
  font-weight: 800;
  color: var(--muted);
}

.gate-purpose {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.gate-consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}

.gate-consent input {
  width: 24px;
  height: 24px;
  flex: none;
  margin: 0;
  accent-color: var(--brand);
}

.gate-error {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
}

.gate-submit {
  min-height: 54px;
  border: none;
  border-radius: 12px;
  background: var(--brand);
  color: var(--brand-ink);
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}

.gate-submit:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* 登録完了画面 */
.gate-done {
  text-align: center;
  align-items: center;
}

.gate-done .gate-lead {
  text-align: center;
}

.gate-done .gate-submit {
  width: 100%;
}

.gate-done-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 4px auto 0;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 30px;
  font-weight: 800;
}

.gate-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.gate-whatsapp {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 54px;
  border-radius: 12px;
  background: #25d366;
  color: #04310f;
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
}

.gate-whatsapp:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.gate-contact {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.gate-option:focus-visible,
.gate-lang-btn:focus-visible,
.gate-submit:focus-visible,
.gate-consent input:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

/* 登録情報の確認・削除 */
.manage {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.manage-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.manage-who {
  margin: 4px 0 8px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.manage-del {
  min-height: 40px;
  padding: 4px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--danger);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
