/* Osmig's Wallet: 2D line-art dashboard.
   Everything is ink on paper. Accounts are told apart by texture
   (solid / hatch / dots), never by color. Dark mode = chalk on board.
   Two screens: the front page (fits one viewport) and one detail
   view per account, swapped client-side with a soft fade. */

@font-face {
  font-family: "Caveat";
  src: url("/static/fonts/Caveat-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Patrick Hand";
  src: url("/static/fonts/PatrickHand-Regular.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-display: swap;
}

:root {
  --paper: #fcfbf6;
  --ink: #1c1b1a;
  --ink-soft: rgba(28, 27, 26, 0.55);
  --ink-faint: rgba(28, 27, 26, 0.28);
  --line: 2.5px;
  --hand: "Patrick Hand", "Comic Sans MS", cursive;
  --script: "Caveat", "Patrick Hand", cursive;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #191817;
    --ink: #f0ede4;
    --ink-soft: rgba(240, 237, 228, 0.6);
    --ink-faint: rgba(240, 237, 228, 0.3);
  }
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 1.05rem;
  line-height: 1.5;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

main {
  width: min(1200px, 100% - 3rem);
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- view switching ---------- */
.view {
  flex: 1;
  min-height: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.view.entering { opacity: 0; transform: translateY(10px); }
.view.leaving { opacity: 0; transform: translateY(-8px); }
.view[hidden] { display: none !important; }

#view-home {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  padding: 0.8rem 0 1.2rem;
}

/* ---------- header ---------- */
.top {
  width: min(1200px, 100% - 3rem);
  margin: 0 auto;
  padding: 1.1rem 0 0.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: var(--line) solid var(--ink);
}
.wordmark {
  font-family: var(--script);
  font-size: 2.4rem;
  line-height: 1;
}
.asof { font-size: 0.75rem; color: var(--ink-soft); }

/* subtle "working" spinner next to the title: a spinning sketch circle */
.busy {
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-left: 0.45rem;
  vertical-align: 0.15em;
  border: 2px dashed var(--ink-soft);
  border-radius: 50%;
  animation: busy-spin 1.4s linear infinite;
}
.busy[hidden] { display: none; }
@keyframes busy-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .busy { animation: none; border-style: dotted; }
}
.top-right { display: flex; align-items: baseline; gap: 1.1rem; }
.signout {
  font-size: 0.95rem;
  color: var(--ink-soft);
  text-decoration: underline dashed var(--ink-faint) 1px;
  text-underline-offset: 4px;
}
.signout:hover { color: var(--ink); }

/* ---------- login ---------- */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  max-width: 400px;
  width: 100%;
  text-align: center;
  padding: 2rem 2rem 1.8rem;
  cursor: default;
}
.login-card .frame-kind { margin-bottom: 1.4rem; }
.login-btn { display: inline-block; text-decoration: none; }
.login-note { font-size: 0.95rem; color: var(--ink-soft); text-align: left; }
.login-error { margin-top: 1rem; font-size: 0.95rem; }
.login-error::before { content: "✗ "; }

/* ---------- entry gates (admin pass, invitee secret) ---------- */
.gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.9rem;
  text-align: left;
}
.gate-form label { font-size: 0.95rem; color: var(--ink-soft); }
.sketch-input {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px 180px 12px 190px / 190px 12px 180px 12px;
  padding: 0.4rem 0.9rem;
  width: 100%;
}
.sketch-input:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }
.gate-note { margin-top: 1.1rem; text-align: center; }
.notfound-code { font-size: 4.2rem; line-height: 1.1; }

/* ---------- admin ---------- */
.mini-btn {
  font-family: var(--hand);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 120px 8px 110px 8px / 8px 110px 8px 120px;
  padding: 0.1rem 0.7rem;
  cursor: pointer;
  text-decoration: none;
}
.mini-btn:hover { transform: translateY(-1px); }
.admin-link { align-self: center; }

