/* Sora: a night sky of everything you're curious about. Japandi dark, same family as KAYX. */

:root {
  --bg: #1c1a17;
  --bg-2: #22201c;
  --card: #262320;
  --raise: #2b2824;
  --ink: #ece5d9;
  --mute: #a39b8f;
  --faint: #6f685e;
  --line: rgba(236, 229, 217, 0.11);
  --line-2: rgba(236, 229, 217, 0.2);
  --clay: #c88d6d;
  --danger: #d9826f;
  --sans: 'Poppins', system-ui, sans-serif;
  --serif: 'Shippori Mincho', 'Yu Mincho', Georgia, serif;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 300 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }
.kanji { font-family: var(--serif); font-weight: 600; }
.readonly .ro-hide, body:not(.readonly) .ro-show { display: none !important; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Sign in ---------- */
#login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(ellipse at 50% 30%, #2a2622 0%, var(--bg) 70%);
}
#login form { width: min(320px, 100%); display: grid; gap: 12px; text-align: center; }
#login .kanji { font-size: 64px; line-height: 1; margin: 0; color: var(--clay); }
#login h1 { font: 500 26px/1.2 var(--serif); margin: 4px 0 0; letter-spacing: 0.04em; }
#login .lede { margin: 0 0 18px; color: var(--mute); font-size: 14px; }
#login input {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 12px 14px; font-size: 16px; outline: none; text-align: center;
}
#login input:focus { border-color: var(--clay); }
#login button[type=submit] {
  background: var(--clay); color: #1c1a17; font-weight: 500; border-radius: 10px; padding: 12px;
}
.err { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 13px; }
a.quiet { color: var(--mute); font-size: 13px; text-decoration: none; border-bottom: 1px solid var(--line-2); justify-self: center; }

/* ---------- Canvas ---------- */
#app { position: fixed; inset: 0; }
#canvas {
  position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(circle, rgba(236, 229, 217, 0.075) 1px, transparent 1.4px);
  background-size: 40px 40px;
}
#canvas::after { /* soft vignette, sits above the dot grid only */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.28) 100%);
}
#canvas.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; z-index: 1; }
#links { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#links .ln { stroke: rgba(236, 229, 217, 0.28); stroke-width: 1.2; fill: none; vector-effect: non-scaling-stroke; transition: opacity .3s; }
#links .ln.rel { stroke-dasharray: 3 5; }
#links .ah { fill: rgba(236, 229, 217, 0.4); stroke: none; }
#links .on { stroke: var(--clay); opacity: 1; }
#links .ah.on { fill: var(--clay); }
#links .dim { opacity: 0.35; }
#links .temp { stroke: var(--clay); stroke-dasharray: 4 4; }

.card {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 9px;
  width: max-content; max-width: 240px; padding: 8px 14px 8px 11px;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: opacity .3s, border-color .2s, background .2s;
}
.card:hover { border-color: var(--line-2); }
.card .dot {
  flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--k);
  box-shadow: 0 0 calc(2px + var(--warm, 0) * 12px) calc(var(--warm, 0) * 2px) var(--k);
}
.card .t {
  font-size: 14px; line-height: 1.3; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere;
}
.card.k-word .t { font-family: var(--serif); font-weight: 500; font-size: 15px; }
.card .handle {
  position: absolute; right: -9px; top: 50%; width: 18px; height: 18px; margin-top: -9px;
  border-radius: 50%; background: var(--bg); border: 1px solid var(--clay); cursor: crosshair;
  opacity: 0; transform: scale(.6); transition: opacity .2s, transform .2s;
}
.card .handle::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: var(--clay); }
.card.sel .handle, .card:hover .handle { opacity: 1; transform: none; }
@media (hover: none) { .card:hover .handle { opacity: 0; } .card.sel .handle { opacity: 1; transform: none; } }
.card.sel { border-color: var(--clay); background: var(--raise); z-index: 2; }
.card.drop { border-color: var(--clay); box-shadow: 0 0 0 3px rgba(200, 141, 109, .25); }
.card.dragging { z-index: 3; cursor: grabbing; }
.focus .card:not(.sel):not(.near) { opacity: 0.42; }
.card.born { animation: born .7s var(--ease); }
@keyframes born { from { opacity: 0; transform: translate(-50%, -50%) scale(.7); } }
.card.flash { animation: flash 1.2s var(--ease); }
@keyframes flash { 30% { border-color: var(--clay); box-shadow: 0 0 0 6px rgba(200, 141, 109, .22); } }

