/* Timapple — component primitives. */

/* button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 36px;
  min-height: 36px;
  padding: 0 var(--s-4);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 30%);
  transition: background var(--motion-fast) var(--ease),
              transform var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}
.btn:hover {
  background: var(--surface-3);
  border-color: var(--surface-4);
  color: var(--ink);
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}
.btn--sm {
  height: 32px;
  min-height: 32px;
  padding: 0 var(--s-3);
  font-size: var(--fs-xs);
}
.btn--lg {
  height: 44px;
  min-height: 44px;
  padding: 0 var(--s-5);
  font-size: var(--fs-md);
}
.btn--block { width: 100%; }

.btn--primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.btn--primary:hover {
  background: var(--sage-strong);
  border-color: var(--sage-strong);
  color: var(--ink-on-accent);
}

.btn--ghost {
  background: var(--surface);
  border-color: color-mix(in oklch, var(--surface-3), transparent 25%);
  color: var(--ink-soft);
}
.btn--ghost:hover {
  background: var(--surface-2);
  border-color: var(--surface-4);
  color: var(--ink);
}

.btn--danger {
  background: var(--terracotta);
  color: var(--ink-on-accent);
  border-color: var(--terracotta);
}
.btn--danger:hover { background: var(--terracotta-strong); border-color: var(--terracotta-strong); }

.btn--accent {
  background: var(--sage-soft);
  color: var(--sage-strong);
  border-color: color-mix(in oklch, var(--sage), transparent 60%);
}
.btn--accent:hover { background: var(--sage); color: var(--ink-on-accent); border-color: var(--sage); }

.btn--icon {
  width: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  color: var(--ink-soft);
}
.btn--icon:hover { color: var(--ink); }
.btn--icon.btn--sm {
  width: 32px;
  min-width: 32px;
}

.btn-group {
  display: inline-flex;
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.btn-group .btn {
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--surface-3);
}
.btn-group .btn:last-child { border-right: 0; }

/* Editor */
.editor {
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.editor__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1);
  padding: var(--s-2);
  background: var(--surface-2);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 30%);
}
.editor__toolbar button {
  min-width: 34px;
  height: 32px;
  padding: 0 var(--s-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1;
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 20%);
  box-shadow: 0 1px 0 color-mix(in oklch, var(--surface-4), transparent 45%);
  cursor: pointer;
}
.editor__toolbar button b,
.editor__toolbar button i { font-size: var(--fs-md); }
.editor__toolbar button code {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  background: transparent;
  padding: 0;
}
.editor__toolbar button:hover {
  background: var(--surface-3);
  border-color: var(--surface-4);
  color: var(--ink);
}
.editor__toolbar button:active {
  transform: translateY(1px);
  background: var(--sage-soft);
  color: var(--sage-strong);
  border-color: var(--sage);
  box-shadow: none;
}
.editor__sep {
  width: 1px;
  height: 22px;
  background: var(--surface-3);
  margin: 0 var(--s-1);
}
.editor__body {
  min-height: 240px;
  padding: var(--s-4) var(--s-5);
  outline: none;
}
.editor__body:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-faint);
}

/* card */
.card {
  background: var(--surface);
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 50%);
  border-radius: var(--radius-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.card--inset { background: var(--surface-2); }
.card--flat { box-shadow: none; background: var(--surface); }
.card__title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: var(--s-1);
}
.card__sub {
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  margin-bottom: var(--s-4);
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.card__body { font-size: var(--fs-sm); }

/* input */
.input, .textarea, .select {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 var(--s-3);
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--surface-3);
  color: var(--ink);
  font-size: var(--fs-sm);
  transition: border-color var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease);
}
.textarea {
  height: auto;
  min-height: 80px;
  padding: var(--s-3);
  resize: vertical;
  line-height: var(--lh-body);
  font-family: var(--font-sans);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%23736b62' d='M3 5l3 3 3-3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  padding-right: var(--s-8);
}
.input:focus, .textarea:focus, .select:focus {
  outline: 0;
  border-color: var(--sage-strong);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--sage), transparent 70%);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.field__label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field__hint {
  font-size: var(--fs-xs);
  color: var(--ink-faint);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-sm);
  cursor: pointer;
  user-select: none;
}
.checkbox input { accent-color: var(--sage-strong); width: 16px; height: 16px; }

/* badge — soft tinted bg with high-contrast charcoal text */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  height: 20px;
  padding: 0 var(--s-2);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge--ok     { background: var(--sage-soft);       color: oklch(28% 0.10 145); }
