:root {
  color-scheme: dark;
  --bg: #131617;
  --sidebar: #191e1f;
  --panel: #1c2223;
  --panel-raised: #222929;
  --line: #303839;
  --text: #ecf0ed;
  --muted: #9ba6a2;
  --green: #89d5a2;
  --green-strong: #a2e5b7;
  --coral: #e9a18b;
  font-family: Inter, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { color: inherit; }
.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; }

.auth-shell { display: grid; grid-template-columns: minmax(280px, 0.85fr) minmax(340px, 440px); align-items: center; gap: clamp(50px, 9vw, 150px); min-height: 100vh; max-width: 1100px; margin: 0 auto; padding: 48px; }
.auth-brand { max-width: 420px; }
.brand-mark { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 14px; background: var(--green); color: #132019; font-weight: 800; font-size: 25px; }
.auth-brand .brand-mark { margin-bottom: 40px; }
.eyebrow { color: var(--green); font-size: 10px; font-weight: 750; letter-spacing: 1.3px; }
.auth-brand h1 { margin: 8px 0 12px; font-size: 48px; line-height: 1; font-weight: 680; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 15px; }
.auth-panel { padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 25px; padding: 4px; border-radius: 6px; background: #15191a; }
.tab { min-height: 37px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.tab.active { background: #2a3232; color: var(--text); }
.form-stack { display: grid; gap: 17px; }
.form-stack label, .token-result label { display: grid; gap: 7px; color: #c5ceca; font-size: 12px; font-weight: 600; }
input { width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid #374140; border-radius: 5px; outline: none; background: #151a1a; color: var(--text); }
input:focus { border-color: var(--green); box-shadow: 0 0 0 2px #89d5a222; }
.primary, .secondary { min-height: 40px; padding: 0 15px; border: 1px solid transparent; border-radius: 5px; font-size: 13px; font-weight: 650; cursor: pointer; }
.primary { background: var(--green); color: #152019; }
.primary:hover { background: var(--green-strong); }
.primary:disabled, .secondary:disabled, .send-button:disabled { opacity: 0.6; cursor: wait; }
.secondary { border-color: #46504e; background: #252c2c; color: var(--text); }
.secondary:hover { border-color: var(--green); }
.status { min-height: 18px; color: var(--coral); font-size: 12px; }

.app-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.sidebar { display: flex; flex-direction: column; min-height: 100vh; padding: 23px 14px 15px; border-right: 1px solid var(--line); background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 7px 40px; color: var(--text); font-size: 14px; text-decoration: none; }
.brand b { color: var(--muted); font-weight: 500; }
.brand-mark.small { width: 32px; height: 32px; border-radius: 8px; font-size: 15px; }
.side-label { margin: 0 10px 10px; color: #77827e; font-size: 9px; font-weight: 750; letter-spacing: 1.2px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 38px; padding: 0 10px; border: 0; border-radius: 5px; background: transparent; color: #aeb8b4; text-align: left; cursor: pointer; font-size: 13px; }
.nav-item:hover { background: #232929; color: var(--text); }
.nav-item.active { background: #293231; color: var(--green-strong); }
.nav-icon { display: grid; place-items: center; width: 18px; font-size: 16px; color: inherit; }
.sidebar-bottom { display: grid; gap: 16px; margin-top: auto; padding: 13px 8px 3px; }
.connection { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.online-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #70c98b; box-shadow: 0 0 0 3px #70c98b18; }
.quiet-button { justify-self: start; padding: 0; border: 0; background: none; color: #9ba6a2; font-size: 12px; cursor: pointer; }
.quiet-button:hover { color: var(--text); }

.main-area { display: flex; flex-direction: column; width: 100%; min-width: 0; height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 84px; padding: 15px clamp(22px, 4vw, 54px); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 3px 0 0; font-size: 20px; font-weight: 650; }
.user-chip { display: flex; align-items: center; gap: 9px; color: #cbd3cf; font-size: 12px; }
.avatar { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; background: #34403b; color: var(--green-strong); font-size: 11px; font-weight: 700; }
.role-badge, .message-admin-badge { padding: 3px 5px; border: 1px solid #785a49; border-radius: 3px; color: #e8b594; font-size: 8px; font-weight: 750; letter-spacing: 0.5px; }
.view { min-height: 0; flex: 1; }
.chat-view { display: flex; flex-direction: column; max-width: 1120px; width: 100%; margin: 0 auto; padding: 0 clamp(20px, 5vw, 68px) 22px; }
.chat-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; min-height: 88px; border-bottom: 1px solid #293130; }
.chat-heading h2 { margin: 0 0 4px; font-size: 15px; font-weight: 650; }
.chat-heading p, .section-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.member-count { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.messages { display: flex; flex: 1; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; padding: 18px 4px 18px 0; scrollbar-color: #394342 transparent; }
.message-row { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 11px; padding: 10px 8px; border-radius: 6px; }
.message-row:hover { background: #1b2021; }
.message-avatar { display: grid; place-items: center; width: 29px; height: 29px; margin-top: 2px; border-radius: 50%; background: #2e3c37; color: #b3dfc0; font-size: 10px; font-weight: 700; }
.message-avatar.admin-avatar { background: #49352e; color: #efbd9a; }
.message-content { min-width: 0; }
.message-meta { display: flex; align-items: baseline; gap: 8px; min-height: 17px; }
.message-meta strong { color: #e2e8e4; font-size: 12px; font-weight: 650; overflow-wrap: anywhere; }
.message-meta time { color: #74807c; font-size: 10px; }
.message-content p { margin: 4px 0 0; color: #c4ccc8; font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 5px 6px 5px 12px; border: 1px solid #3b4644; border-radius: 6px; background: #191e1f; }
.composer:focus-within { border-color: #799c83; }
.composer input { flex: 1; min-width: 0; min-height: 34px; padding: 0; border: 0; background: transparent; box-shadow: none; }
.key-hint { color: #697571; font-size: 10px; white-space: nowrap; }
.send-button { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border: 0; border-radius: 5px; background: var(--green); color: #132019; font-size: 20px; line-height: 1; cursor: pointer; }

.profile-view, .admin-view { max-width: 1050px; width: 100%; margin: 0 auto; padding: 38px clamp(20px, 5vw, 68px); overflow-y: auto; }
.section-heading { margin-bottom: 24px; }
.section-heading h2 { margin: 5px 0 6px; font-size: 22px; font-weight: 650; }
.profile-grid { display: grid; grid-template-columns: minmax(250px, 0.8fr) minmax(330px, 1.2fr); gap: 14px; }
.detail-panel { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.panel-heading { display: flex; align-items: center; gap: 12px; }
.panel-heading h3 { margin: 0 0 4px; font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); font-size: 11px; }
.avatar.large, .token-icon { width: 42px; height: 42px; flex: 0 0 42px; font-size: 15px; }
.token-icon { display: grid; place-items: center; border-radius: 8px; background: #303a35; color: var(--green-strong); font-size: 21px; }
.detail-panel dl { display: grid; gap: 0; margin: 23px 0 0; }
.detail-panel dl div { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid #303738; }
.detail-panel dt, .detail-panel dd { margin: 0; font-size: 11px; }
.detail-panel dt { color: var(--muted); }
.detail-panel dd { color: #dbe2de; }
.game-token-panel > p { max-width: 460px; margin: 21px 0 17px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.token-result { display: grid; gap: 8px; margin-top: 17px; padding-top: 16px; border-top: 1px solid #303738; }
.token-result small { color: var(--muted); font-size: 10px; }
.token-copy { display: flex; align-items: center; gap: 7px; }
.token-copy input { min-width: 0; flex: 1; font-family: "IBM Plex Mono", Consolas, monospace; font-size: 11px; }
.token-copy button { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 40px; border: 1px solid #3a4543; border-radius: 5px; background: #282f2f; color: var(--text); font-size: 17px; cursor: pointer; }
.token-copy button:hover { border-color: var(--green); }
.extension-space { margin-top: 28px; padding: 18px 0; border-top: 1px solid var(--line); }
.extension-space p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.admin-toolbar { display: flex; align-items: center; gap: 14px; margin: 0 0 15px; }
.players-heading { margin-top: 35px; padding: 17px 0 13px; border-top: 1px solid var(--line); }
.players-heading h3 { margin: 0 0 4px; font-size: 14px; font-weight: 650; }
.players-heading p { margin: 0; color: var(--muted); font-size: 11px; }
.role-action { padding: 6px 9px; border: 1px solid #46504e; border-radius: 4px; background: #252c2c; color: #c8d1cd; font-size: 10px; cursor: pointer; white-space: nowrap; }
.role-action:hover:not(:disabled) { border-color: var(--green); color: var(--green-strong); }
.role-action:disabled { opacity: .5; cursor: default; }
.new-key { display: grid; gap: 8px; max-width: 530px; margin-bottom: 18px; padding: 14px; border: 1px solid #526957; border-radius: 6px; background: #1c2921; color: #c5d9ca; font-size: 11px; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { height: 44px; padding: 0 12px; border-bottom: 1px solid #293130; font-size: 11px; }
th { color: #8d9994; font-weight: 600; }
td { color: #c5ceca; }
.empty-cell { height: 75px; color: var(--muted); text-align: center; }
.state-badge { display: inline-block; padding: 4px 7px; border-radius: 4px; font-size: 10px; }
.state-badge.available { background: #25372d; color: #9cdbaf; }
.state-badge.used { background: #333a39; color: #a8b2ae; }
.toast { position: fixed; right: 22px; bottom: 20px; z-index: 5; padding: 11px 15px; border: 1px solid #4d5c55; border-radius: 5px; background: #252e2b; color: #d9e5de; font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(6px); transition: opacity 140ms ease, transform 140ms ease; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 760px) {
  .auth-shell { grid-template-columns: 1fr; gap: 32px; max-width: 500px; padding: 28px 20px; }
  .auth-brand .brand-mark { margin-bottom: 22px; }
  .auth-brand h1 { font-size: 38px; }
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { position: fixed; inset: auto 0 0; z-index: 4; display: block; min-height: 0; height: 61px; padding: 0 12px; border-top: 1px solid var(--line); border-right: 0; background: #191e1f; }
  .brand, .side-label, .sidebar-bottom { display: none; }
  .sidebar nav { display: flex; justify-content: space-around; height: 100%; }
  .nav-item { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-width: 84px; min-height: 0; padding: 5px 7px; font-size: 9px; text-align: center; }
  .nav-icon { height: 21px; font-size: 16px; }
  .main-area { height: calc(100vh - 61px); }
  .topbar { min-height: 72px; padding: 12px 17px; }
  .topbar h1 { font-size: 18px; }
  .chat-view { padding: 0 12px 12px; }
  .chat-heading { min-height: 75px; }
  .chat-heading p { max-width: 230px; line-height: 1.4; }
  .member-count { font-size: 0; }
  .member-count .online-dot { margin-right: 3px; }
  .messages { padding-top: 10px; }
  .composer { gap: 7px; }
  .key-hint { display: none; }
  .profile-view, .admin-view { padding: 26px 16px; }
  .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
  .auth-panel { padding: 19px; }
  .user-chip { gap: 6px; font-size: 10px; }
  .role-badge { font-size: 7px; }
  .chat-heading p { max-width: 190px; }
  .message-row { grid-template-columns: 28px minmax(0, 1fr); gap: 8px; padding-inline: 3px; }
}
