:root {
  --ink: #132238;
  --muted: #64748b;
  --cream: #eff6ff;
  --paper: #ffffff;
  --line: #dbe7f5;
  --pine: #2563eb;
  --pine-dark: #1d4ed8;
  --lime: #dbeafe;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(30, 64, 175, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--cream); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.ambient { position: fixed; border-radius: 999px; filter: blur(1px); opacity: .38; pointer-events: none; z-index: -1; }
.ambient-one { width: 420px; height: 420px; background: #bfdbfe; right: -160px; top: -180px; }
.ambient-two { width: 360px; height: 360px; background: #dbeafe; left: -180px; bottom: -150px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); padding: 42px; border: 1px solid rgba(37,99,235,.16); border-radius: 28px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.brand-mark { width: 60px; height: 60px; display: grid; place-items: center; border-radius: 18px; background: var(--pine); color: var(--lime); font: 800 18px/1 Georgia, serif; letter-spacing: -.04em; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 13px; flex: 0 0 auto; }
.eyebrow { margin: 24px 0 7px; color: var(--pine); font-size: 11px; font-weight: 800; letter-spacing: .17em; }
.login-card h1, .hero h1 { margin: 0; font: 600 clamp(36px, 6vw, 54px)/1.05 Georgia, "Songti SC", serif; letter-spacing: -.035em; }
.login-copy { margin: 16px 0 28px; color: var(--muted); line-height: 1.65; }
.login-form > label, .dialog-body > label { display: grid; gap: 8px; font-size: 13px; font-weight: 700; }
.login-form input, .dialog-body input, .dialog-body textarea, .dialog-body select { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); padding: 13px 14px; outline: none; transition: border-color .2s, box-shadow .2s; }
input:focus, textarea:focus, select:focus { border-color: var(--pine) !important; box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 64px; }
.text-button { position: absolute; right: 6px; top: 6px; bottom: 6px; border: 0; background: transparent; color: var(--pine); font-size: 13px; font-weight: 700; }
.primary-button, .secondary-button, .ghost-button, .danger-button { min-height: 44px; border-radius: 12px; padding: 0 17px; font-weight: 750; border: 1px solid transparent; transition: transform .15s, background .15s, opacity .15s; }
.primary-button { background: var(--pine); color: white; box-shadow: 0 8px 18px rgba(37,99,235,.2); }
.primary-button:hover { background: var(--pine-dark); transform: translateY(-1px); }
.primary-button.full { width: 100%; margin-top: 16px; }
.secondary-button { background: #eff6ff; color: var(--pine); border-color: #bfdbfe; }
.ghost-button { color: var(--ink); background: transparent; border-color: var(--line); }
.danger-button { background: var(--danger); color: #fff; }
button:disabled { cursor: wait; opacity: .6; transform: none !important; }
.privacy-note { margin: 22px 0 0; color: #88908c; font-size: 11px; text-align: center; }
.form-error { color: var(--danger); margin: 9px 0 0; font-size: 13px; line-height: 1.4; }

.topbar { height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 max(24px, calc((100vw - 1200px) / 2)); border-bottom: 1px solid rgba(19,34,56,.10); background: rgba(255,255,255,.86); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; gap: 11px; align-items: center; color: inherit; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font: 600 17px/1.1 Georgia, serif; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.sync-status { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 7px; }
.sync-status i { width: 7px; height: 7px; border-radius: 50%; background: #3aa16d; box-shadow: 0 0 0 4px rgba(58,161,109,.12); }
.content { width: min(1200px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 70px; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 34px; }
.hero .eyebrow { margin-top: 0; }
.hero p:last-child { color: var(--muted); margin: 12px 0 0; }
.hero-actions { display: flex; gap: 10px; flex: 0 0 auto; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { min-height: 154px; padding: 25px; border-radius: 18px; background: var(--paper); border: 1px solid rgba(23,35,31,.09); display: flex; flex-direction: column; justify-content: space-between; }
.stat-card.accent { background: var(--pine); color: #fff; border-color: var(--pine); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.accent .stat-label, .accent small { color: rgba(255,255,255,.7); }
.stat-card strong { display: block; margin-top: 13px; font: 600 32px/1 Georgia, serif; letter-spacing: -.03em; }
.stat-card small { color: var(--muted); font-size: 11px; margin-top: 6px; }
.collection-panel { border-radius: 22px; background: var(--paper); border: 1px solid rgba(19,34,56,.1); overflow: hidden; box-shadow: 0 9px 30px rgba(30,64,175,.06); }
.panel-toolbar { min-height: 96px; padding: 22px 24px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.panel-toolbar h2 { margin: 0; font: 600 21px/1.2 Georgia, serif; }
.panel-toolbar p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.search-box { width: min(320px, 40%); min-height: 43px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: #f8fbff; border: 1px solid var(--line); border-radius: 12px; }
.search-box span { font-size: 22px; color: var(--muted); transform: rotate(-20deg); }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.desktop-table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; table-layout: fixed; }
th { padding: 14px 20px; text-align: left; background: #f4f8fd; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
th:nth-child(1) { width: 22%; } th:nth-child(2) { width: 27%; } th:nth-child(3) { width: 14%; } th:nth-child(4) { width: 15%; } th:nth-child(5) { width: 14%; } th:nth-child(6) { width: 8%; }
td { padding: 18px 20px; border-top: 1px solid #ece9e1; vertical-align: middle; font-size: 13px; }
tbody tr { transition: background .15s; } tbody tr:not(.region-row):hover { background: #f8fbff; }
.region-row th { width: auto; padding: 13px 20px; background: #eaf2ff; color: var(--pine); text-transform: none; letter-spacing: 0; border-top: 1px solid #dbeafe; }
.region-name { font-size: 13px; font-weight: 800; }
.region-count { margin-left: 9px; color: var(--muted); font-size: 11px; font-weight: 600; }
.account-title { font-weight: 750; overflow-wrap: anywhere; }
.account-notes { display: block; color: var(--muted); font-size: 11px; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.game-tag { padding: 4px 8px; border-radius: 99px; background: #eff6ff; color: #334e68; font-size: 11px; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-tag.more { background: #f1f5f9; color: var(--muted); }
.price { font: 600 17px/1 Georgia, serif; white-space: nowrap; }
.purchase-date { color: #405047; font-size: 12px; white-space: nowrap; }
.updated { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 10px; display: grid; place-items: center; background: transparent; color: var(--muted); font-size: 20px; }
.icon-button:hover { background: #eaf2ff; color: var(--ink); }
.icon-button.delete:hover { background: #f8e8e5; color: var(--danger); }
.mobile-cards { display: none; }
.state-panel { min-height: 340px; padding: 50px 24px; display: grid; place-items: center; align-content: center; text-align: center; }
.state-panel h3 { margin: 14px 0 0; font: 600 20px/1.2 Georgia, serif; }
.state-panel p { color: var(--muted); font-size: 13px; margin: 9px 0 18px; }
.spinner { width: 28px; height: 28px; border: 3px solid #d6d6cc; border-top-color: var(--pine); border-radius: 50%; animation: spin .8s linear infinite; }
.state-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: #f8e7e4; color: var(--danger); font: 700 20px Georgia, serif; }
.state-icon.game { background: #eaf2ff; color: var(--pine); }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { width: min(590px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 22px; background: var(--paper); color: var(--ink); box-shadow: 0 30px 100px rgba(13,30,24,.28); }
dialog::backdrop { background: rgba(13,30,24,.48); backdrop-filter: blur(4px); }
.dialog-header { padding: 24px 26px 19px; display: flex; justify-content: space-between; align-items: start; border-bottom: 1px solid var(--line); }
.dialog-header .eyebrow { margin: 0 0 6px; }
.dialog-header h2 { margin: 0; font: 600 25px/1.2 Georgia, serif; }
.dialog-body { padding: 22px 26px; display: grid; gap: 19px; max-height: min(66vh, 620px); overflow-y: auto; }
.dialog-body label > span { color: var(--danger); }
.dialog-body label > small { color: var(--muted); font-weight: 400; }
.dialog-body textarea { resize: vertical; line-height: 1.5; }
.price-field { position: relative; }
.price-field > span { position: absolute; top: 13px; left: 14px; color: var(--muted); }
.price-field input { padding-left: 32px; }
.dialog-footer { padding: 17px 26px max(17px, env(safe-area-inset-bottom)); display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); }
.confirm-dialog { width: min(430px, calc(100% - 32px)); padding: 30px; text-align: center; }
.confirm-dialog h2 { margin: 15px 0 8px; font: 600 23px/1.2 Georgia, serif; }
.confirm-dialog p { margin: 0; color: var(--muted); line-height: 1.6; }
.confirm-icon { width: 50px; height: 50px; display: grid; place-items: center; margin: auto; border-radius: 50%; color: var(--danger); background: #f8e8e5; font: 700 20px Georgia, serif; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 25px; }
.toast-region { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: grid; gap: 10px; }
.toast { min-width: 230px; max-width: 360px; padding: 13px 16px; background: var(--ink); color: white; border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; animation: toast-in .25s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 760px) {
  .login-shell { padding: 16px; align-items: center; }
  .login-card { padding: 30px 22px; border-radius: 22px; }
  .topbar { height: 68px; padding: 0 16px; }
  .brand small, .sync-status { display: none; }
  .top-actions { gap: 8px; }
  .top-actions .ghost-button { min-height: 40px; padding: 0 12px; }
  .content { width: calc(100% - 28px); padding: 34px 0 calc(54px + env(safe-area-inset-bottom)); }
  .hero { align-items: stretch; flex-direction: column; margin-bottom: 25px; }
  .hero h1 { font-size: 39px; }
  .hero-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .hero-actions > button { width: 100%; padding-inline: 10px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { min-height: 128px; padding: 18px; }
  .stat-card:first-child { grid-column: 1 / -1; min-height: 116px; }
  .stat-card strong { font-size: 28px; }
  .collection-panel { border-radius: 18px; }
  .panel-toolbar { padding: 18px; flex-direction: column; align-items: stretch; }
  .search-box { width: 100%; }
  .desktop-table-wrap { display: none; }
  .mobile-cards { display: grid; padding: 12px; gap: 10px; }
  .region-group { display: grid; gap: 9px; }
  .region-group + .region-group { margin-top: 7px; }
  .region-heading { padding: 9px 6px 2px; display: flex; align-items: baseline; justify-content: space-between; color: var(--pine); }
  .region-heading strong { font-size: 14px; }
  .region-heading span { color: var(--muted); font-size: 11px; }
  .region-accounts { display: grid; gap: 10px; }
  .account-card { padding: 17px; border-radius: 15px; border: 1px solid var(--line); background: #ffffff; }
  .card-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
  .card-head .account-title { font-size: 15px; }
  .card-price { color: var(--pine); font: 600 19px/1 Georgia, serif; white-space: nowrap; }
  .card-games { margin-top: 15px; }
  .card-purchase { margin-top: 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
  .card-purchase .card-label { margin: 0; }
  .card-purchase strong { color: #405047; font-size: 12px; }
  .card-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
  .card-footer { margin-top: 16px; padding-top: 12px; border-top: 1px solid #ece9e1; display: flex; align-items: center; justify-content: space-between; }
  .card-footer .updated { font-size: 11px; }
  .card-actions { display: flex; gap: 4px; }
  dialog { width: 100%; max-width: none; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  dialog[open] { animation: sheet-up .22s ease-out; }
  .dialog-body { max-height: 65vh; padding: 20px; }
  .dialog-header { padding: 21px 20px 16px; }
  .dialog-footer { padding-left: 20px; padding-right: 20px; }
  .dialog-footer > button { flex: 1; }
  .confirm-dialog { width: calc(100% - 28px); margin: auto; border-radius: 20px; }
  .toast-region { left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; width: 100%; }
  @keyframes sheet-up { from { transform: translateY(30px); opacity: .7; } }
}

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