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

:root {
  --md-primary: #6750a4;
  --md-on-primary: #ffffff;
  --md-tonal: #e8def8;
  --md-on-tonal: #4a4458;
  --md-bg: #fef7ff;
  --md-surface: #ffffff;
  --md-on-surface: #1d1b20;
  --md-muted: #79747e;
  --md-outline: #cac4d0;
  --md-shadow: 0 1px 3px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.08);
  --md-shadow-2: 0 4px 8px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.1);
}
:root[data-theme="dark"] {
  --md-primary: #d0bcff;
  --md-on-primary: #381e72;
  --md-tonal: #4a4458;
  --md-on-tonal: #e8def8;
  --md-bg: #141218;
  --md-surface: #1d1b20;
  --md-on-surface: #e6e0e9;
  --md-muted: #938f99;
  --md-outline: #49454f;
  --md-shadow: 0 1px 3px rgba(0,0,0,.5);
  --md-shadow-2: 0 4px 8px rgba(0,0,0,.5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --md-primary: #d0bcff;
    --md-on-primary: #381e72;
    --md-tonal: #4a4458;
    --md-on-tonal: #e8def8;
    --md-bg: #141218;
    --md-surface: #1d1b20;
    --md-on-surface: #e6e0e9;
    --md-muted: #938f99;
    --md-outline: #49454f;
    --md-shadow: 0 1px 3px rgba(0,0,0,.5);
    --md-shadow-2: 0 4px 8px rgba(0,0,0,.5);
  }
}

[hidden] { display: none !important; }

html, body { height: 100%; }
@supports (height: 100dvh) {
  /* dvh tracks the real visible height on mobile (URL bar, keyboard) */
  html, body { height: 100dvh; }
}
body {
  background: var(--md-bg);
  color: var(--md-on-surface);
  font-family: Roboto, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 20px;
  padding: 0.55rem 1.4rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: box-shadow .15s, background .15s, filter .15s;
}
.btn.filled { background: var(--md-primary); color: var(--md-on-primary); }
.btn.filled:hover { box-shadow: var(--md-shadow); filter: brightness(1.08); }
.btn.tonal { background: var(--md-tonal); color: var(--md-on-tonal); }
.btn.tonal:hover { box-shadow: var(--md-shadow); }
.btn.text { background: transparent; color: var(--md-primary); }
.btn.text:hover { background: color-mix(in srgb, var(--md-primary) 10%, transparent); }
.theme-toggle {
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  color: var(--md-on-surface);
}
.theme-toggle:hover { background: color-mix(in srgb, var(--md-primary) 12%, transparent); }
#home .theme-toggle { position: fixed; top: 0.75rem; right: 0.75rem; }

/* Home */
#home {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}
.home-content { max-width: 520px; }
.home-content h1 { font-size: 1.8rem; font-weight: 500; margin-bottom: 0.75rem; }
.home-content p { color: var(--md-muted); line-height: 1.6; margin-bottom: 1.25rem; }
.home-content ol { margin: 0 0 2rem 1.25rem; line-height: 1.9; }
.home-content code {
  background: var(--md-tonal);
  color: var(--md-on-tonal);
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  font-size: 0.9em;
}
.home-content a { color: var(--md-primary); }

/* Editor */
#editor { height: 100%; display: flex; flex-direction: column; }
.appbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  background: var(--md-surface);
  box-shadow: var(--md-shadow);
  font-size: 0.9rem;
  z-index: 1;
}
.brand { color: var(--md-muted); text-decoration: none; font-weight: 500; }
.brand:hover { color: var(--md-primary); }
.channel-name { font-weight: 500; color: var(--md-primary); }
.spacer { flex: 1; }
.viewers { color: var(--md-muted); font-size: 0.85rem; }

.sheet { flex: 1; display: flex; padding: 1rem; min-height: 0; }
#note {
  flex: 1;
  width: 100%;
  padding: 1.25rem 1.4rem;
  border: 1px solid var(--md-outline);
  border-radius: 16px;
  outline: none;
  resize: none;
  background: var(--md-surface);
  color: var(--md-on-surface);
  box-shadow: var(--md-shadow);
  font-family: "Roboto Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.65;
  transition: border-color .15s;
}
#note:focus { border-color: var(--md-primary); }

.statusbar {
  padding: 0.4rem 1.4rem 0.7rem;
  color: var(--md-muted);
  font-size: 0.8rem;
}

/* Snackbar */
.snackbar {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--md-on-surface);
  color: var(--md-surface);
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  box-shadow: var(--md-shadow-2);
  font-size: 0.875rem;
  animation: snackbar-in .2s ease-out;
}
@keyframes snackbar-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Small screens */
@media (max-width: 600px) {
  .appbar { flex-wrap: wrap; padding: 0.5rem 0.75rem; gap: 0.5rem; }
  .sheet { padding: 0.6rem; }
  #note { padding: 0.9rem 1rem; font-size: 16px; /* <16px triggers iOS zoom on focus */ }
  .statusbar { padding: 0.3rem 1rem 0.6rem; }
  .home-content h1 { font-size: 1.5rem; }
}