.badge--warn   { background: var(--ochre-soft);      color: oklch(30% 0.10 80); }
.badge--danger { background: var(--terracotta-soft); color: oklch(30% 0.12 35); }
.badge--info   { background: var(--slate-blue-soft); color: oklch(28% 0.08 250); }
.badge--rose   { background: var(--rose-soft);       color: oklch(30% 0.10 15); }
@media (prefers-color-scheme: dark) {
  .badge--ok     { color: oklch(88% 0.06 145); }
  .badge--warn   { color: oklch(88% 0.07 80); }
  .badge--danger { color: oklch(88% 0.07 35); }
  .badge--info   { color: oklch(88% 0.05 250); }
  .badge--rose   { color: oklch(88% 0.06 15); }
}

/* table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--surface-3);
  z-index: 1;
}
.table tbody td {
  padding: var(--s-3);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 60%);
  vertical-align: top;
}
.table tbody tr:hover td { background: color-mix(in oklch, var(--sage-soft), transparent 60%); }
.table--zebra tbody tr:nth-child(even) td {
  background: color-mix(in oklch, var(--surface-2), transparent 50%);
}
.table--compact tbody td { padding: var(--s-2) var(--s-3); }

/* admin */
.admin-tabs {
  margin-bottom: var(--s-5);
}
.admin-security {
  display: grid;
  gap: var(--s-5);
}
.admin-security__top {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: var(--s-4);
  align-items: start;
}
.admin-security__panel {
  min-width: 0;
  overflow: hidden;
}
.admin-security__events {
  min-width: 0;
}
.admin-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-4);
}
.admin-section-header--compact {
  align-items: center;
}
.admin-section-header .card__sub {
  margin-bottom: 0;
}
.security-view-switch {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
}
.admin-filter-grid {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(150px, 0.8fr) minmax(150px, 0.8fr) minmax(220px, 1.35fr) minmax(110px, 0.6fr) minmax(96px, 0.5fr);
  gap: var(--s-3);
  align-items: end;
  padding: var(--s-4);
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 45%);
  border-radius: var(--radius-md);
  background: color-mix(in oklch, var(--surface-2), transparent 35%);
}
.admin-filter-grid--geo {
  grid-template-columns: minmax(150px, 0.8fr) minmax(110px, 0.55fr) minmax(150px, 0.8fr) minmax(150px, 0.75fr) minmax(150px, 0.75fr) minmax(220px, 1.2fr);
}
.admin-filter-field--wide {
  grid-column: span 2;
}
.admin-filter-field--limit {
  max-width: 110px;
}
.admin-filter-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  justify-content: flex-end;
}
.admin-inline-form {
  display: grid;
  grid-template-columns: minmax(140px, 170px) minmax(160px, 1fr) auto;
  gap: var(--s-2);
  align-items: center;
  min-width: min(100%, 460px);
}
.admin-status-line {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.admin-jail-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.security-ban-list {
  display: grid;
  gap: var(--s-2);
  max-height: 260px;
  overflow: auto;
  padding-right: var(--s-1);
}
.security-ban-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto auto;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2);
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 55%);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.security-ban-row__ip {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-empty-inline {
  padding: var(--s-4);
  border: 1px dashed color-mix(in oklch, var(--surface-3), transparent 25%);
  border-radius: var(--radius-md);
  color: var(--ink-soft);
  font-size: var(--fs-sm);
  text-align: center;
}
.admin-results {
  min-width: 0;
}
.admin-table-wrap {
  width: 100%;
  max-height: min(68vh, 720px);
  overflow: auto;
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 55%);
  border-radius: var(--radius-md);
}
.admin-table-wrap--short {
  max-height: 300px;
}
.admin-table-wrap .table {
  min-width: 920px;
}
@media (max-width: 1120px) {
  .admin-security__top {
    grid-template-columns: 1fr;
  }
  .admin-filter-grid,
  .admin-filter-grid--geo {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 760px) {
  .admin-section-header,
  .admin-section-header--compact {
    flex-direction: column;
    align-items: stretch;
  }
  .security-view-switch,
  .admin-status-line {
    justify-content: flex-start;
  }
  .admin-filter-grid,
  .admin-filter-grid--geo,
  .admin-inline-form {
    grid-template-columns: 1fr;
  }
  .admin-filter-field--wide {
    grid-column: span 1;
  }
  .admin-filter-field--limit {
    max-width: none;
  }
  .admin-filter-actions {
    justify-content: flex-start;
  }
}

/* tabs */
.tabs {
  display: flex;
  gap: var(--s-1);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 60%);
  margin-bottom: var(--s-5);
  overflow-x: auto;
}
.tab {
  padding: var(--s-2) var(--s-4);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--motion-fast) var(--ease),
              border-color var(--motion-fast) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--sage-strong); border-bottom-color: var(--sage-strong); }

