.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  min-height: 60px;
  padding-block: var(--space-2);
}

.brand {
  color: var(--text);
  font-size: var(--text-lg);
  font-weight: 700;
  text-decoration: none;
}

.brand:hover {
  color: var(--accent);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) 14px;
}

.nav-user {
  max-width: 9rem;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-link {
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  color: var(--accent);
}

.nav-link:hover {
  color: var(--accent);
}

.nav-form {
  margin: 0;
}

.card {
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-title {
  margin-bottom: 20px;
  font-size: var(--text-xl);
  line-height: 1.25;
}

.card-footer {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

.field {
  margin-bottom: var(--space-4);
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
}

.input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: inherit;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
  outline: none;
}

.input:disabled {
  background: var(--surface-muted);
  color: var(--muted);
  cursor: not-allowed;
}

.input.is-invalid {
  border-color: var(--danger);
}

.input.is-invalid:focus {
  box-shadow: 0 0 0 3px var(--error-border);
}

.field-hint,
.field-error {
  margin: 6px 0 0;
  font-size: var(--text-sm);
}

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

.field-error {
  color: var(--danger);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary,
.btn-primary:hover {
  color: var(--accent-text);
}

.btn-primary {
  background: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-muted);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--muted);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-muted);
  color: var(--text);
}

.btn-danger,
.btn-danger:hover {
  color: var(--danger-text);
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--text-sm);
}

.btn-lg {
  padding: 14px 26px;
  font-size: var(--text-lg);
}

.btn-block {
  width: 100%;
}

.alert {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

.alert p {
  margin: 0;
}

.alert ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.alert-title {
  font-weight: 600;
}

.alert-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.alert-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.alert-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.alert-info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info-text);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.5;
}

.badge-accent {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.badge-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.badge-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.badge-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.avatar {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 50%;
  color: var(--accent-text);
  font-weight: 700;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 0.8rem;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: var(--text-xl);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.table th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

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

.table .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.tabs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 10px 14px;
  background: none;
  border: 0;
  box-shadow: inset 0 -2px 0 transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  box-shadow: inset 0 -2px 0 var(--accent);
  color: var(--accent);
}

.dialog {
  width: min(92vw, 440px);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}

.dialog::backdrop {
  background: rgb(8 10 20 / 0.55);
}

.dialog-title {
  margin: 0 0 var(--space-3);
  font-size: var(--text-lg);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.btn-icon {
  aspect-ratio: 1;
  padding: 8px;
}

.btn-icon.btn-sm {
  padding: 6px;
}

.spinner {
  display: inline-block;
  flex: none;
  width: 1.25em;
  height: 1.25em;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  display: block;
  min-height: 1em;
  background: linear-gradient(90deg, var(--surface-muted) 25%, var(--border) 50%, var(--surface-muted) 75%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-title {
  width: 40%;
  height: 1.4em;
}

.skeleton-line {
  width: 100%;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty .icon {
  width: 40px;
  height: 40px;
}

.empty-title {
  margin: 0;
  color: var(--text);
  font-size: var(--text-lg);
  font-weight: 600;
}

.empty p {
  margin: 0;
}

.waiting {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  border-radius: var(--radius-sm);
  color: var(--info-text);
  font-size: var(--text-sm);
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: 10;
  padding: 4px 8px;
  background: var(--text);
  border-radius: 6px;
  color: var(--bg);
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.12s;
}

[data-tooltip][data-tooltip-pos="bottom"]::after {
  top: calc(100% + 8px);
  bottom: auto;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
}

.menu {
  position: relative;
  display: inline-block;
}

.menu > summary {
  list-style: none;
  cursor: pointer;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  min-width: 210px;
  margin: 0;
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  list-style: none;
}

.menu-end .menu-list {
  right: 0;
  left: auto;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.menu-item.is-danger,
.menu-item.is-danger:hover {
  color: var(--danger);
}

.menu-divider {
  height: 1px;
  margin: var(--space-1) 0;
  background: var(--border);
}

@media (max-width: 480px) {
  .card {
    padding: 20px;
  }
}

.btn-link {
  padding: 0;
  background: none;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
}

.btn-link:hover:not(:disabled) {
  color: var(--accent-hover);
}

.btn .spinner {
  width: 1em;
  height: 1em;
  border-color: currentColor;
  border-top-color: transparent;
}

.btn.is-loading {
  opacity: 0.85;
  pointer-events: none;
}

.btn-group {
  display: inline-flex;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn + .btn {
  margin-left: -1px;
}

.btn-group .btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.btn-group .btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.btn-group .btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

textarea.input {
  min-height: 96px;
  resize: vertical;
}

.input-group {
  display: flex;
  gap: var(--space-2);
}

.input-group .input {
  flex: 1;
  min-width: 0;
}

.fieldset {
  min-width: 0;
  margin: 0 0 var(--space-4);
  padding: 0;
  border: 0;
}

.legend {
  margin-bottom: 6px;
  padding: 0;
  font-size: var(--text-sm);
  font-weight: 600;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}

.choice-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: var(--space-3);
}

.choice {
  position: relative;
  display: block;
  cursor: pointer;
}

.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-body {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.choice-body .piece-icon {
  font-size: 2rem;
}

.choice-body .icon {
  width: 2rem;
  height: 2rem;
}

.choice:hover .choice-body {
  border-color: var(--muted);
}

.choice input:checked + .choice-body {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.choice input:focus-visible + .choice-body {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.choice input:disabled + .choice-body {
  cursor: not-allowed;
  opacity: 0.5;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  flex: none;
  width: 44px;
  height: 24px;
  background: var(--muted);
  border-radius: var(--radius-pill);
  transition: background 0.15s;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  transition: transform 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chat-log {
  display: grid;
  gap: var(--space-2);
  align-content: start;
  max-height: 240px;
  margin: 0;
  padding: var(--space-3);
  overflow-y: auto;
  list-style: none;
}

.chat-message {
  max-width: 85%;
  padding: 6px 12px;
  background: var(--surface-muted);
  border-radius: 14px;
  font-size: var(--text-sm);
}

.chat-message.is-own {
  justify-self: end;
  background: var(--accent);
  color: var(--accent-text);
}

.chat-author {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: var(--text-xs);
}

.chat-message.is-own .chat-author {
  color: inherit;
  opacity: 0.85;
}

.chat-form {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}

.chat-form .input {
  flex: 1;
  min-width: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--space-3);
}

.stat {
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-value {
  display: block;
  font-size: var(--text-2xl);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.2;
}

.stat-label {
  color: var(--muted);
  font-size: var(--text-sm);
}

.profile-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}

.profile-head > div {
  display: grid;
  gap: var(--space-2);
}

.profile-head :is(h1, h2) {
  margin: 0;
}

.profile {
  display: grid;
  gap: var(--space-5);
}

.profile-section {
  display: grid;
  gap: var(--space-3);
}

.profile-section h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.page-link {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.page-link:hover {
  border-color: var(--muted);
  color: var(--text);
}

.page-link.is-active,
.page-link.is-active:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.page-link.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}

[data-tooltip][data-tooltip-align="end"]::after {
  right: 0;
  left: auto;
  transform: none;
}

.table tr.is-me td {
  background: var(--surface-muted);
  font-weight: 700;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}
