:root {
  color-scheme: light;
  --paper: #f4f2ec;
  --surface: #fffefb;
  --ink: #181a1e;
  --muted: #6d706f;
  --line: #d9d7d0;
  --accent: #2457e6;
  --accent-dark: #1743bc;
  --danger: #a2392e;
  --radius: 14px;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  overflow-y: visible;
  overscroll-behavior-y: auto;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }

button, a, input, textarea {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  padding: 0 18px;
  color: white;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, opacity 140ms ease;
}

button:active { transform: scale(.98); }
button:disabled { cursor: wait; opacity: .55; }

button:focus-visible {
  outline: 3px solid rgba(36, 87, 230, .3);
  outline-offset: 2px;
}

button.secondary {
  border: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
}

@media (hover: hover) {
  button:hover { background: var(--accent-dark); }
  button.secondary:hover { background: rgba(24, 26, 30, .05); }
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  color: var(--ink);
  background: var(--surface);
  font-size: 16px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input { min-height: 50px; padding: 0 14px; }
textarea { min-height: 132px; padding: 14px; line-height: 1.5; resize: vertical; }

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 87, 230, .12);
}

label {
  display: block;
  margin-bottom: 7px;
  font-size: .84rem;
  font-weight: 750;
}

.view { min-height: 100vh; min-height: 100svh; min-height: 100dvh; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

.login-view {
  display: grid;
  align-items: center;
  padding:
    max(28px, env(safe-area-inset-top))
    max(22px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom))
    max(22px, env(safe-area-inset-left));
  animation: enter 380ms ease both;
}

.login-shell { width: min(100%, 420px); margin: 0 auto; }

.brand {
  margin: 0 0 48px;
  font-size: clamp(2.8rem, 13vw, 5.6rem);
  font-weight: 900;
  letter-spacing: -.08em;
  line-height: .8;
}

.brand span { color: var(--accent); }

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.65rem, 6vw, 2.2rem);
  letter-spacing: -.04em;
}

.lead { margin-bottom: 28px; color: var(--muted); line-height: 1.5; }
.field + .field { margin-top: 16px; }
.login-form button { width: 100%; margin-top: 22px; }

.message {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: .88rem;
}

.app-view { overflow: visible; animation: enter 300ms ease both; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(68px + env(safe-area-inset-top));
  padding:
    max(10px, env(safe-area-inset-top))
    max(20px, calc((100vw - 760px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(244, 242, 236, .94);
  backdrop-filter: blur(12px);
}

.wordmark { font-size: 1.25rem; font-weight: 900; letter-spacing: -.05em; }
.wordmark span { color: var(--accent); }

.user-actions { display: flex; align-items: center; gap: 10px; }
.user-actions form { margin: 0; }
.user-name { max-width: 220px; overflow: hidden; color: var(--muted); font-size: .86rem; text-overflow: ellipsis; white-space: nowrap; }
.logout { min-height: 40px; padding-inline: 13px; }

main {
  width: min(100%, 800px);
  margin: 0 auto;
  padding:
    42px
    max(20px, env(safe-area-inset-right))
    max(72px, calc(44px + env(safe-area-inset-bottom)))
    max(20px, env(safe-area-inset-left));
}

.composer { padding-bottom: 38px; border-bottom: 1px solid var(--line); }
.composer h1 { margin-bottom: 18px; }
.composer-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }

.notes-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding: 38px 0 10px;
}

.notes-header h2 { margin: 0; font-size: 1.15rem; letter-spacing: -.02em; }
.count { color: var(--muted); font-size: .86rem; }
.notes-list { list-style: none; margin: 0; padding: 0; }

.note-item {
  border-bottom: 1px solid var(--line);
  animation: note-in 260ms ease both;
}

.note-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  width: 100%;
  min-height: 70px;
  padding: 18px 2px;
  color: var(--ink);
  background: transparent;
  text-decoration: none;
  text-align: left;
  transition: color 160ms ease, padding 160ms ease;
}

.note-link:focus-visible {
  outline: 3px solid rgba(36, 87, 230, .3);
  outline-offset: 2px;
}

@media (hover: hover) {
  .note-link:hover { padding-left: 8px; color: var(--accent); }
  .note-link:hover .note-arrow { transform: translateX(4px); }
}

.note-title {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 760;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-arrow {
  color: var(--muted);
  font-size: 1.05rem;
  transition: transform 180ms ease;
}

.delete-form { margin: 0; }
.delete-button { min-height: 40px; padding-inline: 14px; color: var(--danger); }

@media (hover: hover) {
  .delete-button:hover { color: white; background: var(--danger); }
}

.wordmark-link { color: var(--ink); text-decoration: none; }

.note-page {
  width: min(100%, 1040px);
  padding-top: 34px;
}

.back-link {
  display: inline-flex;
  margin-bottom: 38px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 700;
  text-decoration: none;
  transition: color 140ms ease, transform 140ms ease;
}

.back-link:focus-visible {
  outline: 3px solid rgba(36, 87, 230, .3);
  outline-offset: 4px;
}

@media (hover: hover) {
  .back-link:hover { color: var(--accent); transform: translateX(-3px); }
}

.note-reader { animation: note-in 260ms ease both; }

.note-page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: .75rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.note-page-header h1 { margin: 0; }
.note-copy-button { min-height: 40px; }

.note-page-content {
  min-height: 240px;
  margin: 0;
  padding: 28px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .93rem;
  line-height: 1.7;
  white-space: pre-wrap;
}

.note-page-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 18px;
}

.empty {
  padding: 44px 0;
  color: var(--muted);
  text-align: center;
}

@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes note-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 560px) {
  button { min-height: 52px; }
  .topbar {
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }
  .user-name { display: none; }
  .logout { min-height: 44px; }
  main {
    width: 100%;
    padding-top: 28px;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }
  textarea { min-height: 148px; }
  .composer { padding-bottom: 28px; }
  .composer-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); }
  .notes-header { padding-top: 30px; }
  .note-title {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .note-page { padding-top: 24px; }
  .back-link { margin-bottom: 28px; }
  .note-page-content { min-height: 180px; padding: 22px 0; }
  .note-page-header { align-items: center; }
  .note-copy-button { min-height: 48px; }
  .note-page-actions { display: block; }
  .note-page-actions .delete-form { width: 100%; }
  .note-page-actions button { width: 100%; }
}

@media (max-width: 360px) {
  .wordmark { font-size: 1.1rem; }
  .composer-actions { grid-template-columns: 1fr; }
}

@media (max-height: 680px) and (max-width: 560px) {
  .login-view { align-items: start; }
  .brand { margin-bottom: 32px; font-size: 3.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
