:root {
  color-scheme: dark;
  --bg: #101f21;
  --panel: #132629;
  --line: #3e5b56;
  --text: #f4efe4;
  --muted: #bccbc3;
  --gold: #f6cb86;
  --ink: #272316;
  --felt-background:
    repeating-linear-gradient(37deg, #dbfff405 0 1px, transparent 1px 4px),
    repeating-linear-gradient(137deg, #081c1d18 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 48% 39%, #265251, #183838 59%, #101f21);
  font: 16px/1.47 system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }

body { margin: 0; min-height: 100vh; background: var(--felt-background); }
body:not(.game-screen) #app {
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button, .button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }
h1, h2 { font-family: Georgia, serif; font-weight: normal; line-height: 1.09; }
h1 { font-size: clamp(2.45rem, 6vw, 4.6rem); letter-spacing: -.045em; overflow-wrap: anywhere; }
h2 { font-size: clamp(1.4rem, 2.6vw, 1.8rem); letter-spacing: -.018em; }
p { overflow-wrap: anywhere; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.loading { padding: 3rem; }
.muted { color: var(--muted); }

button, .button {
  display: inline-flex;
  min-height: 2.75rem;
  min-width: 0;
  align-items: center;
  justify-content: center;
  padding: .6rem .95rem;
  border: 1px solid transparent;
  border-radius: .58rem;
  background: transparent;
  color: var(--text);
  font-weight: 650;
  text-align: center;
}

button:disabled { cursor: default; opacity: .55; }
.primary { background: var(--gold); color: var(--ink); }
.primary:hover:not(:disabled) { background: #ffdb9f; }
.secondary { border-color: #6a9186; background: #203d37; }
.secondary:hover:not(:disabled) { background: #2c4d43; }
.quiet { color: var(--muted); padding-inline: .45rem; }
.quiet:hover { color: var(--text); }

label, legend { font-size: .9rem; font-weight: 650; }
label { display: grid; min-width: 0; gap: .4rem; }
fieldset { min-width: 0; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 2.9rem;
  padding: .63rem .75rem;
  border: 1px solid #5b7871;
  border-radius: .52rem;
  background: #101f22;
  color: var(--text);
}

input::placeholder { color: #a8bbb3; opacity: 1; }
input:disabled { color: #becdc5; -webkit-text-fill-color: #becdc5; opacity: 1; background: #1e3234; }
form { display: grid; gap: 1rem; }
form > .primary { justify-self: start; }
.form-error { color: #ffc3b9; }

.brand {
  display: flex;
  align-items: center;
  gap: .58rem;
  min-width: 0;
  color: #f4ecdc;
  font: 1.38rem Georgia, serif;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.27rem;
  height: 2.27rem;
  border: 1px solid #8c7049;
  border-radius: .52rem;
  color: var(--gold);
  background: #302b20;
  font-size: 1.46rem;
}

body:has(.login) {
  --text: #202730;
  --muted: #515c68;
  --gold: #486783;
  color-scheme: light;
  background: #f2f3f5;
  color: var(--text);
}

.login {
  display: grid;
  place-items: center;
  min-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: clamp(1rem, 4vw, 2rem);
}

.login-content {
  width: min(100%, 25rem);
  padding: clamp(1.15rem, 5vw, 1.85rem);
  border: 1px solid #d5d9df;
  border-radius: .65rem;
  background: #fff;
}

.login-name { color: var(--muted); font-size: .9rem; font-weight: 650; }
.login h1 {
  margin: .6rem 0 .5rem;
  font: 680 clamp(1.7rem, 4vw, 2rem)/1.13 system-ui, sans-serif;
  letter-spacing: -.025em;
}
.login form { margin-top: 1.3rem; gap: .85rem; }
.login input { border-color: #9ba4ae; background: #fff; }
.login .primary { justify-self: stretch; margin-top: .15rem; background: #34495d; color: #fff; }
.login .primary:hover:not(:disabled) { background: #27394b; }
.login .form-error { color: #a82e2e; }
.login-rules { margin-top: .55rem; padding-inline: 0; font-size: .9rem; text-decoration: underline; }
body:has(.login) #rules { border-color: #9ba4ae; background: #fff; }
body:has(.login) #rules ol { color: #35414d; }

.topbar { background: #102123d9; border-bottom: 1px solid #8eac9e38; }
.topbar-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: .65rem 1.4rem;
  width: min(100%, 82rem);
  margin: auto;
  padding: .67rem clamp(.85rem, 3vw, 2.4rem);
}

.home-link { justify-self: start; min-width: 0; }
.site-nav, .profile { display: flex; align-items: center; gap: .32rem; }
.site-nav > a, .site-nav button, .profile a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.65rem;
  padding-inline: .75rem;
  border-radius: .52rem;
  color: var(--muted);
  font-weight: 650;
}
.site-nav > a[aria-current], .profile a[aria-current] { color: #ffe5b2; background: #2d413a; }
.site-nav > a:hover, .site-nav button:hover, .profile a:hover { color: var(--text); background: #2d413a; }
.profile { justify-content: end; min-width: 0; }
.profile a { min-width: 0; gap: .45rem; }
.profile-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-compact { display: none; }
.profile button { flex: none; }
.identity-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.45rem;
  height: 2.45rem;
  border: 1px solid #64867a;
  border-radius: 50%;
  background: linear-gradient(150deg, #385c55, #26423d);
  color: #e0eddb;
  font: bold 1.2rem Georgia, serif;
}
.profile .identity-mark { width: 1.65rem; height: 1.65rem; font-size: .92rem; }

.workspace {
  width: min(100%, 82rem);
  margin: auto;
  padding: clamp(1.2rem, 4vw, 3.6rem) clamp(.85rem, 3vw, 2.4rem) 3rem;
}

.page-intro { margin-bottom: clamp(1.2rem, 3vw, 2.55rem); }
.page-intro p { margin-top: .55rem; color: #d3e0d6; }
.profile-intro { display: flex; align-items: center; gap: clamp(.75rem, 3vw, 1.55rem); }
.profile-intro > div { min-width: 0; }
.profile-intro .identity-mark { width: clamp(3rem, 7vw, 5.1rem); height: auto; aspect-ratio: 1; font-size: clamp(1.35rem, 3.4vw, 2.7rem); }

.lobby-grid { display: grid; grid-template-columns: minmax(0, 1.56fr) minmax(17rem, 1fr); gap: clamp(.8rem, 2vw, 1.45rem); align-items: start; }
.profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel {
  min-width: 0;
  padding: clamp(.9rem, 2.5vw, 1.5rem);
  border: 1px solid #64877d75;
  border-radius: 1rem;
  background: linear-gradient(160deg, #1b3334, #132629 84%);
  box-shadow: 0 10px 28px #091a1a28;
}

.panel h2 { margin-bottom: 1.05rem; }
.row-meta { color: var(--muted); font-size: .875rem; }
.row-title { font-weight: 700; overflow-wrap: anywhere; }

.table-list, .row-list { display: grid; gap: .55rem; list-style: none; padding: 0; margin: 0; }
.table-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: .8rem;
  min-height: 4.25rem;
  padding: .62rem .7rem;
  border: 1px solid #54736c95;
  border-radius: .68rem;
  background: #162c2e;
}

.table-row:hover { border-color: #b99b6e; background: #233d39; }
.table-emblem {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.75rem;
  border: 1px solid #aa8758;
  border-radius: .35rem;
  color: #ffdfaa;
  background: #49392c;
  font-size: 1.3rem;
}

.table-info, .table-row-side { display: grid; gap: .18rem; min-width: 0; }
.table-info strong { overflow-wrap: anywhere; }
.table-row-side { justify-items: end; }
.table-row-action { color: #ffda9f; font-size: .86rem; font-weight: 650; white-space: nowrap; }
.info-chip {
  display: inline-block;
  padding: .12rem .45rem;
  border: 1px solid #658079;
  border-radius: 99px;
  color: #e1eee4;
  font-size: .76rem;
  line-height: 1.3;
  white-space: nowrap;
}
.info-chip.live { background: #26483c; border-color: #709b84; color: #dcf2e0; }
.info-chip.inactive { background: #43302c; border-color: #a87365; color: #ffe0d2; }

.empty {
  display: grid;
  gap: .45rem;
  place-items: center;
  padding: clamp(1.8rem, 5vw, 3rem) .65rem;
  border: 1px dashed #81a59a95;
  border-radius: .68rem;
  text-align: center;
  color: var(--muted);
}
.empty span { color: var(--gold); font-size: 2.6rem; line-height: 1; }
.active-table-panel { border-color: #b2966aa1; }
.current-table-link { margin-top: 1rem; }

.deck-options { padding: 0; margin: 0; border: 0; }
.deck-options legend { padding: 0; margin-bottom: .42rem; }
.deck-options > div { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
.deck-option { position: relative; display: block; cursor: pointer; }
.deck-option input {
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  min-height: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
}
.deck-option > span {
  display: grid;
  align-content: center;
  gap: .14rem;
  height: 100%;
  min-height: 3.9rem;
  padding: .55rem .65rem;
  border: 1px solid #5e7d74;
  border-radius: .58rem;
  background: #14282a;
}
.deck-option small { color: #c1d0c7; font-size: .79rem; font-weight: 500; }
.deck-option input:checked + span { border-color: var(--gold); background: #3c3b29; color: #ffe9bd; }
.deck-option input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .6rem .75rem;
  align-items: start;
  min-width: 0;
  padding: .78rem;
  border: 1px solid #54736c95;
  border-radius: .72rem;
  background: #162c2e;
}
.account-identity { display: flex; align-items: start; gap: .62rem; min-width: 0; }
.account-identity > div { min-width: 0; overflow-wrap: anywhere; }
.account-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .14rem .4rem; margin-block: .13rem .35rem; }
.account-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: .4rem; }
.account-actions button { padding-inline: .52rem; font-size: .8rem; }
.account-edit { grid-column: 1 / -1; width: 100%; border-top: 1px solid #62807961; }
.account-edit summary {
  min-height: 2.7rem;
  padding-block: .6rem .35rem;
  cursor: pointer;
  color: #ffdb9f;
  font-size: .9rem;
  font-weight: 650;
}
.account-edit form { margin-top: .38rem; padding: .75rem; border-radius: .6rem; background: #142324; }
.account-danger { grid-column: 1 / -1; border-color: #93685d; }
.danger { border-color: #b27a6d; background: #442e2b; color: #ffe0d6; }
.danger:hover:not(:disabled) { background: #603d35; }

#notice {
  position: fixed;
  z-index: 2;
  right: max(.85rem, env(safe-area-inset-right));
  bottom: max(.85rem, env(safe-area-inset-bottom));
  max-width: min(26rem, calc(100% - 1.7rem));
  padding: .8rem 1rem;
  border: 1px solid #95b7a9;
  border-radius: .62rem;
  background: #233f38;
  box-shadow: 0 8px 24px #0008;
}
#notice.error { background: #532c2a; border-color: #d68d82; }
dialog {
  width: min(36rem, calc(100% - 1.5rem));
  max-height: 82dvh;
  padding: clamp(.85rem, 3vw, 1.45rem);
  overflow: auto;
  border-radius: .88rem;
  border: 1px solid #749a8c;
  background: #182e30;
  color: var(--text);
  box-shadow: 0 20px 55px #091516b0;
}
dialog::backdrop { background: #071217c4; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: .55rem; }
.account-dialog { width: min(29rem, calc(100% - 1.5rem)); }
.account-dialog > p { margin-top: .75rem; }
.account-dialog > form, .account-dialog > .dialog-actions { margin-top: 1rem; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: .45rem; }
#rules ol { margin: .75rem 0 0; padding-left: 1.65rem; color: #dbe8df; }
#rules li { padding-left: .2rem; }
#rules li::marker { color: var(--gold); }
#rules li + li { margin-top: .63rem; }

@media (max-width: 900px) {
  .account-row { grid-template-columns: minmax(0, 1fr); }
  .account-actions { justify-content: start; }
}

@media (max-width: 740px) {
  .lobby-grid, .profile-grid { grid-template-columns: minmax(0, 1fr); }
  .active-table-panel { grid-row: 1; }
  .topbar-inner { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: .2rem .4rem; padding-top: .5rem; }
  .site-nav { grid-row: 2; grid-column: 1 / -1; }
  .profile { grid-row: 1; grid-column: 2; }
  .profile a { padding-inline: .38rem; }
  .brand { font-size: 1.15rem; gap: .4rem; }
  .brand-mark { width: 1.85rem; height: 1.85rem; font-size: 1.2rem; }
  input, select { font-size: 1rem; }
}

@media (max-width: 430px) {
  .topbar-inner { padding-inline: .68rem; }
  .profile a, .profile button { font-size: .85rem; }
  .profile .identity-mark, .profile-name { display: none; }
  .profile-compact { display: inline; }
  .site-nav > a, .site-nav button { padding-inline: .58rem; font-size: .9rem; }
  .table-row { column-gap: .48rem; padding: .53rem .43rem; }
  .table-emblem { width: 1.8rem; height: 2.25rem; font-size: 1.05rem; }
  .table-row-side .info-chip { font-size: .69rem; padding-inline: .32rem; }
  .table-info .row-meta { font-size: .78rem; }
  .table-row-action { font-size: .79rem; }
  .panel form > .primary, .current-table-link { width: 100%; }
}

@media (max-width: 345px) {
  .brand { font-size: 1.02rem; gap: .25rem; }
  .brand-mark { width: 1.65rem; height: 1.65rem; }
  .profile { gap: .1rem; }
  .profile a, .profile button { padding-inline: .25rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
