:root {
  --ink-0: #12100d;
  --ink-1: #17140f;
  --ink-2: #1d1913;
  --line: #2b2519;
  --line-soft: #241f15;
  --paper: #e8dcc3;
  --paper-dim: #a99a7c;
  --paper-faint: #6f6450;
  --gold: #d4a24e;
  --gold-soft: rgba(212, 162, 78, 0.14);
  --seal: #a8402a;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "STZhongsong", "SimSun", serif;
  --font-mono: "IBM Plex Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

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

html, body { height: 100%; }

body {
  background:
    radial-gradient(1100px 720px at 88% -12%, rgba(212, 162, 78, 0.09), transparent 62%),
    radial-gradient(900px 700px at -8% 112%, rgba(94, 119, 87, 0.07), transparent 60%),
    var(--ink-0);
  color: var(--paper);
  font-family: var(--font-serif);
  overflow-x: hidden;
  min-height: 100vh;
}

::selection { background: rgba(212, 162, 78, 0.35); color: #fff8ea; }

.watermark {
  position: fixed;
  right: -4vw;
  bottom: -14vh;
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: min(58vw, 44rem);
  line-height: 1;
  color: rgba(224, 179, 106, 0.035);
  z-index: 0;
  user-select: none;
  pointer-events: none;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.page {
  position: relative;
  z-index: 2;
  max-width: 1120px;
  margin: 0 auto;
  padding: 56px 28px 48px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
  animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.brand { display: flex; align-items: center; gap: 18px; }

.brand-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  background: var(--seal);
  color: #f7ecd8;
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 2px;
  writing-mode: vertical-rl;
  box-shadow: 0 10px 30px rgba(168, 64, 42, 0.35), inset 0 0 0 2px rgba(247, 236, 216, 0.22);
  transform: rotate(-3deg);
}

.brand-meta h1 {
  font-size: clamp(26px, 3.4vw, 38px);
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1.15;
}

.brand-meta h1 em {
  font-style: normal;
  font-weight: 600;
  font-size: 0.52em;
  color: var(--gold);
  letter-spacing: 2px;
}

.brand-sub {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--paper-faint);
}

.clock { text-align: right; }

.clock-time {
  font-family: var(--font-mono);
  font-size: clamp(22px, 2.6vw, 30px);
  font-weight: 500;
  color: var(--paper);
  letter-spacing: 2px;
}

.clock-date {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--paper-faint);
  letter-spacing: 1px;
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 26px 0 22px;
  animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.3, 1) 0.08s both;
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 460px;
  padding: 10px 16px;
  background: var(--ink-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: border-color 0.25s, background 0.25s;
}

.search:focus-within { border-color: var(--gold); background: var(--ink-2); }

.search-key {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--paper-faint);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 8px;
}

.search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--paper);
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: 1px;
}

.search input::placeholder { color: var(--paper-faint); }

.counter {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--paper-dim);
  letter-spacing: 1px;
  white-space: nowrap;
}

.counter b { color: var(--gold); font-weight: 500; }

/* ---------- grid & cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
  gap: 16px;
  min-height: 200px;
}

.card {
  position: relative;
  padding: 20px 18px 18px;
  background: linear-gradient(165deg, var(--ink-2), var(--ink-1));
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  animation: rise 0.65s cubic-bezier(0.2, 0.7, 0.3, 1) both;
  animation-delay: calc(var(--i) * 70ms + 0.12s);
  transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.3, 1), border-color 0.3s, box-shadow 0.3s;
}

.card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 18px;
  right: 18px;
  height: 2px;
  border-radius: 2px;
  background: hsl(var(--h) 55% 55%);
  opacity: 0;
  transition: opacity 0.3s;
}

.card:hover {
  transform: translateY(-5px);
  border-color: hsl(var(--h) 38% 38%);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.5);
}

.card:hover::after { opacity: 0.9; }

.card-link {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}

.card-body { position: relative; display: flex; align-items: center; gap: 14px; }

.glyph {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 11px;
  font-size: 24px;
  font-weight: 600;
  background: hsl(var(--h) 30% 16%);
  color: hsl(var(--h) 55% 68%);
  border: 1px solid hsl(var(--h) 30% 26%);
  transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.card:hover .glyph { transform: scale(1.08) rotate(-3deg); }

.card-text { min-width: 0; }

.card-name {
  display: block;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-url {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--paper-faint);
  letter-spacing: 0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 6px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s, transform 0.25s;
}

.card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; transform: none; }

.act {
  font-family: var(--font-serif);
  font-size: 12px;
  letter-spacing: 1px;
  padding: 4px 9px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: rgba(18, 16, 13, 0.85);
  color: var(--paper-dim);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.act:hover { color: var(--paper); border-color: var(--gold); }

.act.del.armed {
  color: #ffb4a1;
  border-color: var(--seal);
  background: rgba(168, 64, 42, 0.25);
}

/* ---------- add card ---------- */