.admin-view .detail-head { align-items: baseline; }
.admin-msg { font-size: 1rem; color: var(--ink-soft); }
.go-back-link { text-decoration: none; display: inline-block; }
.admin-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-top: 1rem; }

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.6rem;
  margin-bottom: 1.8rem;
}
.admin-card {
  border: 2px solid var(--ink);
  border-radius: 15px 225px 15px 255px / 255px 15px 225px 15px;
  padding: 1.1rem 1.3rem 1.2rem;
}
.admin-card-title { font-family: var(--script); font-size: 1.5rem; font-weight: 600; margin-bottom: 0.3rem; }
.admin-fine { font-size: 0.95rem; color: var(--ink-soft); margin-bottom: 0.8rem; }
.admin-warn {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
  text-decoration: underline wavy var(--ink-faint) 1px;
  text-underline-offset: 4px;
}
.admin-card .gate-form { margin-top: 0.2rem; }

.admin-add {
  display: flex;
  gap: 0.7rem;
  margin: 0.5rem 0 1rem;
  max-width: 480px;
}
.admin-table th { position: static; }
.admin-actions { display: flex; gap: 0.5rem; justify-content: flex-end; padding: 0.4rem 0.25rem; }
.admin-actions form { display: inline; }

@media (max-width: 760px) {
  .admin-grid { grid-template-columns: 1fr; }
}

/* ---------- hero ---------- */
.hero { text-align: center; padding: 0.6rem 0; }
.hero-label { font-size: 1.15rem; color: var(--ink-soft); }
.hero-value {
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.hero-pl { font-size: 0.95rem; margin-top: 0.25rem; }
.arrow { font-size: 0.8em; }

/* what-if play on the hero total */
#hero-value { cursor: pointer; }
#hero-value:hover {
  text-decoration: underline dashed var(--ink-faint) 2px;
  text-underline-offset: 10px;
}
#hero-value.editing {
  cursor: text;
  outline: none;
  text-decoration: underline dashed var(--ink) 2.5px;
  text-underline-offset: 10px;
}
.hero-pl.whatif { font-style: italic; }
.neg { text-decoration: underline wavy var(--ink-faint) 1px; text-underline-offset: 4px; }

/* ---------- textures (the palette of this house) ---------- */
.tex-solid { background: var(--ink); }
.tex-hatch {
  background: repeating-linear-gradient(
    45deg, var(--ink) 0 2px, transparent 2px 7px);
}
.tex-dots {
  background-image: radial-gradient(var(--ink) 1.3px, transparent 1.4px);
  background-size: 7px 7px;
}

/* ---------- allocation bar ---------- */
.bar {
  display: flex;
  gap: 3px;
  height: 40px;
  padding: 4px;
  border: var(--line) solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
.seg {
  appearance: none;
  border: none;
  height: 100%;
  border-radius: 3px;
  min-width: 5px;
  cursor: pointer;
  transition: transform 0.16s ease;
}
.seg:hover, .seg:focus-visible { transform: scaleY(1.3); }
.seg:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 2.2rem;
  margin-top: 0.8rem;
  justify-content: center;
}
.legend li { display: flex; align-items: baseline; gap: 0.55rem; }
.swatch {
  width: 15px; height: 15px;
  border: 1.5px solid var(--ink);
  border-radius: 4px 2px 5px 2px;
  align-self: center;
}
.legend-name { font-size: 1.1rem; }
.legend-num { font-size: 0.85rem; }
.legend-pct { font-size: 0.85rem; color: var(--ink-soft); }

/* ---------- the three frames ---------- */
.frames {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.6rem;
}
.frame {
  border: var(--line) solid var(--ink);
  padding: 1.1rem 1.3rem 1rem;
  background: var(--paper);
  box-shadow: 6px 6px 0 -3px var(--paper), 6px 6px 0 -1px var(--ink);
  cursor: pointer;
  transition: transform 0.18s ease;
}
.frame { transform: rotate(var(--rot, 0deg)); }
.frame-1 { --rot: -0.5deg; border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px; }
.frame-2 { --rot: 0.35deg; border-radius: 15px 225px 15px 255px / 255px 15px 225px 15px; }
.frame-3 { --rot: -0.25deg; border-radius: 225px 15px 255px 15px / 15px 255px 15px 225px; }
.frame:hover, .frame:focus-visible, .frame.pop {
  transform: rotate(0deg) translateY(-3px) scale(1.02);
}
.frame.dim { transform: rotate(var(--rot, 0deg)) scale(0.95); }
.frame:focus-visible { outline: 2px dashed var(--ink); outline-offset: 5px; }

