:root {
  --bg: #0a0a0a;
  --bg-elev: #161616;
  --bg-elev2: #222;
  --fg: #e8e8e8;
  --fg-mute: #888;
  --accent: #d23a5e;
  --accent-hover: #e85476;
  --danger: #c0392b;
  --border: #2a2a2a;
  --interim: #b88;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  height: 100dvh;
}

/* ── トップバー ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.doc-title {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 16px;
  font-weight: 600;
  padding: 6px 8px;
  outline: none;
  border-radius: 4px;
}
.doc-title:focus { background: var(--bg-elev2); }

.topbar-stats {
  font-size: 12px;
  color: var(--fg-mute);
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--bg-elev2); }

/* ── サイドバー ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 12px;
  padding-top: calc(12px + var(--safe-top));
  overflow-y: auto;
}
.sidebar[hidden] { display: none; }

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.sidebar-head h2 { margin: 0; font-size: 16px; }

.doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
}
.doc-list li {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.doc-list li:hover { background: var(--bg-elev2); }
.doc-list li.active { background: var(--accent); color: white; }
.doc-list li .meta {
  font-size: 11px;
  color: var(--fg-mute);
  white-space: nowrap;
}
.doc-list li.active .meta { color: rgba(255,255,255,.85); }

.sidebar-foot {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-foot button { display: block; width: 100%; margin-bottom: 8px; }
.cmd-list { font-size: 12px; color: var(--fg-mute); padding-left: 16px; }
.cmd-list li { margin: 4px 0; }

.custom-cmd-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.custom-cmd-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-elev2);
  border-radius: 4px;
  font-size: 12px;
}
.custom-cmd-item .cmd-text {
  flex: 1;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-cmd-item .cmd-arrow {
  color: var(--fg-mute);
  margin: 0 4px;
}
.custom-cmd-item .cmd-del {
  background: none;
  border: none;
  color: var(--fg-mute);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 14px;
}
.custom-cmd-item .cmd-del:hover { color: var(--danger); }

.custom-cmd-add {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}
.cmd-input {
  background: var(--bg-elev2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
}
.cmd-input:focus { border-color: var(--accent); }
.primary-btn.small { padding: 6px 12px; font-size: 12px; }
.cmd-help {
  font-size: 11px;
  color: var(--fg-mute);
  margin: 8px 0 0;
  line-height: 1.5;
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.primary-btn:active { background: var(--accent-hover); }

.ghost-btn {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:active { background: var(--bg-elev2); }
.ghost-btn.small { padding: 4px 10px; font-size: 12px; }
.ghost-btn.danger { border-color: var(--danger); color: var(--danger); }

/* ── エディタ ── */
.editor-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.mode-bar {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.mode-btn {
  background: var(--bg-elev2);
  color: var(--fg-mute);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
}
.mode-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.mode-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-mute);
}

.editor {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: none;
  outline: none;
  padding: 16px 20px;
  font-size: 16px;
  line-height: 1.9;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  resize: none;
  white-space: pre-wrap;
  word-break: break-all;
}

.interim {
  min-height: 24px;
  padding: 4px 20px 8px;
  font-size: 14px;
  color: var(--interim);
  font-style: italic;
  border-top: 1px dashed var(--border);
  background: var(--bg-elev);
  white-space: pre-wrap;
}

/* ── マイクバー ── */
.micbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}

.micbar-left { display: flex; align-items: center; gap: 8px; }
.micbar-right { display: flex; justify-content: flex-end; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--fg-mute);
}
.status-dot.idle { background: var(--fg-mute); }
.status-dot.listening { background: #2ecc71; box-shadow: 0 0 8px #2ecc71; animation: pulse 1.4s infinite; }
.status-dot.error { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-text { font-size: 12px; color: var(--fg-mute); }

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 32px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(210, 58, 94, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.2s;
}
.mic-btn:active { transform: scale(0.95); }
.mic-btn.recording {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(192, 57, 43, 0.25);
  animation: pulse 1.4s infinite;
}

/* ── トースト ── */
.toast {
  position: fixed;
  bottom: calc(120px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev2);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  z-index: 200;
  max-width: 80vw;
}

/* ── 覗き見防止モード ── */
body.blur-mode .editor,
body.blur-mode .interim {
  filter: blur(6px);
  transition: filter 0.2s;
}
body.blur-mode .editor:focus,
body.blur-mode .editor:active {
  filter: blur(0);
}

/* ── PC幅 ── */
@media (min-width: 900px) {
  #app {
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "topbar topbar"
      "sidebar editor"
      "micbar micbar";
  }
  .topbar { grid-area: topbar; }
  .sidebar {
    position: static;
    grid-area: sidebar;
    width: auto;
  }
  .sidebar[hidden] { display: flex; }
  .editor-area { grid-area: editor; }
  .micbar { grid-area: micbar; }
  #menu-btn { display: none; }
  .editor { font-size: 17px; padding: 24px 40px; max-width: 800px; margin: 0 auto; width: 100%; }
}
