:root {
  color-scheme: light;
  --ink: #1c1915;
  --muted: #5c564c;
  --line: #e4ddd2;
  --paper: #f6f3ee;
  --card: #fff;
  --open: #1f6b45;
  --open-dark: #174f34;
  --close: #7a2e24;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  background: var(--paper);
  color: var(--ink);
}
a { color: inherit; }

/* Signed-in shell */
body.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  flex-shrink: 0;
}
.brand {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.menu-toggle {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-bars,
.menu-bars::before,
.menu-bars::after {
  display: block;
  width: 1.1rem;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  position: relative;
}
.menu-bars::before,
.menu-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.menu-bars::before { top: -6px; }
.menu-bars::after { top: 6px; }
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 21, 0.25);
  z-index: 20;
  display: none;
}
.menu-backdrop:not([hidden]) {
  display: block;
}
.app-menu {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(18rem, 88vw);
  height: 100%;
  height: 100dvh;
  padding: calc(0.75rem + var(--safe-top)) 1.1rem calc(1.25rem + var(--safe-bottom));
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(28, 25, 21, 0.08);
  display: none;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
}
.app-menu:not([hidden]) {
  display: flex;
}
.menu-who {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  color: var(--muted);
}
.menu-link,
.menu-sign-out button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.85rem 0.25rem;
  font: inherit;
  font-size: 1.1rem;
  text-decoration: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  color: var(--ink);
}
.menu-sign-out { margin: 0; }
.danger-text { color: var(--close); }
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 40rem;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.15rem;
}
.toast {
  margin: 0.65rem 1.15rem 0;
  max-width: 40rem;
  margin-left: auto;
  margin-right: auto;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  background: #e8f3ec;
  color: var(--open-dark);
  font-size: 0.95rem;
  text-align: center;
}
.toast.bad {
  background: #f8e8e4;
  color: var(--close);
}

/* Open screen */
.open-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  padding: 0 0 0.5rem;
}
.open-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
}
.open-form {
  width: 100%;
  max-width: 16rem;
  margin: 0;
}
.open-big {
  width: 100%;
  aspect-ratio: 1;
  max-height: min(72vw, 16rem);
  border: 0;
  border-radius: 50%;
  font: inherit;
  font-size: clamp(1.5rem, 6vw, 1.85rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--open);
  box-shadow: 0 8px 28px rgba(31, 107, 69, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.open-big:active:not(:disabled) {
  transform: scale(0.96);
}
.open-big:disabled {
  cursor: wait;
  opacity: 0.92;
}
.open-big.busy {
  background: var(--open-dark);
  box-shadow: 0 4px 16px rgba(31, 107, 69, 0.25);
}
.open-big.success {
  background: #2a8f5c;
  animation: open-pulse 0.45s ease;
}
.open-big.error {
  background: #6b5344;
  animation: open-shake 0.35s ease;
}
@keyframes open-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
@keyframes open-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.open-feedback {
  min-height: 1.5rem;
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 1.05rem;
  color: var(--open-dark);
}
.open-feedback.bad { color: var(--close); }
.open-feedback.ok { color: var(--open-dark); }
.install-hint {
  margin: 0;
  padding: 0.75rem 0 0.25rem;
  flex-shrink: 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  max-width: 18rem;
}

/* Auth and admin pages */
body.auth .auth-main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 2rem 1.15rem 4rem;
}
h1 { font-weight: 500; font-size: 2.2rem; letter-spacing: -0.03em; margin: 0 0 0.8rem; }
h2 { font-size: 1.45rem; font-weight: 500; margin: 0 0 0.8rem; }
p.lead, .meta { color: var(--muted); }
.app-main h2 { margin-top: 0.5rem; }
.panel, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.15rem 1.2rem;
}
nav form, td form { display: inline; margin: 0; }
label, .field { display: block; margin-bottom: 0.75rem; }
input[type="email"], input[type="password"], input[type="text"] {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.75rem;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.password-field { position: relative; display: block; margin-top: 0.3rem; }
.password-field input { margin-top: 0; padding-right: 4.75rem; }
button, .link-button {
  font: inherit;
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.15rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary, a.primary { background: var(--ink); color: #fff; }
button.open, a.open {
  background: var(--open);
  color: #fff;
  min-height: 3.2rem;
  padding: 0.9rem 1.4rem;
  font-size: 1.25rem;
}
button.ghost, a.ghost { background: transparent; color: var(--muted); padding: 0.35rem 0.15rem; }
button.danger { background: #f8e8e4; color: var(--close); }
button.reveal {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  color: var(--muted);
  padding: 0.3rem 0.55rem;
}
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
article.log { border-bottom: 1px solid var(--line); padding: 0.8rem 0; }
article.log .action { margin: 0; font-size: 1.05rem; }
article.log p { margin: 0.15rem 0 0; }
table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 0.95rem; }
th { color: var(--muted); font-weight: 500; }
td form { display: inline; }
.app-main > .panel,
.app-main > form.panel,
.app-main > table,
.app-main > p.lead,
.app-main > form:not(.open-form) {
  margin-top: 0.75rem;
}
@media (max-width: 640px) {
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  td { border-bottom: 0; padding: 0.2rem 0; }
  tr { border-bottom: 1px solid var(--line); padding: 0.7rem 0; }
}
