:root {
  color-scheme: dark;
  --bg: #070707;
  --bg-soft: #0b0b0c;
  --panel: #141416;
  --panel-2: #1b1b1e;
  --panel-3: #202024;
  --ink: #f4f4f5;
  --muted: #a3a3aa;
  --line: #2b2b31;
  --line-soft: #232327;
  --accent: #c94c4c;
  --accent-hover: #de5d5d;
  --danger: #ef6868;
  --warning: #e0a64a;
  --success: #5fcf8f;
  --info: #77a7ff;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

.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;
}

html {
  min-width: 0;
  background: var(--bg);
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  touch-action: pan-x pan-y;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  min-width: 0;
  background: var(--bg);
}

.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  direction: ltr;
  padding: calc(10px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: rgba(7, 7, 7, 0.96);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(14px);
}

.mobile-brand {
  min-width: 0;
  width: max-content;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.ksk-wordmark {
  display: inline-block;
  color: #ef5c5c;
  font-size: 1.32rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 0 9px rgba(239, 92, 92, 0.32);
  animation: ksk-power-cycle 7s linear infinite;
}

@keyframes ksk-power-cycle {
  0%,
  28% {
    color: #ef5c5c;
    opacity: 1;
    text-shadow: 0 0 9px rgba(239, 92, 92, 0.32);
  }
  29% {
    opacity: 0.18;
  }
  30% {
    opacity: 1;
  }
  31% {
    opacity: 0.28;
  }
  32% {
    opacity: 1;
  }
  33% {
    opacity: 0.08;
  }
  34%,
  70% {
    color: #62dde0;
    opacity: 1;
    text-shadow: 0 0 9px rgba(98, 221, 224, 0.3);
  }
  71% {
    opacity: 0.16;
  }
  72% {
    opacity: 1;
  }
  73% {
    opacity: 0.26;
  }
  74% {
    opacity: 1;
  }
  75% {
    opacity: 0.08;
  }
  76%,
  100% {
    color: #ef5c5c;
    opacity: 1;
    text-shadow: 0 0 9px rgba(239, 92, 92, 0.32);
  }
}

.profile-menu-shell {
  position: relative;
}

.profile-button,
.tool-header-button {
  width: 46px;
  height: 46px;
  min-width: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
  text-decoration: none;
}

.profile-button:hover,
.profile-button:focus-visible,
.tool-header-button:hover,
.tool-header-button:focus-visible,
.tool-header-button[aria-current="page"] {
  border-color: rgba(201, 76, 76, 0.52);
  background: #19191c;
}

.profile-button:focus-visible,
.tool-header-button:focus-visible {
  outline: 3px solid rgba(201, 76, 76, 0.22);
  outline-offset: 2px;
}

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: min(250px, calc(100vw - 28px));
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111113;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  padding: 10px;
}

.profile-language-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.profile-language-row .language-picker {
  width: 54px;
  min-width: 54px;
}

.profile-menu-action {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 9px 12px;
  text-align: start;
}

.profile-menu-action:hover,
.profile-menu-action:focus-visible {
  border-color: rgba(201, 76, 76, 0.52);
  background: #1c1c20;
}

.tool-topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  direction: ltr;
  padding: calc(8px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  background: rgba(7, 7, 7, 0.97);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(14px);
}

.tool-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tool-title {
  min-width: 0;
  overflow: hidden;
  color: #f4f4f5;
  font-size: clamp(0.78rem, 3.4vw, 1rem);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.language-picker {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  overflow: hidden;
}

.language-picker::after {
  display: none;
}

.language-picker:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 76, 76, 0.18);
}

.language-picker .language-select {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  opacity: 0;
  cursor: pointer;
  padding: 0;
}

.language-flag {
  display: block;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
  font-size: 1.28rem;
  line-height: 1;
}

.mobile-menu {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
  padding: 12px 0 2px;
}

.sidebar {
  display: none;
}

.sidebar-tools {
  margin-top: auto;
  display: grid;
  gap: 16px;
}

.brand-logo {
  width: 118px;
  height: 78px;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: contain;
  background: #050505;
  border: 1px solid #25252a;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  min-height: 44px;
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #d9d9de;
  text-decoration: none;
  padding: 10px 12px;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.nav a:hover,
.nav a.active {
  background: rgba(201, 76, 76, 0.13);
  border-color: rgba(201, 76, 76, 0.38);
  color: #ffffff;
}

.language-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
}

.session-box {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
}