/* modal (uses <dialog>) */
dialog.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(92vw, 560px);
  width: 100%;
  margin: auto;
}
dialog.modal::backdrop {
  background: oklch(20% 0.01 60 / 0.5);
  backdrop-filter: blur(4px);
}
.modal__panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--surface-3);
}
dialog.app-modal .modal__panel {
  max-height: min(92vh, calc(100dvh - var(--s-8)));
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 50%);
  flex: 0 0 auto;
}
.modal__title {
  font-size: var(--fs-lg);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal__body {
  padding: var(--s-5);
  min-height: 0;
}
dialog.app-modal .modal__body {
  flex: 1 1 auto;
  overflow-y: auto;
}
dialog.app-modal.app-modal--fullscreen {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
}
dialog.app-modal.app-modal--fullscreen::backdrop {
  background: oklch(8% 0.01 60 / 0.82);
}
.game-modal__panel {
  width: 100vw;
  height: 100dvh;
  background: var(--bg);
  display: grid;
  grid-template-rows: 48px 1fr;
  overflow: hidden;
}
.game-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 0 var(--s-4);
  background: var(--surface);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 45%);
}
.game-modal__title {
  font-size: var(--fs-sm);
  font-weight: 650;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-modal__body {
  min-height: 0;
  overflow: hidden;
  background: oklch(10% 0.012 70);
}
.game-modal__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}
.game-chess-surface {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 280px;
  gap: var(--s-4);
  padding: var(--s-4);
  overflow: auto;
}
.game-chess-board-card {
  display: grid;
  place-items: center;
  min-height: 0;
}
.game-chess-side {
  min-width: 0;
}
@media (max-width: 780px) {
  .game-modal__panel {
    grid-template-rows: 44px 1fr;
  }
  .game-chess-surface {
    grid-template-columns: 1fr;
    padding: var(--s-3);
  }
  .game-chess-side {
    display: none;
  }
}
.modal__footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  background: var(--surface-2);
  border-top: 1px solid color-mix(in oklch, var(--surface-3), transparent 50%);
  flex: 0 0 auto;
}
.modal__footer .btn {
  height: 36px;
  min-height: 36px;
  padding: 0 var(--s-4);
  font-size: var(--fs-sm);
}
.modal__footer .btn--danger:first-child {
  margin-right: auto;
}

/* empty state */
.empty {
  text-align: center;
  padding: var(--s-12) var(--s-6);
  color: var(--ink-soft);
}
.empty h3 { font-size: var(--fs-lg); margin-bottom: var(--s-1); color: var(--ink); }
.empty p { font-size: var(--fs-sm); }

/* progress */
.progress {
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sage), var(--sage-strong));
  transition: width var(--motion) var(--ease);
}

/* divider */
.divider {
  height: 1px;
  background: color-mix(in oklch, var(--surface-3), transparent 60%);
  margin: var(--s-4) 0;
  border: 0;
}

/* kbd */
kbd {
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.8em;
  box-shadow: 0 1px 0 var(--surface-3);
}

/* login surface */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s-6);
  background:
    radial-gradient(circle at 20% 0%, var(--sage-soft), transparent 50%),
    radial-gradient(circle at 100% 100%, var(--rose-soft), transparent 50%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--s-8);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--surface-3);
}
.login-card h1 {
  font-size: var(--fs-2xl);
  margin-bottom: var(--s-1);
}
.login-card .muted { font-size: var(--fs-sm); margin-bottom: var(--s-6); }

/* segmented */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  padding: 2px;
  border-radius: var(--radius-md);
  gap: 1px;
}
.segmented__item {
  padding: 6px 12px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-soft);
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
}
.segmented__item.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* statbox */
.statbox {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--s-4) var(--s-5);
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 50%);
}
.statbox__label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 600;
}
.statbox__value {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: var(--s-1);
  font-variant-numeric: tabular-nums;
}
.statbox__delta {
  font-size: var(--fs-xs);
  color: var(--ink-faint);
  margin-top: var(--s-1);
}

/* prose (rich text) */
.prose { max-width: 70ch; line-height: 1.65; }
.prose h2 { font-size: var(--fs-xl); margin: var(--s-6) 0 var(--s-2); }
.prose h3 { font-size: var(--fs-lg); margin: var(--s-5) 0 var(--s-2); }
.prose p { margin-bottom: var(--s-3); }
.prose ul, .prose ol { margin: 0 0 var(--s-3) var(--s-5); }
.prose li { margin-bottom: var(--s-1); }
.prose blockquote {
  border-left: 3px solid var(--sage);
  padding: var(--s-1) var(--s-4);
  color: var(--ink-soft);
  margin: var(--s-3) 0;
  font-style: italic;
}
.prose code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
}
.prose pre {
  background: var(--surface-2);
  padding: var(--s-3);
  border-radius: var(--radius-md);
  overflow-x: auto;
}
.prose img { border-radius: var(--radius-md); margin: var(--s-3) 0; }
