:root {
  --brand: #6d5efc;
  --brand-dark: #5848e0;
  --brand-light: #e9e6ff;
  --brand-ink: #5848e0;
  --bg: #f3f2fb;
  --card: #ffffff;
  --soft: #f7f6fd;
  --text: #1a1730;
  --muted: #6b6880;
  --border: #e6e3f2;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(26, 23, 48, .08), 0 1px 2px rgba(26, 23, 48, .04);
  --shadow-lg: 0 12px 30px rgba(26, 23, 48, .14);
  --radius: 14px;
}

html[data-theme="dark"] {
  --brand: #8b7cff;
  --brand-dark: #6d5efc;
  --brand-light: #2a2350;
  --brand-ink: #b3a8ff;
  --bg: #0e0c1a;
  --card: #181430;
  --soft: #211b3d;
  --text: #ece9fb;
  --muted: #9d99b8;
  --border: #322a55;
  --danger: #f87171;
  --ok: #4ade80;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

/* ===== ヘッダー ===== */
.app-header {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; line-height: 1; }
.brand-text h1 { font-size: 20px; letter-spacing: .01em; }
.subtitle { font-size: 12px; opacity: .9; }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  background: rgba(255,255,255,.16);
  border: none; color: #fff; cursor: pointer;
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px;
  transition: background .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.28); }

/* ===== レイアウト ===== */
.container { max-width: 1080px; margin: 0 auto; padding: 22px 16px 40px; }

.mode-tabs {
  display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap;
}
.mode-tab {
  flex: 1 1 auto; min-width: 130px;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 10px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all .15s ease;
}
.mode-tab:hover { border-color: var(--brand); color: var(--text); }
.mode-tab.active {
  background: var(--brand); color: #fff; border-color: var(--brand);
  box-shadow: var(--shadow);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: background .2s ease;
}
.panel-title { font-size: 16px; }
.panel-note { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.result-panel { position: sticky; top: 16px; }

/* ===== フォーム ===== */
.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text);
}
.field-label em {
  font-style: normal; font-size: 11px; color: var(--brand-ink);
  background: var(--brand-light); padding: 1px 7px; border-radius: 999px; margin-left: 6px;
}
input[type="text"], input[type="password"], textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== ボタン ===== */
.btn {
  border: none; border-radius: 10px; padding: 12px 18px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform .05s ease, filter .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--brand); }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ===== 設定 ===== */
.settings { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.settings summary {
  cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted);
  list-style: none; user-select: none;
}
.settings summary::-webkit-details-marker { display: none; }
.settings summary:hover { color: var(--text); }
.settings-body { padding-top: 12px; }
.settings-note {
  font-size: 12px; color: var(--muted); background: var(--soft);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px;
}
.api-fields.hidden { display: none; }

/* ===== 結果 ===== */
.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
}
.badge-demo { background: var(--brand-light); color: var(--brand-ink); }
.badge-live { background: #dcfce7; color: #15803d; }
html[data-theme="dark"] .badge-live { background: #14331f; color: #4ade80; }

.results { min-height: 120px; }
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty-icon { font-size: 38px; margin-bottom: 8px; opacity: .7; }

.result-card {
  background: var(--soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 14px 12px; margin-bottom: 12px;
  animation: pop .25s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.result-card .rc-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.rc-num { font-size: 12px; font-weight: 700; color: var(--brand-ink); }
.rc-text { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }
.rc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.rc-count { font-size: 11.5px; color: var(--muted); }
.copy-btn {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 5px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: all .15s ease;
}
.copy-btn:hover { border-color: var(--brand); color: var(--brand-ink); }
.copy-btn.copied { background: var(--ok); color: #fff; border-color: var(--ok); }

.loading { text-align: center; color: var(--muted); padding: 24px; }
.spinner {
  width: 30px; height: 30px; border: 3px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; margin: 0 auto 10px; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  border-radius: 10px; padding: 12px; font-size: 13px;
}
html[data-theme="dark"] .error-box { background: #2a1414; border-color: #5a2222; color: #fca5a5; }

/* ===== 履歴 ===== */
.history-panel { margin-top: 18px; }
.history-item {
  border-bottom: 1px solid var(--border); padding: 10px 0; font-size: 13.5px;
}
.history-item:last-child { border-bottom: none; }
.history-item .hi-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.history-item .hi-text { white-space: pre-wrap; word-break: break-word; }

/* ===== トースト ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--card); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== フッター ===== */
.app-footer {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 20px 16px 40px; max-width: 760px; margin: 0 auto;
}

/* ===== レスポンシブ ===== */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .result-panel { position: static; }
  .brand-text h1 { font-size: 18px; }
}