.mobile-session {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.main {
  min-width: 0;
  padding: 18px max(14px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.view {
  width: 100%;
  max-width: 1240px;
  min-width: 0;
  margin: 0 auto;
}

.page-head {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  color: #ffffff;
  font-size: clamp(1.52rem, 6vw, 2rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.page-head p {
  max-width: 720px;
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.grid {
  display: grid;
  gap: 14px;
}

.form-note {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.metrics,
.two-col,
.settings-grid {
  grid-template-columns: 1fr;
}

.dashboard-count-grid {
  display: grid;
  gap: 10px;
  align-items: stretch;
}

.dashboard-count-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-count-grid .metric {
  height: 100%;
  min-height: 112px;
  aspect-ratio: 1 / 1;
  align-content: space-between;
  padding: 12px;
}

.dashboard-link-card {
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.dashboard-link-card:hover,
.dashboard-link-card:focus-visible {
  border-color: rgba(201, 76, 76, 0.52);
  background: #19191c;
}

.dashboard-link-card:focus-visible {
  outline: 3px solid rgba(201, 76, 76, 0.25);
  outline-offset: 2px;
}

.dashboard-link-card:active {
  transform: translateY(1px);
}

.dashboard-count-grid .metric span {
  font-size: 0.78rem;
  line-height: 1.2;
}

.dashboard-count-grid .metric strong {
  font-size: clamp(1.55rem, 9vw, 2rem);
}

.project-tool-grid {
  width: min(100%, 620px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  gap: 10px;
  direction: ltr;
}

.project-launcher-grid {
  width: min(100%, 620px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 110px));
  gap: 10px;
  margin-top: 10px;
  direction: ltr;
}

.project-launcher-tile {
  height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  text-decoration: none;
  padding: 8px;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.project-launcher-tile:hover,
.project-launcher-tile:focus-visible {
  border-color: rgba(201, 76, 76, 0.52);
  background: #19191c;
}

.project-launcher-tile:active {
  transform: translateY(1px);
}

.project-launcher-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.project-launcher-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
}

.project-launcher-label {
  font-size: clamp(0.66rem, 3vw, 0.8rem);
  font-weight: 750;
  text-align: center;
  line-height: 1.15;
}

.project-tool {
  position: relative;
  width: 100%;
  height: 110px;
  min-width: 0;
  display: grid;
  grid-template-columns: clamp(56px, 18vw, 78px) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 9px 10px;
  direction: ltr;
  font: inherit;
  text-align: left;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.project-tool.is-clickable {
  cursor: pointer;
}

.project-tool.is-clickable:hover,
.project-tool.is-clickable:focus-visible {
  border-color: rgba(201, 76, 76, 0.52);
  background: #19191c;
}

.project-tool.is-clickable:active {
  transform: translateY(1px);
}

.project-tool.is-locked {
  cursor: default;
  opacity: 1;
}

.project-tool-open {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}

.project-tool-open:focus-visible {
  outline: 3px solid rgba(201, 76, 76, 0.25);
  outline-offset: 2px;
}

.project-tool-logo-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  overflow: visible;
  background: transparent;
}

.project-tool-logo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.project-tool-content {
  min-width: 0;
  display: grid;
  align-items: center;
  justify-content: center;
  justify-items: center;
  gap: 8px;
  direction: ltr;
  text-align: center;
}

.project-tool-content .code-text {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(0.66rem, 3.2vw, 1.12rem);
  line-height: 1.15;
  text-overflow: clip;
  white-space: nowrap;
}

.project-copy-button {
  position: relative;
  z-index: 2;
  min-width: 54px;
  min-height: 28px;
  border: 1px solid #34343a;
  border-radius: 6px;
  background: #202024;
  color: #dedee2;
  padding: 4px 9px;
  font-size: 0.7rem;
  font-weight: 750;
  line-height: 1;
}

.project-copy-button:hover,
.project-copy-button:focus-visible {
  border-color: rgba(98, 221, 224, 0.55);
  background: #26262b;
}

.project-soon-tool {
  width: 100%;
  height: 110px;
  min-width: 0;
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  box-shadow: var(--shadow);
  font: inherit;
  font-size: clamp(0.72rem, 3.3vw, 0.9rem);
  font-weight: 750;
  letter-spacing: 0;
  opacity: 1;
}

.project-soon-tool:disabled {
  opacity: 1;
}

.page-back-button {
  gap: 8px;
}

.back-arrow {
  font-size: 1.18rem;
  line-height: 1;
}

.dashboard-latest-card {
  margin-top: 12px;
  box-shadow: none;
}

.latest-meta {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.latest-meta strong {
  color: #ffffff;
}

.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.card + .card {
  margin-top: 14px;
}

.grid > .card + .card,
.dashboard-count-grid > .card + .card {
  margin-top: 0;
}

.metric {
  display: grid;
  gap: 10px;
}

.metric span,
.muted {
  color: var(--muted);
}

.metric strong {
  color: #ffffff;
  font-size: 1.8rem;
  line-height: 1;
}

.latest-code {
  display: grid;
  gap: 14px;
}

.code-text {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: #ffffff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0;
}

.latest-code .code-text {
  margin-top: 6px;
  font-size: 1.15rem;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  align-items: end;
  gap: 10px;
  margin-bottom: 18px;
}

.form-grid label,
.dialog label {
  min-width: 0;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar input,
.toolbar select,
.form-grid input,
.form-grid select,
.dialog input,
.language-select,
td select {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 16px;
  padding: 0 12px;
  outline: none;
}

.toolbar input:focus,
.toolbar select:focus,
.form-grid input:focus,
.form-grid select:focus,
.dialog input:focus,
.language-select:focus,
td select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 76, 76, 0.18);
}

input::placeholder {
  color: #707078;
}

.form-check {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}

.form-check input {
  width: 19px;
  height: 19px;
  min-height: 0;
  accent-color: var(--accent);
}

.table-wrap {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 13px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #18181b;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  color: #ededf0;
}

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

.actions {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.page-head > .actions {
  justify-content: flex-start;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.icon-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
  text-decoration: none;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

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

.secondary-button {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: rgba(201, 76, 76, 0.45);
  background: #242428;
}

.danger-button {
  border-color: rgba(239, 104, 104, 0.36);
  background: rgba(239, 104, 104, 0.09);
  color: #ff9898;
}

.danger-button:hover {
  border-color: rgba(239, 104, 104, 0.58);
  background: rgba(239, 104, 104, 0.15);
}

.ghost-button {
  border-color: var(--line);
  background: transparent;
  color: #f5f5f6;
}

.ghost-button:hover {
  border-color: rgba(201, 76, 76, 0.52);
  background: rgba(201, 76, 76, 0.13);
}

.icon-button {
  width: 44px;
  flex: 0 0 44px;
  padding: 0;
  background: var(--panel-2);
  color: var(--ink);
}

.badge {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.badge-active,
.badge-redeemed {
  border-color: rgba(95, 207, 143, 0.34);
  background: rgba(95, 207, 143, 0.12);
  color: var(--success);
}

.badge-already_claimed,
.badge-unknown {
  border-color: rgba(119, 167, 255, 0.34);
  background: rgba(119, 167, 255, 0.12);
  color: var(--info);
}

.badge-retry,
.badge-pending {
  border-color: rgba(224, 166, 74, 0.34);
  background: rgba(224, 166, 74, 0.13);
  color: var(--warning);
}

.badge-failed,
.badge-invalid,
.badge-expired,
.badge-exhausted,
.badge-inactive {
  border-color: rgba(239, 104, 104, 0.36);
  background: rgba(239, 104, 104, 0.12);
  color: var(--danger);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #101012;
  color: var(--muted);
  padding: 28px 16px;
  text-align: center;
}

.toast {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(420px, calc(100vw - 28px));
  border: 1px solid rgba(201, 76, 76, 0.4);
  border-radius: 8px;
  background: #171719;
  color: #ffffff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.dialog {
  width: min(430px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.login-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-wordmark {
  width: 60px;
  min-width: 60px;
  flex: 0 0 auto;
  text-align: center;
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.15;
}

.dialog-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.dialog-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.form-error {
  margin: 0;
  color: #ff9b9b;
}

.stat-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.stat-list div {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 12px;
}

.stat-list span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
}

.stat-list strong {
  color: #ffffff;
  font-size: 1.2rem;
}

.alliance-grid,
.result-alliance-list {
  display: grid;
  gap: 14px;
}

.alliance-tile {
  min-width: 0;
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 15px;
}

.alliance-open,
.alliance-result-head {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.alliance-icon {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(201, 76, 76, 0.34);
  border-radius: 8px;
  background: rgba(201, 76, 76, 0.12);
  color: #ffffff;
  font-size: 1.04rem;
  font-weight: 900;
}

.alliance-summary {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.alliance-summary strong,
.alliance-result-head h2,
.card h2 {
  margin: 0;
  color: #ffffff;
  line-height: 1.18;
}

.alliance-summary strong,
.card h2 {
  font-size: 1.08rem;
}

.alliance-summary small,
.tile-meta {
  color: var(--muted);
}

.tile-meta {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 0.9rem;
}

.tile-meta span {
  min-width: 0;
}

.compact-form {
  margin: 14px 0 0;
}

.alliance-detail-metrics {
  margin-bottom: 14px;
}

.section-head {
  min-width: 0;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head p,
.card > p.muted {
  margin: 6px 0 0;
  line-height: 1.5;
}

.status-groups {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.status-group {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 12px;
}

.status-group header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.status-group p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.member-chip-list {
  display: grid;
  gap: 8px;
}

.member-chip {
  min-width: 0;
  display: grid;
  gap: 3px;
  border: 1px solid #303037;
  border-radius: 8px;
  background: #17171a;
  padding: 9px 10px;
}

.member-chip strong,
.member-chip small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-chip small {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.history-table {
  margin-top: 14px;
}

.member-card-list {
  display: grid;
  gap: 9px;
}

.member-filter-toolbar {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.member-filter-toolbar input,
.member-filter-toolbar select[name="alliance_id"],
.member-filter-toolbar button {
  grid-column: 1 / -1;
}

.member-status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 0.72rem;
}

.member-status-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.member-status-legend .status-dot {
  width: 8px;
  height: 8px;
  flex-basis: 8px;
  border-width: 1px;
}

.member-list-button {
  width: 100%;
  min-width: 0;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-align: start;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.member-list-button:hover,
.member-list-button:focus-visible {
  border-color: rgba(201, 76, 76, 0.52);
  background: #19191c;
}

.member-list-button:focus-visible {
  outline: 3px solid rgba(201, 76, 76, 0.25);
  outline-offset: 2px;
}

.member-list-button:active {
  transform: translateY(1px);
}

.member-list-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.member-list-identity strong {
  min-width: 0;
  overflow: hidden;
  color: #ffffff;
  font-size: 0.96rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border: 1px solid #303037;
  border-radius: 50%;
  background: #1a1a1d;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
  font-size: 1.05rem;
}

.member-status-marker {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border: 1px solid #303037;
  border-radius: 50%;
  background: #111113;
}

.status-dot {
  width: 11px;
  height: 11px;
  display: inline-block;
  flex: 0 0 11px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: #777780;
}

.status-dot-redeemed,
.status-dot-active {
  background: var(--success);
}

.status-dot-already_claimed {
  background: var(--info);
}

.status-dot-retry {
  background: var(--warning);
}

.status-dot-pending {
  background: #9a9aa4;
}

.status-dot-failed,
.status-dot-invalid,
.status-dot-expired,
.status-dot-exhausted,
.status-dot-inactive {
  background: var(--danger);
}

.member-detail-dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: min(86vh, 820px);
}

.member-detail-panel {
  max-height: min(86vh, 820px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.member-detail-grid {
  display: grid;
  gap: 8px;
}

.member-detail-grid > div {
  min-width: 0;
  display: grid;
  gap: 4px;
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 0 10px;
}

.member-detail-grid span {
  color: var(--muted);
  font-size: 0.78rem;
}

.member-detail-grid strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #ffffff;
}

.member-history-section {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.member-history-section h3 {
  margin: 0;
  color: #ffffff;
  font-size: 1rem;
}

.member-history-list {
  display: grid;
  gap: 8px;
}

.member-history-item {
  min-width: 0;
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #17171a;
  padding: 11px;
}

.member-history-item header,
.member-history-status,
.member-history-meta {
  min-width: 0;
  display: flex;
  align-items: center;
}

.member-history-item header {
  justify-content: space-between;
  gap: 10px;
}

.member-history-item header > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.member-history-item small {
  color: var(--muted);
  line-height: 1.35;
}

.member-history-status {
  flex: 0 0 auto;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.member-history-meta {
  flex-wrap: wrap;
  gap: 7px 14px;
  color: var(--muted);
  font-size: 0.76rem;
}

.member-history-meta strong {
  color: #ffffff;
  font-weight: 600;
}

.member-history-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.result-alliance-card {
  display: grid;
  gap: 14px;
}

.alliance-result-head h2 {
  font-size: 1.14rem;
}

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] th,
html[dir="rtl"] td {
  text-align: right;
}

html[dir="rtl"] .mobile-brand,
html[dir="rtl"] .brand,
html[dir="rtl"] .login-title,
html[dir="rtl"] .alliance-open,
html[dir="rtl"] .alliance-result-head,
html[dir="rtl"] .actions,
html[dir="rtl"] .dialog-head,
html[dir="rtl"] .dialog-actions {
  direction: rtl;
}

html[dir="rtl"] .profile-menu {
  direction: rtl;
  text-align: right;
}

@media (max-width: 390px) {
  .card {
    padding: 14px;
  }
}

@media (max-width: 340px) {
  .member-filter-toolbar {
    grid-template-columns: 1fr;
  }

  .member-filter-toolbar input,
  .member-filter-toolbar select[name="alliance_id"],
  .member-filter-toolbar button {
    grid-column: auto;
  }

  .profile-button,
  .tool-header-button {
    width: 42px;
    height: 42px;
    min-width: 42px;
  }

  .tool-title {
    font-size: 0.74rem;
  }
}

@media (min-width: 620px) {
  .main {
    padding: 24px max(22px, env(safe-area-inset-right)) calc(30px + env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .alliance-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .member-card-list,
  .member-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .latest-code {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
}

@media (min-width: 900px) {
  .app-shell {
    display: block;
  }

  .mobile-topbar,
  .tool-topbar {
    display: grid;
    padding: 14px max(28px, calc((100vw - 1240px) / 2));
  }

  .sidebar {
    display: none;
  }

  .brand {
    justify-content: center;
  }

  .main {
    padding: 28px;
  }

  .page-head {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .toolbar {
    display: flex;
    flex-wrap: wrap;
  }

  .member-filter-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1.25fr) repeat(3, minmax(150px, 0.75fr)) auto;
  }

  .member-filter-toolbar input,
  .member-filter-toolbar select,
  .member-filter-toolbar button {
    width: 100%;
    min-width: 0;
    grid-column: auto;
  }

  .toolbar input,
  .toolbar select {
    width: auto;
    min-width: 210px;
  }

  .form-grid {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
  }

  .settings-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .settings-grid .form-note {
    grid-column: 1 / -1;
  }

  .alliance-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .compact-form {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .ksk-wordmark {
    animation: none;
  }
}

@media (min-width: 1200px) {
  .metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .two-col {
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  }

  .status-groups {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

}

/* App-style alliance workspace */
.live-pulse {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: #57d99a;
  box-shadow: 0 0 0 0 rgba(87, 217, 154, 0.35);
  animation: live-pulse 2.4s ease-out infinite;
}

@keyframes live-pulse {
  0%, 40% { box-shadow: 0 0 0 0 rgba(87, 217, 154, 0.3); }
  75%, 100% { box-shadow: 0 0 0 6px rgba(87, 217, 154, 0); }
}

.dashboard-app-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.dashboard-app-grid .metric,
.dashboard-alliance-card {
  min-height: 132px;
  aspect-ratio: auto;
}

.dashboard-alliance-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-content: space-between;
  gap: 10px;
  border: 1px solid rgba(201, 76, 76, 0.46);
  border-radius: 8px;
  background: linear-gradient(145deg, #171719, #111113);
  color: inherit;
  padding: 12px;
  text-decoration: none;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.dashboard-alliance-card:hover,
.dashboard-alliance-card:focus-visible {
  border-color: rgba(222, 93, 93, 0.75);
  background: #19191c;
}

.dashboard-alliance-card:active {
  transform: translateY(1px);
}

.dashboard-alliance-image {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(201, 76, 76, 0.5);
  border-radius: 8px;
  background: rgba(201, 76, 76, 0.13);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 900;
}

.dashboard-alliance-label {
  min-width: 0;
  display: grid;
  grid-column: 1 / -1;
  gap: 4px;
}

.dashboard-alliance-label small {
  color: var(--muted);
  font-size: 0.76rem;
}

.dashboard-alliance-label strong {
  overflow: hidden;
  color: #fff;
  font-size: 1.02rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-alliance-label em {
  color: var(--muted);
  font-size: 0.76rem;
  font-style: normal;
}

.page-icon-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-icon-button {
  width: 46px;
  height: 46px;
  min-width: 46px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1;
  padding: 0;
}

.page-icon-button:hover,
.page-icon-button:focus-visible {
  border-color: rgba(201, 76, 76, 0.55);
  background: #242428;
}

.alliance-switch-list {
  display: grid;
  gap: 9px;
}

.alliance-switch-row {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0;
}

.alliance-switch-row.is-selected {
  border-color: rgba(201, 76, 76, 0.62);
  background: #19191c;
}

.alliance-switch-main {
  width: 100%;
  min-width: 0;
  min-height: 74px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 10px 12px;
  text-align: start;
}

button.alliance-switch-row {
  min-height: 74px;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-align: start;
}

.alliance-switch-row .alliance-summary {
  flex: 1 1 auto;
}

.alliance-selected-mark {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 1.2rem;
}

.alliance-owner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 0;
}

html[dir="rtl"] .alliance-owner-actions {
  padding: 8px 0 8px 8px;
}

.danger-icon-button {
  color: #ff9292;
}

.alliance-add-button {
  width: 100%;
  margin-top: 14px;
}

.compact-alliance-list {
  margin-top: 14px;
}

.gift-code-list {
  display: grid;
  gap: 9px;
}

.gift-code-button {
  width: 100%;
  min-width: 0;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 11px 12px;
  text-align: start;
}

.gift-code-button:hover,
.gift-code-button:focus-visible {
  border-color: rgba(201, 76, 76, 0.52);
  background: #19191c;
}

.gift-code-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.gift-code-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gift-code-main small {
  color: var(--muted);
  font-size: 0.74rem;
}

.gift-code-progress {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.gift-code-progress strong {
  color: #fff;
}

.gift-code-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.gift-code-detail-grid > div {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 5px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #111113;
  padding: 10px;
}

.gift-code-detail-grid span:not(.badge) {
  color: var(--muted);
  font-size: 0.74rem;
}

.gift-code-detail-grid strong {
  overflow-wrap: anywhere;
  color: #fff;
}

.sheet-actions,
.member-detail-actions {
  margin-top: 16px;
}

.member-detail-actions {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line-soft);
  padding-top: 16px;
}

.dialog select {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 16px;
  padding: 0 12px;
  outline: none;
}

.dialog select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 76, 76, 0.18);
}

.sheet-dialog {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: 680px;
  max-height: min(88dvh, 820px);
  margin: auto auto 0;
  border-radius: 8px 8px 0 0;
  border-bottom: 0;
}

.sheet-panel {
  max-height: min(88dvh, 820px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.result-card-list .member-list-button,
.member-card-list .member-list-button {
  min-height: 62px;
}

.result-detail-grid > div:last-child {
  grid-column: 1 / -1;
}

.alliance-check-field {
  min-width: 0;
  grid-column: 1 / -1;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 12px;
}

.alliance-check-field legend {
  color: var(--muted);
  padding: 0 6px;
}

.alliance-check-grid,
.admin-user-list {
  display: grid;
  gap: 8px;
}

.alliance-check-option {
  min-width: 0;
  min-height: 52px;
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 10px !important;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #111113;
  padding: 9px 10px;
}

.alliance-check-option input {
  width: 20px;
  min-height: 20px;
  flex: 0 0 20px;
  accent-color: var(--accent);
}

.alliance-check-option span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.alliance-check-option strong {
  color: #fff;
}

.alliance-check-option small {
  color: var(--muted);
}

.admin-user-list {
  margin-top: 16px;
}

.admin-user-row {
  min-width: 0;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #111113;
  padding: 9px 10px;
}

.admin-user-summary {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.admin-user-summary strong,
.admin-user-summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user-summary small {
  color: var(--muted);
}

.admin-user-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 360px) {
  .dashboard-app-grid {
    gap: 8px;
  }

  .dashboard-app-grid .metric,
  .dashboard-alliance-card {
    min-height: 122px;
    padding: 10px;
  }

  .gift-code-detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 620px) {
  .dashboard-app-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .dashboard-app-grid .metric,
  .dashboard-alliance-card {
    min-height: 150px;
  }

  .member-card-list,
  .gift-code-list,
  .alliance-switch-list,
  .admin-user-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sheet-dialog {
    inset: 0;
    width: min(680px, calc(100vw - 40px));
    margin: auto;
    border-radius: 8px;
    border-bottom: 1px solid var(--line);
  }

  .alliance-check-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .member-card-list,
  .gift-code-list,
  .alliance-switch-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-app-grid .metric,
  .dashboard-alliance-card {
    min-height: 166px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-pulse {
    animation: none;
  }
}
