:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #059669;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaee;
    --muted: #9099a8;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #232845;
    --danger: #f87171;
    --danger-soft: #3a1d1f;
    --ok: #34d399;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 18px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

button { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
  text-decoration: none; color: var(--text); transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f1115; } }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

input[type=email], input[type=password], input[type=text] {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; font-weight: 500; margin: 12px 0 6px; }
.code-input { font-size: 22px !important; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; max-width: 1200px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 16px;
}
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.balance {
  padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.menu { position: relative; }
.menu-btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column;
}
.menu-list button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }

.auth { display: grid; place-items: start center; padding: 6vh 16px 40px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px;
}
.auth-card > p { margin: 8px 0 20px; }
.tabs { display: flex; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 4px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.form-error { color: var(--danger); min-height: 1.5em; margin: 10px 0; font-size: 14px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; font-size: 14px; }
.auth-note { margin-top: 12px; font-size: 14px; }

.app { max-width: 1200px; margin: 0 auto; padding: 0 16px 48px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.stats { color: var(--muted); font-size: 14px; margin-top: 2px; }
.meter { width: 220px; max-width: 100%; height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.meter div.full { background: var(--danger); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions .hint { font-size: 13px; color: var(--danger); }

.banner {
  margin-top: 16px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft);
  display: flex; flex-direction: column; gap: 8px; font-size: 14px;
}
.banner .bar { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--accent) 20%, transparent); overflow: hidden; }
.banner .bar div { height: 100%; background: var(--accent); transition: width .4s; }
.banner.done { background: var(--surface-2); }

.drop {
  margin-top: 16px; border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 28px 16px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop svg { color: var(--accent); }
.drop b { color: var(--text); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.compact { padding: 14px 16px; flex-direction: row; justify-content: center; gap: 12px; }
.drop.compact svg { width: 22px; height: 22px; }

.notices { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.notices:empty { display: none; }
.notice {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 8px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 14px;
}
.notice button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 16px; line-height: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.grid:empty { display: none; }
.card {
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface);
  display: flex; flex-direction: column;
}
.thumb { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.thumb img { position: relative; width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; font-weight: 600; }
.remove {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; font-size: 18px; line-height: 1;
  display: grid; place-items: center;
}
.remove:hover { background: rgba(220, 38, 38, .9); }
.overlay {
  position: absolute; inset: auto 8px 8px 8px; padding: 6px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.overlay .bar { flex: 1; height: 4px; border-radius: 2px; background: rgba(255,255,255,.3); overflow: hidden; }
.overlay .bar div { height: 100%; background: #fff; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; opacity: .7; flex: none; }

.card-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.fname { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.fname span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.copy { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; font-weight: 600; padding: 2px 4px; border-radius: 6px; text-transform: none; letter-spacing: 0; }
.copy:hover { background: var(--accent-soft); }
.title-text { font-size: 14px; font-weight: 500; }
.kw-text {
  font-size: 13px; color: var(--text); max-height: 7.5em; overflow: auto; padding: 8px 10px;
  border-radius: 8px; background: var(--surface-2); line-height: 1.5;
}
.card-error { color: var(--danger); font-size: 14px; }
.card-foot { margin-top: auto; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 24px; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.history { list-style: none; padding: 0; margin: 0; max-height: 50vh; overflow: auto; }
.history li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.history .plus { color: var(--ok); font-weight: 600; }
.history .minus { font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
}

@media (max-width: 600px) {
  .auth-card { padding: 20px; }
  .panel { padding: 14px; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .actions .btn { flex: 1; }
  .grid { grid-template-columns: 1fr; }
  .menu-btn { max-width: 120px; }
  .brand { font-size: 16px; }
}