/* Zoomed far out: cards become stars with labels that stay readable */
.far .card {
  padding: 0; background: none; border: 0; border-radius: 50%; gap: 0;
  width: calc(9px / var(--z)); height: calc(9px / var(--z)); max-width: none; overflow: visible;
}
.far .card .dot {
  width: 100%; height: 100%;
  box-shadow: 0 0 calc((3px + var(--warm, 0) * 14px) / var(--z)) calc(var(--warm, 0) * 2px / var(--z)) var(--k);
}
.far .card .t {
  position: absolute; left: calc(100% + 6px / var(--z)); top: 50%; transform: translateY(-50%);
  font-size: calc(12px / var(--z)); white-space: nowrap; display: block; max-width: none;
  color: var(--mute); opacity: calc(0.45 + var(--warm, 0) * 0.55); pointer-events: none;
}
.far .card.sel .t, .far .card.near .t { color: var(--ink); opacity: 1; }
.far .card.nolabel .t { opacity: 0; }
.far .card.nolabel:hover .t { opacity: 1; z-index: 5; }
.far .card .handle { display: none; }

#ghost {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
  border: 1px dashed var(--clay); animation: pulse 1.6s infinite var(--ease);
}
@keyframes pulse { 50% { transform: scale(1.35); opacity: .5; } }

#empty {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 2;
  margin: 0; text-align: center; color: var(--mute); pointer-events: none; width: min(360px, 90vw);
}
#empty .kanji { display: block; font-size: 54px; color: var(--clay); opacity: .55; margin-bottom: 10px; }

/* ---------- Top bar ---------- */
#top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-t)) 16px 12px; pointer-events: none;
}
#top > * { pointer-events: auto; }
.brand { font: 500 17px/1 var(--serif); letter-spacing: .03em; display: flex; align-items: baseline; gap: 6px; }
.brand .kanji { color: var(--clay); font-size: 19px; }
#count { font: 300 12px var(--sans); color: var(--faint); margin-left: 4px; }
.tag { font: 400 11px var(--sans); color: var(--mute); border: 1px solid var(--line-2); border-radius: 99px; padding: 3px 8px; margin-left: 6px; }
#top nav { display: flex; gap: 4px; }
button.icon {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px;
  color: var(--mute); background: rgba(28, 26, 23, .7); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid transparent; transition: color .2s, border-color .2s;
}
button.icon:hover, button.icon.on { color: var(--ink); border-color: var(--line); }
.pop {
  position: absolute; right: 16px; top: calc(56px + var(--safe-t)); min-width: 210px; padding: 6px;
  background: var(--raise); border: 1px solid var(--line-2); border-radius: 12px;
  display: grid; box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.pop button { text-align: left; padding: 9px 12px; border-radius: 8px; font-size: 14px; }
.pop button:hover { background: rgba(236, 229, 217, .06); }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

/* ---------- Capture ---------- */
#capture {
  position: absolute; z-index: 10; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  width: min(620px, calc(100% - 32px));
  background: rgba(38, 35, 32, .88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line-2); border-radius: 16px; padding: 8px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .3);
  transition: border-color .2s, transform .35s var(--ease), opacity .3s;
}
@media (min-width: 701px) {
  .panel-open #capture { left: calc((100% - 400px) / 2); width: min(620px, calc(100% - 432px)); }
}
#capture:focus-within { border-color: rgba(200, 141, 109, .55); }
.cap-row { display: flex; gap: 8px; align-items: center; }
#cap-input {
  flex: 1; min-width: 0; background: none; border: 0; outline: none; padding: 8px 8px 8px 10px; font-size: 16px;
}
#cap-input::placeholder { color: var(--faint); }
#cap-add {
  flex: none; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--clay); color: #1c1a17;
}
#cap-add svg { stroke-width: 2; }
.cap-from {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px 6px 10px; font-size: 12px; color: var(--mute);
}
.cap-from b { font-weight: 400; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.cap-from button { color: var(--faint); font-size: 16px; line-height: 1; padding: 0 4px; }
.cap-from button:hover { color: var(--ink); }
.cap-kinds { display: none; gap: 6px; padding: 2px 4px 8px; overflow-x: auto; scrollbar-width: none; }
.cap-kinds::-webkit-scrollbar { display: none; }
#capture.typing .cap-kinds { display: flex; }

.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px;
  font-size: 12px; color: var(--mute); border: 1px solid var(--line); white-space: nowrap;
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--k); }
.chip:hover { color: var(--ink); }
.chip.on { color: var(--ink); border-color: var(--k); background: rgba(236, 229, 217, .04); }

