:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3345;
  --text: #e8eaef;
  --muted: #8b92a8;
  --accent: #6c8cff;
  --accent-hover: #8aa3ff;
  --danger: #f07178;
  --success: #7fd99a;
  --radius: 8px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

button:hover {
  background: var(--accent-hover);
}

button.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: var(--border);
}

button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

button.danger:hover {
  background: rgba(240, 113, 120, 0.12);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.hidden {
  display: none !important;
}

/* ---- login ---- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.login-card p {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  margin-bottom: 1rem;
}

.error-banner {
  background: rgba(240, 113, 120, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* ---- app shell ---- */
#app-screen {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.1rem;
}

.game-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -0.5rem;
}

.game-row {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
}

.game-row .game-item {
  flex: 1;
  min-width: 0;
  width: auto;
  margin-bottom: 0;
}

.game-copy-id {
  flex-shrink: 0;
  align-self: center;
  padding: 0.35rem 0.45rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.game-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.25rem;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.game-item:hover {
  background: var(--surface2);
}

.game-item.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--accent);
}

.game-item small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
}

.main {
  padding: 1.5rem;
  overflow-y: auto;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.main-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.45rem 0.9rem;
}

.tab.active {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.panel h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.form-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.form-row .field {
  flex: 1;
  min-width: 140px;
  margin-bottom: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td.mono {
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.82rem;
}

.key-reveal {
  background: rgba(127, 217, 154, 0.12);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.key-reveal code {
  font-family: ui-monospace, monospace;
  word-break: break-all;
  color: var(--success);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--surface2);
  color: var(--muted);
}

.badge.revoked {
  background: rgba(240, 113, 120, 0.15);
  color: var(--danger);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.pagination-info {
  color: var(--muted);
  font-size: 0.9rem;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem;
}

.sql-console-textarea {
  width: 100%;
  min-height: 200px;
  resize: vertical;
  font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

.sql-console-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
}

.sql-console-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.sql-console-error {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--danger);
  background: rgba(240, 113, 120, 0.12);
  color: var(--danger);
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.sql-console-results {
  margin-top: 1rem;
  overflow-x: auto;
  max-height: 50vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.sql-console-results table {
  margin: 0;
}

.sql-console-results th {
  position: sticky;
  top: 0;
  background: var(--surface2);
  z-index: 1;
}

.properties-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 768px) {
  #app-screen {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