.frame-title { font-family: var(--script); font-size: 1.9rem; line-height: 1.1; }
.frame-kind { font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 0.8rem; }
.frame-value { font-size: 1.65rem; letter-spacing: -0.01em; }
.frame-pl { font-size: 0.85rem; margin-top: 0.15rem; }
.frame-meta {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-top: 0.8rem;
  padding-top: 0.55rem;
  border-top: 1.5px dashed var(--ink-faint);
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
}
.frame-open { opacity: 0; transition: opacity 0.18s ease; white-space: nowrap; }
.frame:hover .frame-open, .frame:focus-visible .frame-open { opacity: 1; }

/* ---------- detail view ---------- */
.detail {
  padding: 1rem 0 0.7rem;
  display: flex;
  flex-direction: column;
}
.detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.detail-head {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;
  flex-wrap: wrap;
}
.detail-title { font-family: var(--script); font-size: 2.2rem; line-height: 1; }

.sketch-btn {
  font-family: var(--hand);
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 200px 12px 190px 12px / 12px 190px 12px 200px;
  padding: 0.35rem 1.2rem;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.sketch-btn:hover { transform: translateY(-1px); }
.sketch-btn:active { transform: translate(1px, 1px); }
.sketch-btn:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }

.detail-value { font-size: 1.5rem; letter-spacing: -0.01em; }
.detail-pl { font-size: 0.88rem; }
.detail-meta {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-top: 0.15rem;
  padding-bottom: 0.55rem;
  border-bottom: var(--line) solid var(--ink);
}

/* the table gets whatever space is left and scrolls inside it */
.table-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ---------- tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--paper);
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-align: right;
  padding: 0.6rem 0.3rem 0.4rem;
  border-bottom: 1.5px solid var(--ink-faint);
}
td {
  text-align: right;
  padding: 0.55rem 0.3rem;
  font-size: 0.85rem;
  border-bottom: 1.5px dashed var(--ink-faint);
}
tr:last-child td { border-bottom: none; }
.left { text-align: left; }
.sym { font-family: var(--hand); font-size: 1.05rem; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: rgba(127, 127, 127, 0.08); }
.asset-row .sym { color: var(--ink-soft); }

/* ---------- footer: the brick wainscot from the cafe ---------- */
.wainscot { margin-top: 0.5rem; }
.wainscot::before {
  content: "";
  display: block;
  height: 72px;
  background: var(--ink);
  opacity: 0.25;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='40'%3E%3Crect width='56' height='2' y='0' fill='black'/%3E%3Crect width='56' height='2' y='20' fill='black'/%3E%3Crect width='2' height='20' x='0' y='0' fill='black'/%3E%3Crect width='2' height='20' x='28' y='20' fill='black'/%3E%3C/svg%3E");
  -webkit-mask-size: 56px 40px;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='40'%3E%3Crect width='56' height='2' y='0' fill='black'/%3E%3Crect width='56' height='2' y='20' fill='black'/%3E%3Crect width='2' height='20' x='0' y='0' fill='black'/%3E%3Crect width='2' height='20' x='28' y='20' fill='black'/%3E%3C/svg%3E");
  mask-size: 56px 40px;
}
.wainscot p {
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
  padding: 0.6rem 0 0.9rem;
}

/* subtle tip link in the footer, drawn like everything else */
.coffee {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.9rem;
  color: var(--ink-soft);
  text-decoration: underline dashed var(--ink-faint) 1px;
  text-underline-offset: 4px;
}
.coffee:hover { color: var(--ink); }
.coffee-icon {
  width: 15px;
  height: 15px;
  background: var(--ink-soft);
  -webkit-mask: url("/static/coffee.svg") center / contain no-repeat;
  mask: url("/static/coffee.svg") center / contain no-repeat;
}
.coffee:hover .coffee-icon { background: var(--ink); }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 120px 8px 110px 8px / 8px 110px 8px 120px;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* ---------- Ask: floating chat ---------- */
.ask-fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.3rem;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--hand);
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 200px 12px 190px 12px / 12px 190px 12px 200px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  box-shadow: 4px 4px 0 -2px var(--paper), 4px 4px 0 -0.5px var(--ink);
  transition: transform 0.16s ease;
}
.ask-fab:hover, .ask-fab.active { transform: translateY(-2px) rotate(-1deg); }
.ai-logo {
  width: 19px;
  height: 19px;
  background: var(--ink);
  -webkit-mask: url("/static/openai.svg") center / contain no-repeat;
  mask: url("/static/openai.svg") center / contain no-repeat;
}

