:root {
  --bg: #fbf8f4;
  --panel: #ffffff;
  --panel-soft: #f7f8fb;
  --line: #e8e4dc;
  --line-strong: #d8d3ca;
  --text: #2f2a23;
  --muted: #6e6a61;
  --blue: #2f6fff;
  --blue-dark: #285bd1;
  --secondary: #58647a;
  --danger: #ef3555;
  --danger-soft: #f4dddd;
  --green: #2f8f7a;
  --amber: #d6a04a;
  color-scheme: light;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

*::before,
*::after {
  box-sizing: inherit;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #f3f0ea 0%, #fbf8f4 45%, #ffffff 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

#app {
  min-height: 100vh;
}

.auth-screen,
.waiting-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  padding: 28px;
}

.auth-card {
  display: grid;
  gap: 14px;
  justify-items: center;
}

.auth-icon {
  width: 48px;
  height: 48px;
}

.auth-card h1,
.waiting-content h1,
.page h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

input,
select {
  min-height: 40px;
  border: 1px solid #e0ddd6;
  border-radius: 10px;
  background: #ffffff;
  color: #2d2b26;
  padding: 8px 10px;
}

input.valid {
  border-color: var(--green);
  color: #2f7a54;
}

.auth-card input {
  width: min(360px, calc(100vw - 48px));
}

.status-text,
.feedback {
  min-height: 20px;
  margin: 0;
}

.muted,
.page-description {
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 14px;
  min-height: 40px;
  padding: 9px 18px;
  font-weight: 700;
  color: #ffffff;
}

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

.btn.primary:hover {
  background: var(--blue-dark);
}

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

.btn.secondary:hover,
.gift-trigger:hover {
  background: #4d5870;
}

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

.btn.compact,
.gift-trigger {
  width: 118px;
  min-height: 40px;
}

.gift-trigger {
  background: var(--secondary);
}

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

.btn.secondary:disabled:hover,
.gift-trigger:disabled:hover {
  background: var(--secondary);
}

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

.header-danger {
  background: var(--danger-soft);
  color: #b23c43;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #ffffff;
}

.icon-button img {
  width: 24px;
  height: 24px;
}

.help-float {
  position: absolute;
  top: 24px;
  right: 24px;
}

.progress {
  width: 480px;
  max-width: calc(100vw - 64px);
  height: 14px;
  border: 1px solid #e0ddd6;
  background: #f5f2ec;
  overflow: hidden;
}

.progress::before {
  content: "";
  display: block;
  width: 40%;
  height: 100%;
  background: #c3d3f7;
  animation: slide 1.2s infinite ease-in-out;
}

@keyframes slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

.waiting-content {
  display: grid;
  justify-items: center;
  gap: 18px;
}

.reset-block {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.hidden {
  display: none !important;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid #e9e3d7;
}

.topbar-left,
.topbar-right,
.card-line,
.status-row,
.input-row,
.action-row,
.gift-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-left {
  flex: 1;
}

.server-title {
  font-size: 20px;
}

.arena-chip {
  margin-left: auto;
  border: 1px solid #e4ded3;
  background: #f2efe9;
  border-radius: 12px;
  padding: 6px 10px;
  font-weight: 700;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d45252;
}

.connection-dot.connected {
  background: #3aa56d;
}

.connection-dot.waiting {
  background: #d4a832;
}

.connection-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.profile-button {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 19px;
  background: #f7f3ec;
}

.profile-button img {
  width: 28px;
  height: 28px;
}

.body-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 0;
  height: calc(100vh - 64px);
}