/* ---------- Card page ---------- */
#panel {
  position: absolute; z-index: 20; top: 0; right: 0; bottom: 0; width: min(400px, 100%);
  background: var(--bg-2); border-left: 1px solid var(--line);
  transform: translateX(105%); transition: transform .38s var(--ease);
  overflow-y: auto; overscroll-behavior: contain;
  padding: calc(18px + var(--safe-t)) 24px calc(28px + var(--safe-b));
}
#panel.open { transform: none; }
#panel .close { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; background: none; }
#panel .grab { display: none; }
.p-trail { font-size: 12px; color: var(--faint); margin: 4px 44px 14px 0; line-height: 1.7; }
.p-trail button { color: var(--mute); }
.p-trail button:hover { color: var(--ink); }
.p-trail .sep { margin: 0 5px; }
.p-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 40px 14px 0; }
.p-title {
  display: block; width: 100%; resize: none; overflow: hidden; background: none; border: 0; outline: none; padding: 0;
  font: 500 26px/1.25 var(--serif); letter-spacing: .01em; margin: 0;
}
.p-meta { color: var(--faint); font-size: 12.5px; margin: 8px 0 22px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; outline: none;
  padding: 10px 12px; font-size: 15px; line-height: 1.6;
}
.field textarea { min-height: 150px; resize: none; overflow: hidden; }
.field input:focus, .field textarea:focus { border-color: rgba(200, 141, 109, .6); }
.field input::placeholder, .field textarea::placeholder { color: var(--faint); }
.ro-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.ro-text a, .p-source a { color: var(--clay); }

.threads h3 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 400; margin: 20px 0 6px; }
.thread { display: flex; align-items: center; gap: 4px; }
.thread > button:first-child {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; text-align: left; padding: 7px 8px; border-radius: 8px;
}
.thread > button:first-child:hover { background: rgba(236, 229, 217, .05); }
.thread .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--k); }
.thread .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .rm { flex: none; width: 28px; height: 28px; color: var(--faint); border-radius: 8px; font-size: 16px; }
.thread .rm:hover { color: var(--danger); }
.none { color: var(--faint); font-size: 13px; margin: 4px 0; }

.linker { position: relative; margin-top: 14px; }
.linker input { width: 100%; background: none; border: 1px dashed var(--line-2); border-radius: 10px; padding: 9px 12px; outline: none; font-size: 14px; }
.linker input:focus { border-style: solid; border-color: rgba(200, 141, 109, .6); }
.linker-results { display: grid; gap: 2px; margin-top: 6px; }
.lr { display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 8px; border-radius: 8px; font-size: 14px; }
.lr:hover { background: rgba(236, 229, 217, .04); }
.lr .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--k); }
.lr .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr button { flex: none; font-size: 12px; color: var(--mute); border: 1px solid var(--line); border-radius: 99px; padding: 3px 9px; }
.lr button:hover { color: var(--ink); border-color: var(--clay); }

