:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #071018;
  --bg-deep: #04080e;
  --panel: #0c1826;
  --panel-raised: #122235;
  --panel-soft: #152a40;
  --line: #2a3f58;
  --line-gold: rgba(210, 167, 66, .45);
  --gold: #d7b15a;
  --gold-bright: #f0d58a;
  --gold-dark: #9a6a18;
  --text: #eef3f8;
  --muted: #8fa0b5;
  --green: #6ed9a0;
  --red: #ff8b96;
  --shadow: 0 18px 48px rgba(0, 0, 0, .42);
  --hover-lift: translateY(-2px);
  --press: scale(.985);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fa;
  --bg-deep: #e8eef5;
  --panel: #ffffff;
  --panel-raised: #f8fafc;
  --panel-soft: #eef3f8;
  --line: #d5dee8;
  --line-gold: rgba(166, 124, 42, .35);
  --gold: #9a6f1c;
  --gold-bright: #7a5514;
  --gold-dark: #6a4a12;
  --text: #152033;
  --muted: #5d6d82;
  --green: #1f9a5c;
  --red: #c53d4a;
  --shadow: 0 14px 36px rgba(24, 40, 64, .12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg-deep);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 72% -10%, color-mix(in srgb, var(--gold) 18%, transparent), transparent 42%),
    linear-gradient(160deg, var(--bg-deep) 0%, var(--bg) 48%, var(--bg-deep) 100%);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", "Helvetica Neue", sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: .2;
  background-image:
    linear-gradient(rgba(226, 189, 89, .12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(226, 189, 89, .08) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .8), transparent 78%);
}

.hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  padding: 12px 19px;
  border: 1px solid #f7db88;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffe69a 0%, #e6bd58 48%, #b77b1c 100%);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, .75),
    0 8px 20px rgba(164, 108, 20, .2);
  color: #130d04;
  font-weight: 900;
  letter-spacing: .015em;
  cursor: pointer;
  transition: border-color .16s ease, filter .16s ease, transform .16s ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(255, 220, 122, .28);
  outline-offset: 2px;
}

button:disabled {
  opacity: .5;
  cursor: wait;
  transform: none;
}

.login-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  isolation: isolate;
  overflow: hidden;
  padding: 40px 24px;
}

.login-shell::before,
.login-shell::after {
  position: absolute;
  z-index: -1;
  content: "";
  pointer-events: none;
}

.login-shell::before {
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent, #8c5910 16%, #ffdf7d 50%, #8c5910 84%, transparent);
  box-shadow: 0 0 30px rgba(226, 184, 72, .45);
}

.login-shell::after {
  width: min(900px, 88vw);
  height: min(900px, 88vw);
  border: 1px solid rgba(219, 177, 69, .12);
  border-radius: 50%;
  box-shadow:
    0 0 0 100px rgba(218, 174, 66, .018),
    0 0 0 220px rgba(218, 174, 66, .012);
}

.login-stage {
  position: absolute;
  z-index: -1;
  inset: 0;
  background:
    radial-gradient(circle at 50% 44%, rgba(22, 56, 96, .7), transparent 31%),
    radial-gradient(circle at 50% 44%, rgba(228, 188, 80, .11), transparent 47%);
}

.login-card {
  position: relative;
  width: min(520px, 100%);
  padding: 34px 40px 30px;
  overflow: hidden;
  border: 1px solid var(--line-gold);
  border-radius: 22px;
  background:
    linear-gradient(155deg, rgba(16, 35, 60, .98), rgba(4, 13, 25, .985)),
    var(--panel);
  box-shadow:
    var(--shadow),
    inset 0 1px rgba(255, 236, 171, .09);
}

.login-card::before {
  position: absolute;
  top: 0;
  right: 12%;
  left: 12%;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--gold-bright), transparent);
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding-bottom: 21px;
  border-bottom: 1px solid rgba(222, 181, 76, .26);
}

.login-logo {
  display: block;
  width: 130px;
  height: 130px;
  object-fit: contain;
  filter: drop-shadow(0 8px 15px rgba(0, 0, 0, .55));
}

