/* =====================================================================
 * style.css  ―  見た目
 *
 *  スマートフォン縦画面を最優先。色やボタンの大きさは先頭の変数で調整できます。
 * ===================================================================== */

:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --display-bg: #1f2933;
  --display-fg: #ffffff;
  --display-muted: #9aa5b1;
  --accent: #1e5fa8;
  --accent-dark: #174a84;
  --danger: #d64545;
  --success: #2e8b57;
  --key-bg: #ffffff;
  --key-fg: #1f2933;
  --key-func-bg: #d9dee5;
  --key-op-bg: #ffb84d;
  --key-op-fg: #3b2500;
  --key-mem-bg: #cfd8e3;
  --key-equals-bg: #1e5fa8;
  --key-equals-fg: #ffffff;
  --border: #d3d9e0;
  --text: #1f2933;
  --text-muted: #5f6b7a;
  --radius: 12px;
  --key-min-h: 52px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-num: "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button:active { filter: brightness(0.9); }

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  overflow: hidden;
}

/* ---------- 上部バー ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  background: var(--accent);
  color: #fff;
}
.app-title { font-weight: 700; font-size: 17px; white-space: nowrap; }
.stats { display: flex; gap: 6px; flex: 1; justify-content: flex-end; min-width: 0; }
.stat {
  display: flex; align-items: baseline; gap: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 4px 8px;
  color: #fff;
  min-width: 0;
}
.stat-label { font-size: 11px; opacity: 0.85; }
.stat-value { font-family: var(--font-num); font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.stat-sub { font-size: 11px; opacity: 0.8; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  background: rgba(255,255,255,0.18);
}

/* ---------- バナー ---------- */
.banner {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 13px; line-height: 1.4;
}
.banner-warn { background: #fff3cd; color: #6b4b00; }
.banner-info { background: #dbe8fb; color: #163d6b; }
.banner-btn { background: var(--accent); color: #fff; border-radius: 6px; padding: 6px 12px; font-weight: 600; white-space: nowrap; }
.banner-close { font-size: 20px; padding: 0 6px; }
.banner > span { flex: 1; }

/* ---------- メイン ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
}

/* ---------- 表示部 ---------- */
.display {
  background: var(--display-bg);
  color: var(--display-fg);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.label { font-size: 11px; color: var(--display-muted); margin-right: 6px; flex-shrink: 0; }
.recognized {
  display: flex; align-items: baseline;
  font-size: 14px; min-height: 20px;
  overflow: hidden; white-space: nowrap;
}
.recognized-text { overflow: hidden; text-overflow: ellipsis; }
.interim-text { color: var(--display-muted); margin-left: 6px; overflow: hidden; text-overflow: ellipsis; }

.expression-row { display: flex; align-items: center; gap: 6px; }
.expression {
  flex: 1;
  min-width: 0;
  font-family: var(--font-num);
  font-size: 22px;
  background: transparent;
  color: var(--display-fg);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px 6px;
  text-align: right;
  outline: none;
}
.expression::placeholder { color: var(--display-muted); }
.expression:not([readonly]) { background: #ffffff; color: #000; border-color: var(--accent); }
.edit-btn { background: rgba(255,255,255,0.12); font-size: 16px; }
.edit-btn.active { background: var(--accent); }

.result-row { display: flex; align-items: baseline; }
.result {
  flex: 1;
  font-family: var(--font-num);
  font-size: 38px;
  font-weight: 600;
  text-align: right;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result.dim { color: var(--display-muted); font-weight: 400; }
.message {
  font-size: 13px; min-height: 18px; line-height: 1.35;
  color: var(--display-muted);
}
.message.error { color: #ff8a80; }
.message.notice { color: #8fd3ff; }

/* ---------- マイク ---------- */
.voice {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.mic {
  width: 72px; height: 72px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(30,95,168,0.35);
  position: relative;
  transition: background 0.2s;
}
.mic:disabled { background: #a5adb8; box-shadow: none; cursor: not-allowed; }
.mic.listening { background: var(--danger); box-shadow: 0 3px 10px rgba(214,69,69,0.4); }
.mic.listening::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 3px solid var(--danger); opacity: 0.6;
  animation: pulse 1.2s ease-out infinite;
}
.mic.processing { background: #e08a00; }
.mic.starting { background: #7a8797; }
@keyframes pulse {
  0%   { transform: scale(0.9); opacity: 0.7; }
  100% { transform: scale(1.35); opacity: 0; }
}
.voice-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.voice-status { font-size: 15px; font-weight: 600; line-height: 1.3; }
.voice-status.listening { color: var(--danger); }
.voice-status.processing { color: #b36b00; }
.voice-status.error { color: var(--danger); font-weight: 500; font-size: 13px; }
.voice-options { display: flex; gap: 12px; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-muted); }
.toggle input { width: 16px; height: 16px; margin: 0; }

/* ---------- テンキー ---------- */
.keypad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(var(--key-min-h), 1fr);
  gap: 6px;
  min-height: 0;
}
.key {
  background: var(--key-bg);
  color: var(--key-fg);
  border-radius: var(--radius);
  font-size: 24px;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  display: flex; align-items: center; justify-content: center;
}
.key:active { background: #e3e8ee; }
.key-func { background: var(--key-func-bg); font-size: 20px; }
.key-mem { background: var(--key-mem-bg); font-size: 17px; font-weight: 600; }
.key-op { background: var(--key-op-bg); color: var(--key-op-fg); font-size: 26px; }
.key-equals { background: var(--key-equals-bg); color: var(--key-equals-fg); font-size: 28px; }
.key-zero { grid-column: span 2; }

/* ---------- 下部ツールバー ---------- */
.toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.tool {
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  white-space: nowrap;
}
.tool-primary { background: var(--success); color: #fff; }

/* ---------- パネル ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 20;
}
.panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto;
  max-height: 80vh; max-height: 80dvh;
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { flex: 1; margin: 0; font-size: 16px; }
.panel-head .icon-btn { background: var(--key-func-bg); color: var(--text); }
.text-btn { padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; background: var(--key-func-bg); }
.text-btn.danger { color: var(--danger); }
.list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
.list li {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-family: var(--font-num);
}
.list .no { color: var(--text-muted); font-size: 13px; min-width: 2em; }
.list .expr { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--text-muted); }
.list .val { font-weight: 600; font-size: 16px; white-space: nowrap; }
.list .small-btn { padding: 6px 10px; border-radius: 8px; background: var(--key-func-bg); font-size: 13px; }
.list .small-btn.danger { color: var(--danger); }
.list .empty { color: var(--text-muted); justify-content: center; border: none; }
.total-big { font-family: var(--font-num); font-size: 32px; font-weight: 700; text-align: right; padding: 8px 16px; }

/* ---------- ヘルプ ---------- */
.help { overflow-y: auto; padding: 10px 14px 20px; font-size: 14px; line-height: 1.5; }
.help h3 { font-size: 14px; margin: 14px 0 6px; color: var(--accent); }
.help table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help td { padding: 5px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.help td:first-child { white-space: nowrap; font-weight: 600; width: 34%; }
.help .words { color: var(--text-muted); }
.help .ver { color: var(--text-muted); font-size: 12px; margin-top: 16px; }
.help .text-btn { margin-top: 8px; }

/* ---------- 横画面（PC / スマホ横向き） ---------- */
@media (orientation: landscape) and (min-width: 640px) {
  .app { max-width: 960px; }
  .main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "display keypad"
      "voice   keypad"
      "toolbar toolbar";
  }
  .display { grid-area: display; }
  .voice { grid-area: voice; align-self: start; }
  .keypad { grid-area: keypad; }
  .toolbar { grid-area: toolbar; }
  .result { font-size: 44px; }
}

/* 画面が低いとき（スマホ横向きなど）はテンキーを詰める */
@media (max-height: 560px) {
  :root { --key-min-h: 38px; }
  .key { font-size: 18px; }
  .result { font-size: 28px; }
  .mic { width: 56px; height: 56px; }
}