.add-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 118px;
  border: 1.5px dashed #3a3223;
  border-radius: 12px;
  background: transparent;
  color: var(--paper-faint);
  font-family: var(--font-serif);
  cursor: pointer;
  animation: rise 0.65s cubic-bezier(0.2, 0.7, 0.3, 1) both;
  animation-delay: calc(var(--i) * 70ms + 0.12s);
  transition: color 0.25s, border-color 0.25s, background 0.25s, transform 0.3s;
}

.add-card .plus { font-size: 30px; font-weight: 400; line-height: 1; }

.add-card .add-tip { font-size: 13px; letter-spacing: 2px; }

.add-card:hover { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); transform: translateY(-5px); }

.add-card.locked { cursor: not-allowed; opacity: 0.45; }
.add-card.locked:hover { color: var(--paper-faint); border-color: #3a3223; background: transparent; transform: none; }

.empty-hint {
  grid-column: 1 / -1;
  padding: 44px 20px;
  text-align: center;
  color: var(--paper-faint);
  font-size: 15px;
  letter-spacing: 2px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  animation: rise 0.65s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

/* ---------- toolbar extras & lock ---------- */

.toolbar-right { display: flex; align-items: center; gap: 14px; }

.lock {
  font-family: var(--font-serif);
  font-size: 12.5px;
  letter-spacing: 1px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: none;
  color: var(--paper-dim);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.lock:hover { color: var(--paper); border-color: var(--paper-dim); }

.lock.unlocked { color: #b8d8a8; border-color: #46603f; }

body.locked .card-actions { display: none; }

/* ---------- modal ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 9, 6, 0.72);
  backdrop-filter: blur(6px);
}

.modal-mask[hidden] { display: none; }

.modal {
  width: min(420px, 100%);
  padding: 28px 26px 24px;
  background: var(--ink-2);
  border: 1px solid #342d1f;
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: pop 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.modal h2 { font-size: 20px; font-weight: 900; letter-spacing: 3px; margin-bottom: 20px; }
.modal h2::before { content: "※ "; color: var(--gold); }

.field { display: block; margin-bottom: 15px; }

.field-label {
  display: block;
  font-size: 13px;
  letter-spacing: 1.5px;
  color: var(--paper-dim);
  margin-bottom: 7px;
}

.field-label i { font-style: normal; font-size: 11px; color: var(--paper-faint); margin-left: 6px; }

.field input {
  width: 100%;
  padding: 11px 14px;
  background: var(--ink-1);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--paper);
  font-family: var(--font-serif);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.field input:focus { border-color: var(--gold); background: #201b13; }
.field input::placeholder { color: var(--paper-faint); }

.field input.invalid { border-color: var(--seal); background: rgba(168, 64, 42, 0.12); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.btn {
  font-family: var(--font-serif);
  font-size: 14px;
  letter-spacing: 2px;
  padding: 10px 22px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn.ghost { background: none; border: 1px solid var(--line); color: var(--paper-dim); }
.btn.ghost:hover { color: var(--paper); border-color: var(--paper-dim); }

.btn.primary {
  background: var(--gold);
  border: 1px solid var(--gold);
  color: #241a08;
  font-weight: 600;
}

.btn.primary:hover { background: #e2b563; box-shadow: 0 8px 24px rgba(212, 162, 78, 0.3); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 60;
  transform: translateX(-50%);
  padding: 11px 22px;
  background: #26201565;
  background: rgba(38, 32, 21, 0.95);
  border: 1px solid #3d3524;
  border-radius: 10px;
  color: var(--paper);
  font-size: 13.5px;
  letter-spacing: 1.5px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.toast[hidden] { display: none; }

/* ---------- animations ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: none; }
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

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

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .page { padding: 34px 18px 36px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { justify-content: space-between; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card { padding: 16px 14px 14px; }
  .glyph { width: 42px; height: 42px; font-size: 20px; }
  .card-name { font-size: 15px; }
  .card-actions { opacity: 1; transform: none; }
}