.eyebrow {
  margin: 18px 0 4px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.login-brand .eyebrow {
  margin: 0 0 6px;
}

.login-card h1 {
  margin: 0;
  background: linear-gradient(180deg, #fff4c3 2%, #e6bd59 65%, #ac711a 100%);
  background-clip: text;
  color: transparent;
  font: 900 clamp(27px, 6vw, 37px)/1 Georgia, "Times New Roman", serif;
  letter-spacing: .055em;
  white-space: nowrap;
}

.login-product {
  margin: 8px 0 0;
  color: #f7f8fb;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .29em;
}

.login-intro {
  margin: 22px 0 8px;
  color: var(--muted);
  text-align: center;
}

.login-card label,
dialog label {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  color: #d7dfeb;
  font-size: 13px;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  background: #071323;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .22);
  color: var(--text);
  transition: border-color .16s ease, box-shadow .16s ease;
}

input:hover,
select:hover {
  border-color: #3b5272;
}

input:focus,
select:focus {
  border-color: var(--gold);
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, .22),
    0 0 0 3px rgba(226, 188, 89, .12);
}

.login-card > button {
  width: 100%;
  margin-top: 4px;
  letter-spacing: .055em;
}

.error {
  min-height: 22px;
  color: var(--red);
}

.login-foot {
  margin: 12px 0 0;
  color: #718299;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  text-align: center;
}

.muted {
  color: var(--muted);
}

.portal {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  border-right: 1px solid var(--line-gold);
  background:
    linear-gradient(180deg, rgba(6, 16, 29, .99), rgba(2, 8, 16, .995)),
    var(--bg-deep);
  box-shadow: 12px 0 40px rgba(0, 0, 0, .22);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 104px;
  padding: 6px 8px 20px;
  border-bottom: 1px solid rgba(220, 177, 67, .23);
}

.brand-logo {
  width: 86px;
  height: 86px;
  flex: 0 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .5));
}

.brand strong {
  display: block;
  background: linear-gradient(#fff3bb, #d6a63d);
  background-clip: text;
  color: transparent;
  font: 900 19px/1.15 Georgia, "Times New Roman", serif;
  letter-spacing: .07em;
}

.brand small,
.user small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .08em;
}

nav {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}

nav button,
.quiet {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: #bbc6d6;
  text-align: left;
}

nav button {
  position: relative;
  padding: 12px 14px 12px 18px;
}

nav button::before {
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 0;
  width: 3px;
  border-radius: 3px;
  content: "";
  background: transparent;
}

nav button:hover,
.quiet:hover {
  border-color: rgba(224, 184, 82, .22);
  background: rgba(20, 40, 67, .62);
  color: var(--gold-bright);
}

nav button.active {
  border-color: rgba(224, 184, 82, .38);
  background: linear-gradient(90deg, rgba(31, 57, 92, .92), rgba(15, 33, 57, .55)) !important;
  color: var(--gold-bright) !important;
}

nav button.active::before {
  background: var(--gold);
  box-shadow: 0 0 12px rgba(226, 188, 89, .55);
}

.user {
  margin-top: auto;
  padding: 18px 8px 0;
  border-top: 1px solid rgba(220, 177, 67, .2);
}

.user > span {
  display: block;
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user .quiet {
  width: 100%;
  margin-top: 10px;
}

.workspace {
  min-width: 0;
  padding: 30px clamp(22px, 3vw, 46px) 50px;
}

.workspace > header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
  margin: -30px clamp(-46px, -3vw, -22px) 30px;
  padding: 19px clamp(22px, 3vw, 46px);
  border-bottom: 1px solid rgba(222, 180, 73, .38);
  background: rgba(3, 10, 19, .68);
  backdrop-filter: blur(16px);
}

.workspace > header::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, rgba(229, 189, 84, .8), transparent 56%);
}

.workspace > header .eyebrow {
  margin: 0 0 3px;
}

.workspace h2 {
  margin: 0;
  color: #f7f8fb;
  font: 800 30px/1.15 Georgia, "Times New Roman", serif;
}

.pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 7px 12px;
  border: 1px solid #315d49;
  border-radius: 999px;
  background: rgba(25, 75, 52, .15);
  color: var(--green);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .045em;
  white-space: nowrap;
}

.pill::before {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  content: "";
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 16px;
}

.card,
.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(145deg, rgba(15, 33, 56, .98), rgba(6, 17, 31, .98)),
    var(--panel);
  box-shadow:
    0 15px 35px rgba(0, 0, 0, .16),
    inset 0 1px rgba(255, 255, 255, .025);
}

.card::before,
.panel::before {
  position: absolute;
  top: 0;
  right: 14%;
  left: 0;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, rgba(234, 197, 100, .58), transparent);
}

.card {
  min-height: 118px;
  padding: 20px;
}

.panel {
  padding: 21px;
}

