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

:root {
  --bg: #ffffff;
  --bg2: #f5f5f3;
  --bg3: #eeede8;
  --text: #1a1a18;
  --text2: #6b6b67;
  --border: rgba(0,0,0,0.12);
  --border2: rgba(0,0,0,0.22);
  --accent: #E91E63;
  --accent-hover: #D81B60;
  --accent-pressed: #C2185B;
  --accent-bg: #FCE4EC;
  --accent-text: #C2185B;
  --danger: #a32d2d;
  --danger-bg: #fcebeb;
  --radius: 10px;
  --radius-lg: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a;
    --bg2: #2a2a27;
    --bg3: #333330;
    --text: #f0efe8;
    --text2: #9b9b95;
    --border: rgba(255,255,255,0.1);
    --border2: rgba(255,255,255,0.2);
    --accent: #F06292;
    --accent-hover: #E91E63;
    --accent-pressed: #D81B60;
    --accent-bg: #4A0020;
    --accent-text: #F48FB1;
    --danger: #f09595;
    --danger-bg: #501313;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

#app { position: relative; min-height: 100vh; }

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* Settings */
#screen-settings {
  display: flex; justify-content: center;
  padding: 2rem 1rem;
}
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  max-width: 400px; width: 100%;
  display: flex; flex-direction: column; gap: 1rem;
  text-align: center;
}
.card h1 { font-size: 20px; font-weight: 500; }
.card .muted { color: var(--text2); font-size: 14px; }
.card .small { font-size: 12px; }
.card a { color: var(--accent); }
.card input[type="password"],
.card input[type="url"] {
  width: 100%; padding: 9px 11px;
  font-size: 14px; border-radius: var(--radius);
  border: 0.5px solid var(--border);
  background: var(--bg2); color: var(--text);
  font-family: inherit;
}
.card input:focus { outline: none; border-color: var(--border2); }
.settings-section {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  text-align: left;
}
.settings-section-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text2); margin-bottom: 4px;
}
.danger-title { color: var(--danger); }
.notion-tone-field { display: flex; flex-direction: column; gap: 4px; }

/* Avatar */
.avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 500;
  margin: 0 auto;
}
.avatar.small { width: 36px; height: 36px; font-size: 14px; margin: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 0.5px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg);
  z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-name { font-weight: 500; font-size: 15px; }
.header-sub { font-size: 12px; color: var(--text2); }
.header-right { display: flex; gap: 6px; }

/* Main */
main { padding: 1.25rem; max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; padding-bottom: 3rem; }

/* Sections */
.section { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--text2); font-weight: 500; letter-spacing: 0.02em; }

/* Textarea */
.textarea-wrap { display: flex; gap: 8px; align-items: flex-start; }
textarea {
  flex: 1; resize: vertical;
  padding: 10px 12px;
  font-size: 14px; line-height: 1.6;
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  min-height: 110px;
}
textarea:focus { outline: none; border-color: var(--border2); }
.input-actions { display: flex; flex-direction: column; gap: 6px; padding-top: 2px; }

/* Mic + clear buttons */
.mic-btn, .clear-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 0.5px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.mic-btn:hover, .clear-btn:hover { background: var(--bg3); }
.mic-btn.active { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.mic-status { font-size: 12px; color: var(--danger); }

/* Pills */
.pill-group { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  padding: 5px 14px; border-radius: 20px; font-size: 13px;
  border: 0.5px solid var(--border);
  background: transparent; color: var(--text);
  cursor: pointer; transition: all 0.1s;
}
.pill.active {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent-text);
  font-weight: 500;
}

/* Buttons */
.btn-primary {
  width: 100%; padding: 11px;
  background: var(--accent-bg);
  color: var(--accent-text);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-pressed); color: #fff; border-color: var(--accent-pressed); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger {
  width: 100%; padding: 10px;
  background: transparent;
  color: var(--danger);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px; cursor: pointer;
}
.btn-secondary {
  width: 100%; padding: 9px;
  background: transparent; color: var(--text);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
}
.btn-secondary:hover { background: var(--bg2); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  background: transparent; border: none;
  color: var(--text2); cursor: pointer;
  font-size: 16px; padding: 6px;
  border-radius: var(--radius);
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg2); }
.update-wrap { position: relative; display: flex; }
.update-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.75); }
}
.copy-btn {
  padding: 4px 10px; font-size: 12px;
  border: 0.5px solid var(--border);
  border-radius: 6px; background: transparent;
  color: var(--text2); cursor: pointer; white-space: nowrap;
}
.result-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.save-notion-btn {
  padding: 4px 10px; font-size: 12px;
  border: 0.5px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-bg); color: var(--accent-text);
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s;
}
.save-notion-btn:hover { background: var(--accent-hover); color: #fff; border-color: var(--accent-hover); }
.save-notion-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.speak-btn {
  width: 30px; height: 30px; border-radius: 50%;
  border: 0.5px solid var(--border);
  background: var(--bg2);
  cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.speak-btn:hover { background: var(--bg3); }
.speak-btn.speaking { background: var(--accent-bg); border-color: var(--accent); }

/* Error */
.error { font-size: 13px; color: var(--danger); }

/* Result */
.result-box {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: 4px;
}
.result-meta { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.subject-wrap { display: flex; flex-direction: column; gap: 4px; }
.subject-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg2); border-radius: var(--radius);
  padding: 8px 10px;
}
.subject-text { font-size: 14px; font-weight: 500; flex: 1; }
.result-body { font-size: 14px; line-height: 1.7; color: var(--text); white-space: pre-wrap; }

/* History panel */
.side-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(320px, 90vw);
  background: var(--bg);
  border-left: 0.5px solid var(--border);
  z-index: 100;
  display: flex; flex-direction: column;
  padding: 0;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.side-panel.open { transform: translateX(0); }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 0.5px solid var(--border);
  font-weight: 500;
}
.history-list {
  flex: 1; overflow-y: auto;
  padding: 0.75rem;
  display: flex; flex-direction: column; gap: 8px;
}
.history-item {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer; transition: background 0.1s;
}
.history-item:hover { background: var(--bg2); }
.history-item-meta { font-size: 11px; color: var(--text2); margin-bottom: 4px; }
.history-item-preview { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-empty { font-size: 13px; color: var(--text2); text-align: center; padding: 2rem; }

/* Overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}

/* Padding for safe area (iPhone notch etc) */
@supports (padding-top: env(safe-area-inset-top)) {
  header { padding-top: calc(1rem + env(safe-area-inset-top)); }
}