.chat-panel {
  position: fixed;
  right: 1.5rem;
  bottom: 4.6rem;
  z-index: 20;
  width: min(380px, 100vw - 2rem);
  height: min(540px, 78dvh);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 15px 225px 15px 255px / 255px 15px 225px 15px;
  box-shadow: 6px 6px 0 -3px var(--paper), 6px 6px 0 -1px var(--ink);
  transform-origin: bottom right;
  animation: chat-pop 0.2s ease;
}
.chat-panel[hidden] { display: none; }
@keyframes chat-pop {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.1rem 0.45rem;
  border-bottom: 1.5px dashed var(--ink-faint);
}
.chat-title { font-family: var(--script); font-size: 1.45rem; }
.chat-head-actions { display: flex; align-items: center; gap: 0.55rem; }
.chat-new {
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  cursor: pointer;
  background: var(--ink-faint);
  -webkit-mask: url("/static/pencil.svg") center / contain no-repeat;
  mask: url("/static/pencil.svg") center / contain no-repeat;
  transition: background 0.15s ease, transform 0.15s ease;
}
.chat-new:hover { background: var(--ink); transform: rotate(-8deg); }
.chat-new:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem 1rem;
}
.msg {
  font-size: 0.95rem;
  line-height: 1.45;
  padding: 0.45rem 0.8rem;
  max-width: 88%;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg.bot {
  align-self: flex-start;
  border: 1.5px solid var(--ink);
  border-radius: 10px 140px 10px 150px / 150px 10px 140px 10px;
}
.msg.user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--paper);
  border-radius: 140px 10px 150px 10px / 10px 150px 10px 140px;
}
.msg.typing { display: flex; gap: 4px; align-items: center; min-height: 1.6rem; }
.msg.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink);
  animation: think 1.1s infinite;
}
.msg.typing span:nth-child(2) { animation-delay: 0.18s; }
.msg.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes think { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }
.chat-form {
  display: flex;
  gap: 0.55rem;
  padding: 0.6rem 1rem 1rem;
}
.chat-form .sketch-input { font-family: var(--hand); }

/* ---------- cmd+A payload modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(22, 21, 20, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  width: min(680px, 100%);
  cursor: default;
  padding: 1.4rem 1.5rem 1.3rem;
}
.paste-area {
  width: 100%;
  min-height: 230px;
  resize: vertical;
  border-radius: 10px;
  font-size: 0.78rem;
  line-height: 1.4;
  margin-top: 0.7rem;
}
.modal-error { margin-top: 0.6rem; font-size: 0.9rem; }
.modal-error::before { content: "✗ "; }
.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.9rem;
}

/* ---------- responsive ---------- */
@media (min-width: 1100px) {
  th { font-size: 0.95rem; padding: 0.65rem 0.5rem 0.45rem; }
  td { font-size: 0.95rem; padding: 0.6rem 0.5rem; }
  .sym { font-size: 1.15rem; }
  .detail-title { font-size: 2.4rem; }
  .detail-value { font-size: 1.65rem; }
}
@media (max-width: 900px) {
  .frames { grid-template-columns: 1fr; }
  .frame-1, .frame-2, .frame-3 { --rot: 0deg; }
  #view-home { gap: 1.6rem; justify-content: flex-start; }
}
@media (max-width: 640px) {
  .opt { display: none; }
  .legend { flex-direction: column; gap: 0.3rem; align-items: flex-start; }
  .detail-top { flex-direction: column-reverse; align-items: flex-end; }
  .detail-top > div { align-self: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