.card small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.card strong {
  display: block;
  margin-top: 5px;
  color: var(--gold-bright);
  font: 800 30px/1.2 Georgia, "Times New Roman", serif;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.table-wrap {
  margin-top: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(2, 9, 18, .35);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px;
  border-bottom: 1px solid rgba(38, 59, 88, .75);
  text-align: left;
  vertical-align: middle;
}

th {
  background: rgba(15, 32, 54, .82);
  color: #aebbd0;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .11em;
}

tbody tr {
  transition: background .14s ease;
}

tbody tr:hover {
  background: rgba(22, 44, 72, .42);
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .025em;
}

.online {
  color: var(--green);
}

.offline {
  color: var(--muted);
}

dialog {
  width: min(900px, calc(100% - 16px));
  max-height: 92vh;
  padding: 28px;
  overflow: auto;
  border: 1px solid var(--line-gold);
  border-radius: 18px;
  background:
    linear-gradient(145deg, #0d1d32, #06101d),
    var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 3, 8, .82);
  backdrop-filter: blur(5px);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(222, 181, 76, .22);
}

.dialog-head .eyebrow {
  margin-top: 0;
}

.dialog-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 20px;
}

.warning {
  padding: 12px 14px;
  border: 1px solid #745c29;
  border-radius: 10px;
  background: rgba(73, 51, 12, .55);
  color: #f7db8f;
}

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.receipt-grid > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(3, 10, 19, .48);
}

.secret {
  margin-top: 5px;
  padding: 9px;
  border-radius: 7px;
  background: #02070e;
  color: var(--gold-bright);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.toast {
  position: fixed;
  z-index: 50;
  top: 20px;
  right: 20px;
  max-width: min(430px, calc(100vw - 40px));
  padding: 12px 18px;
  border: 1px solid #3e7d59;
  border-radius: 10px;
  background: #143725;
  box-shadow: var(--shadow);
  transform: translateY(-170%);
  transition: transform .22s ease;
}

.toast.show {
  transform: none;
}

@media (max-width: 1050px) {
  .portal {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .brand-logo {
    width: 70px;
    height: 70px;
  }

  .brand strong {
    font-size: 16px;
  }
}

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

  aside {
    position: relative;
    z-index: 5;
    height: auto;
    min-height: 92px;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line-gold);
  }

  .brand {
    min-height: auto;
    padding: 0;
    border: 0;
  }

  .brand-logo {
    width: 62px;
    height: 62px;
  }

  nav {
    display: flex;
    margin: 0;
  }

  .user {
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
  }

  .user .quiet {
    margin: 2px 0 0;
    padding: 4px 8px;
    min-height: 30px;
  }

  .workspace > header {
    margin-top: -30px;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .login-shell {
    padding: 18px;
  }

  .login-card {
    padding: 27px 22px 24px;
  }

  .login-brand {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }

  .login-logo {
    width: 118px;
    height: 118px;
  }

  .login-product {
    margin-left: .29em;
  }

  aside {
    flex-wrap: wrap;
  }

  .brand {
    flex: 1 1 auto;
  }

  .brand div {
    display: block;
  }

  nav {
    order: 3;
    width: 100%;
  }

  nav button {
    flex: 1;
    text-align: center;
  }

  .user > span,
  .user > small {
    display: none;
  }

  .workspace {
    padding: 18px;
  }

  .workspace > header {
    align-items: flex-start;
    gap: 14px;
    margin: -18px -18px 22px;
    padding: 17px 18px;
  }

  .workspace h2 {
    font-size: 25px;
  }

  .workspace > header .pill {
    max-width: 48vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .cards,
  .form-grid,
  .receipt-grid {
    grid-template-columns: 1fr;
  }

  dialog {
    width: calc(100% - 12px);
    max-height: 96vh;
    padding: 16px;
  }

  table {
    min-width: 560px;
  }

  nav button {
    min-width: 0;
    padding: 8px 6px;
    font-size: 11px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  #receipt-dialog,
  #receipt-dialog * {
    visibility: visible;
  }

  #receipt-dialog {
    position: absolute;
    inset: 0;
    width: 100%;
    max-height: none;
    border: 0;
    color: #000;
    background: #fff;
  }
}


/* Minimal chrome polish + theme toggle */
.header-actions{display:flex;align-items:center;gap:10px}
.theme-toggle{min-width:72px}
.cache-actions{margin-top:14px;padding-top:12px;border-top:1px solid var(--line);display:grid;gap:6px}
.cache-actions .subtle{font-size:12px;color:var(--muted)}
button:not(.quiet), .portal nav button, .game-tile, .quiet{
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, background .18s ease, color .18s ease;
}
button:not(.quiet):hover{transform:var(--hover-lift)}
button:not(.quiet):active{transform:var(--press)}
.portal nav button:hover{border-color:var(--line-gold)}
.portal nav button.active{
  background:linear-gradient(135deg, color-mix(in srgb, var(--gold) 28%, transparent), transparent);
  outline:1px solid var(--line-gold);
}
.card, .panel{transition:box-shadow .2s ease, border-color .2s ease}
.card:hover, .panel:hover{box-shadow:var(--shadow)}
:root[data-theme="light"] body::before{opacity:.35}
:root[data-theme="light"] .login-shell{background:var(--bg)}