.sidebar {
  position: sticky;
  top: 0;
  height: calc(100vh - 64px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px;
  background: #ffffff;
  border-right: 1px solid #e9e3d7;
}

.brand {
  height: 48px;
  display: flex;
  align-items: center;
  font-size: 22px;
  font-weight: 800;
}

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

.nav-button {
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #3f3b33;
  padding: 10px 12px;
  font-weight: 700;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: #f7f3ec;
}

.nav-button.locked {
  opacity: 0.42;
  cursor: not-allowed;
}

.nav-button.locked:hover {
  background: transparent;
}

.nav-button img {
  width: 24px;
  height: 24px;
}

.sidebar-spacer {
  flex: 1;
}

.language-block {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  border-radius: 12px;
  background: #f7f3ec;
  padding: 8px;
}

.lang-select {
  width: 92px;
  color: #3f3b33;
}

.main-content {
  min-width: 0;
  height: calc(100vh - 64px);
  overflow: auto;
}

.page {
  padding: 24px 28px;
  display: grid;
  gap: 16px;
  max-width: 1360px;
  margin: 0 auto;
}

.panel-card,
.help-card {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
}

.panel-card h2,
.help-card h2 {
  margin: 0;
  font-size: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.button-grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #9aa3af;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.badge.running,
.badge.listening,
.badge.active,
.badge.normal,
.badge.free {
  background: var(--green);
}

.badge.paused,
.badge.passive,
.badge.offline {
  background: var(--amber);
}

.badge.error,
.badge.explosive,
.badge.busy {
  background: #d64550;
}

.mob-grid,
.event-grid {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

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

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

.mob-card,
.event-card {
  min-width: 0;
  background: var(--panel-soft);
  border: 1px solid #ece7df;
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.mob-card .card-line {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.mob-card strong,
.gift-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mob-dot {
  width: 20px;
  flex-shrink: 0;
  height: 20px;
  border-radius: 50%;
  background: #cfe2d9;
}

.mob-dot.explosive {
  background: #f2c1c1;
}

.mob-dot.passive {
  background: #e6ddc8;
}

.action-row {
  min-width: 0;
}

.event-card .action-row {
  display: grid;
  grid-template-columns: auto 72px minmax(96px, 1fr);
  align-items: center;
  column-gap: 12px;
  row-gap: 10px;
}

.mob-card .action-row {
  display: grid;
  grid-template-columns: minmax(54px, auto) 64px minmax(82px, 1fr);
  align-items: center;
  column-gap: 10px;
  row-gap: 10px;
}

.mob-card .action-row label,
.event-card .action-row label {
  min-width: 0;
  color: var(--text);
}

.mob-card .action-row label {
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
}

.mob-card .action-row .btn,
.event-card .action-row .btn {
  width: 100%;
  min-width: 0;
  padding-inline: 12px;
}

.number-input {
  width: 72px;
  min-width: 0;
  text-align: center;
}

.mob-card .number-input {
  width: 64px;
}

.gift-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

.gift-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  object-fit: contain;
}

.gift-desc {
  min-height: 42px;
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.event-card {
  display: flex;
  flex-direction: column;
}

.event-card .action-row {
  margin-top: auto;
}

.arena-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
}

.arena-card {
  display: grid;
  gap: 8px;
  border: 1px solid #e4dfd6;
  border-radius: 18px;
  background: #fdfcf9;
  padding: 12px;
  cursor: pointer;
}

.arena-card[data-status="busy"] {
  cursor: not-allowed;
  opacity: 0.78;
}

.arena-image {
  height: 110px;
  object-fit: contain;
  justify-self: center;
}

.arena-status {
  margin-left: auto;
  padding: 4px 10px;
  background: rgba(110, 110, 110, 0.15);
  color: #6e6e6e;
}

.arena-card[data-status="free"] .arena-status {
  color: #3aa56d;
  background: rgba(58, 165, 109, 0.18);
}

.arena-card[data-status="busy"] .arena-status {
  color: #d45252;
  background: rgba(212, 82, 82, 0.18);
}

.card-hint {
  color: #8b8378;
  text-align: right;
  font-weight: 700;
}

.wide-action {
  width: 168px;
}

.input-row input {
  flex: 1;
}

.align-start {
  align-items: flex-start;
}

.tiktok-page {
  gap: 22px;
}

.tiktok-page-header {
  display: grid;
  gap: 12px;
  margin-bottom: 6px;
}

.tiktok-page-header h1 {
  margin-bottom: 8px;
}

.tiktok-page-header .page-description {
  margin: 0;
}

.tiktok-section-card {
  min-width: 0;
  display: grid;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.section-title {
  margin: 0;
  font-size: 20px;
}

.section-description {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.listener-form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  align-items: center;
  gap: 14px;
}

.listener-form-row input,
.listener-form-row button {
  width: 100%;
  min-width: 0;
}

.listener-meta {
  display: grid;
  gap: 10px;
  margin-top: 2px;
}

.target-line {
  font-weight: 700;
}

.helper-text,
.logging-hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.logging-action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.logging-action-row button {
  min-width: 180px;
}

.live-events-panel {
  min-height: 320px;
  max-height: 420px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #ece7df;
  border-radius: 14px;
  background: #fdfcf9;
  padding: 16px;
}

.live-events-panel:not(.empty) {
  display: block;
}

.live-events-empty {
  max-width: 560px;
  padding: 24px;
  text-align: center;
}

.live-events-empty-icon {
  margin: 0 auto 14px;
}

.live-events-empty-title {
  display: block;
  margin-bottom: 12px;
  font-weight: 800;
}

.live-events-empty-description {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.events-body {
  min-height: 260px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid #ece7df;
  border-radius: 12px;
  background: #fdfcf9;
  padding: 12px;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  text-align: center;
  color: #7a746b;
}

.empty-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 19px;
  background: #ece7df;
  color: #8d867a;
  font-size: 11px;
  font-weight: 800;
}

.event-line {
  padding: 8px 10px;
  border-radius: 8px;
  background: #f2f2f2;
  margin-bottom: 8px;
  word-break: break-word;
}

.event-line.error,
.feedback.error {
  color: #b83a3a;
}

.overlay-preview {
  display: grid;
  justify-items: center;
}

.phone-preview {
  width: min(620px, 100%);
  min-height: 560px;
  border-radius: 24px;
  background: linear-gradient(135deg, #252629, #18191c);
  color: #ffffff;
  padding: 22px;
}

.overlay-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 12px;
}

.overlay-tile {
  border: 1px solid #3a3c42;
  border-radius: 10px;
  background: #242529;
  padding: 10px;
  display: grid;
  gap: 6px;
  min-height: 116px;
}

.overlay-tile img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.overlay-tile span {
  color: #c8cad1;
  font-size: 11px;
}

.help-grid {
  display: grid;
  gap: 12px;
}

.help-card p {
  color: var(--muted);
}

.help-dialog {
  width: min(640px, calc(100vw - 32px));
  border: none;
  border-radius: 18px;
  padding: 20px;
  background: #fbf8f4;
}

.help-dialog::backdrop {
  background: rgba(47, 42, 35, 0.32);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}

@media (max-width: 1200px) {
  .body-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

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

@media (max-width: 860px) {
  .body-shell {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .sidebar {
    align-items: center;
  }

  .brand,
  .nav-button span,
  .language-block,
  .logout span {
    display: none;
  }

  .nav-button {
    width: 48px;
    justify-content: center;
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-left {
    flex-wrap: wrap;
  }

  .arena-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .tiktok-section-card {
    padding: 18px;
  }

  .section-header {
    flex-direction: column;
    gap: 12px;
  }

  .listener-form-row {
    grid-template-columns: 1fr;
  }

  .logging-action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .logging-action-row button {
    width: 100%;
    min-width: 0;
  }

  .live-events-panel {
    min-height: 280px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    height: 100vh;
    grid-template-rows: auto 1fr auto;
  }

  .body-shell {
    height: auto;
    display: flex;
    flex-direction: column-reverse;
  }

  .main-content {
    height: auto;
    min-height: 0;
  }

  .sidebar {
    position: sticky;
    bottom: 0;
    top: auto;
    height: auto;
    overflow: visible;
    z-index: 20;
    flex-direction: row;
    justify-content: space-around;
    border-top: 1px solid #e9e3d7;
    border-right: none;
    padding: 8px;
  }

  .nav-list {
    display: contents;
  }

  .sidebar-spacer,
  .logout {
    display: none;
  }

  .nav-button {
    width: 44px;
    height: 44px;
    padding: 10px;
  }

  .topbar {
    display: grid;
    gap: 10px;
    padding: 10px 12px;
  }

  .topbar-left,
  .topbar-right {
    width: 100%;
  }

  .topbar-right {
    justify-content: flex-end;
  }

  .mob-grid,
  .event-grid {
    grid-template-columns: 1fr;
  }

  .mob-card .action-row,
  .event-card .action-row {
    grid-template-columns: auto 72px minmax(96px, 1fr);
  }

  .server-title {
    font-size: 17px;
  }

  .arena-chip {
    margin-left: 0;
    font-size: 12px;
  }

  .page {
    padding: 16px 14px 84px;
    gap: 14px;
  }

  .auth-card h1,
  .waiting-content h1,
  .page h1 {
    font-size: 24px;
  }

  .button-grid.two,
  .mob-grid,
  .event-grid,
  .arena-grid {
    grid-template-columns: 1fr;
  }

  .input-row,
  .action-row {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .input-row > *,
  .action-row .btn,
  .wide-action,
  .gift-trigger {
    width: 100%;
  }

  .action-row label {
    width: auto;
  }

  .number-input {
    flex: 1;
    min-width: 86px;
  }

  .card-header {
    display: grid;
  }

  .panel-card,
  .help-card {
    padding: 16px;
  }

  .phone-preview {
    min-height: 460px;
    padding: 16px;
  }

  .help-float {
    top: 14px;
    right: 14px;
  }
}