.p-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.btn { border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 14px; font-size: 14px; }
.btn:hover { border-color: var(--clay); }
.btn.primary { background: var(--clay); color: #1c1a17; border-color: var(--clay); font-weight: 400; }
.btn.danger { color: var(--danger); border-color: transparent; margin-left: auto; }
.btn.danger:hover { border-color: var(--danger); }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--mute); cursor: pointer; width: 100%; margin-bottom: 4px; }
.switch input { appearance: none; -webkit-appearance: none; width: 36px; height: 20px; border-radius: 99px; background: var(--line-2); position: relative; cursor: pointer; transition: background .2s; margin: 0; flex: none; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: transform .2s var(--ease); }
.switch input:checked { background: var(--clay); }
.switch input:checked::after { transform: translateX(16px); }
.switch small { color: var(--faint); font-size: 12px; }

/* ---------- Timeline ---------- */
#timeline {
  position: absolute; z-index: 20; top: 0; left: 0; bottom: 0; width: min(380px, 100%);
  background: var(--bg-2); border-right: 1px solid var(--line);
  transform: translateX(-105%); transition: transform .38s var(--ease);
  display: flex; flex-direction: column;
}
#timeline.open { transform: none; }
#timeline header { display: flex; align-items: center; justify-content: space-between; padding: calc(14px + var(--safe-t)) 12px 8px 22px; }
#timeline h2 { font: 500 20px var(--serif); margin: 0; }
#timeline header .icon { background: none; }
#tl-list { flex: 1; overflow-y: auto; padding: 0 14px calc(30px + var(--safe-b)); overscroll-behavior: contain; }
.tl-month { font: 500 15px var(--serif); margin: 22px 8px 4px; display: flex; justify-content: space-between; align-items: baseline; }
.tl-month small { font: 300 12px var(--sans); color: var(--faint); }
.tl-day { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin: 14px 8px 4px; }
.tl-item { display: flex; gap: 10px; width: 100%; text-align: left; padding: 7px 8px; border-radius: 9px; align-items: baseline; }
.tl-item:hover { background: rgba(236, 229, 217, .05); }
.tl-item .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--k); transform: translateY(-1px); }
.tl-item .nm { flex: 1; min-width: 0; }
.tl-item .from { display: block; font-size: 12px; color: var(--faint); }
.tl-item time { font-size: 12px; color: var(--faint); flex: none; }
.resurface { margin: 6px 0 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.resurface p { margin: 0 0 8px; font-size: 13px; color: var(--mute); }
.resurface button { font: 500 17px var(--serif); text-align: left; }
.resurface button:hover { color: var(--clay); }

/* ---------- Search ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 30; background: rgba(18, 17, 15, .6);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; justify-content: center; align-items: flex-start; padding: calc(80px + var(--safe-t)) 16px 16px;
}
.overlay .box { width: min(520px, 100%); background: var(--raise); border: 1px solid var(--line-2); border-radius: 14px; overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); }
#search-input { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); outline: none; padding: 16px 18px; font-size: 17px; }
#search-results { max-height: 50vh; overflow-y: auto; padding: 6px; }
#search-results:empty { display: none; }
.sr { display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left; padding: 9px 12px; border-radius: 9px; }
.sr.on, .sr:hover { background: rgba(236, 229, 217, .06); }
.sr .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--k); transform: translateY(-1px); }
.sr .nm { flex: 1; min-width: 0; }
.sr small { display: block; color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toast ---------- */
#toast {
  position: absolute; z-index: 40; left: 50%; top: calc(64px + var(--safe-t)); transform: translate(-50%, -8px);
  background: var(--raise); border: 1px solid var(--line-2); border-radius: 99px; padding: 8px 16px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s var(--ease); white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Phones ---------- */
@media (max-width: 700px) {
  #panel {
    top: auto; left: 0; width: 100%; max-height: 82dvh; border-left: 0; border-top: 1px solid var(--line-2);
    border-radius: 18px 18px 0 0; transform: translateY(105%); padding-top: 22px;
    box-shadow: 0 -16px 50px rgba(0, 0, 0, .35);
  }
  #panel .grab { display: block; position: absolute; top: 8px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 9px; background: var(--line-2); }
  #panel .close { top: 10px; }
  .panel-open #capture { opacity: 0; pointer-events: none; transform: translate(-50%, 30px); }
  .p-title { font-size: 23px; }
  .brand #count { display: none; }
  #top nav { gap: 2px; }
  .overlay { padding-top: calc(64px + var(--safe-t)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
