:root {
  color-scheme: dark;
  --bg: #0d1b2a;
  --panel: #13283c;
  --panel-2: #173753;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f8fbff;
  --muted: rgba(248, 251, 255, 0.68);
  --primary: #00a6a6;
  --accent: #f2c14e;
  --danger: #ef476f;
  --success: #2fbf71;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
  font-family: Inter, Segoe UI, Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

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

a {
  color: inherit;
}

.shell {
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(0, 166, 166, 0.12), transparent 34%),
    radial-gradient(circle at 78% 18%, rgba(242, 193, 78, 0.13), transparent 28%),
    var(--bg);
}

.topbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 54px);
}

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

.mark {
  align-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 8px;
  color: #07131e;
  display: grid;
  font-weight: 900;
  height: 40px;
  place-items: center;
  width: 40px;
}

.brand-mark strong {
  display: block;
  font-size: 17px;
  line-height: 1.1;
}

.brand-mark span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.nav {
  display: flex;
  gap: 8px;
}

.nav button,
.icon-btn,
.primary-btn,
.secondary-btn,
.danger-btn {
  align-items: center;
  border-radius: 8px;
  display: inline-flex;
  font-weight: 750;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
}

.nav button,
.secondary-btn,
.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
}

.nav button.active,
.primary-btn {
  background: var(--primary);
  color: #061417;
}

.danger-btn {
  background: rgba(239, 71, 111, 0.18);
  border: 1px solid rgba(239, 71, 111, 0.5);
  color: #ffdbe4;
}

.content {
  padding: 24px clamp(18px, 4vw, 54px) 48px;
}

.admin-layout {
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr);
}

.panel {
  background: rgba(19, 40, 60, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  min-height: 66px;
  padding: 14px 16px;
}

.panel-head h2,
.section-title h2,
.game-title {
  font-size: 22px;
  letter-spacing: 0;
  line-height: 1.15;
  margin: 0;
}

.panel-head p,
.section-title p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
}

.theme-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.theme-row {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  display: block;
  padding: 12px;
  text-align: left;
}

.theme-row.active {
  border-color: var(--primary);
  background: rgba(0, 166, 166, 0.14);
}

.theme-row strong {
  display: block;
  line-height: 1.2;
}

.theme-row span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 12px 0;
}

.tabs button {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  min-height: 42px;
  padding: 0 14px;
}

.tabs button.active {
  background: rgba(0, 166, 166, 0.16);
  border-color: var(--primary);
  color: var(--text);
}

.form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 16px;
}

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

.field {
  display: grid;
  gap: 8px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label,
.mini-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  min-height: 42px;
  padding: 10px 11px;
  width: 100%;
}

.field select option {
  background: #13283c;
  color: #f8fbff;
}

.field textarea {
  min-height: 90px;
  resize: vertical;
}

.field input[type="color"] {
  padding: 4px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.upload-spec {
  color: rgba(248, 251, 255, 0.62);
  font-size: 12px;
  line-height: 1.35;
}

.actions {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 16px;
}

.cards-editor,
.fields-editor {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.card-line,
.field-line {
  align-items: center;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 70px minmax(130px, 1fr) minmax(190px, 1.4fr) 42px;
  padding: 10px;
}

.card-pair-line.single {
  grid-template-columns: auto minmax(130px, 1fr) minmax(190px, 1.4fr) 42px;
}

.card-pair-line.dual {
  grid-template-columns: auto auto minmax(130px, 1fr) minmax(190px, 1.25fr) minmax(190px, 1.25fr) 42px;
}

.field-line {
  grid-template-columns: minmax(150px, 1fr) 130px 110px 42px;
}

.thumb {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  overflow: hidden;
  place-items: center;
}

.thumb img {
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.upload-preview {
  align-items: center;
  aspect-ratio: 1;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.035));
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  font-size: 12px;
  justify-items: center;
  overflow: hidden;
  padding: 0;
  position: relative;
  width: fit-content;
}

.upload-preview img,
.upload-preview video {
  height: auto;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
  width: auto;
}

.upload-preview span {
  padding: 12px;
  text-align: center;
}

.upload-preview::after {
  background: rgba(5, 12, 20, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  bottom: 8px;
  color: rgba(248, 251, 255, 0.88);
  content: attr(data-size);
  font-size: 11px;
  font-weight: 750;
  left: 8px;
  line-height: 1.2;
  padding: 5px 7px;
  position: absolute;
  right: 8px;
  text-align: center;
}

.upload-preview-logo {
  aspect-ratio: 2 / 1;
  height: 130px;
  width: 260px;
}

.upload-preview-screen {
  aspect-ratio: 9 / 16;
  height: 360px;
  width: 203px;
}

.upload-preview-square {
  aspect-ratio: 1;
  height: 70px;
  width: 70px;
}

.upload-preview-card {
  aspect-ratio: var(--preview-ratio, 1);
  height: 128px;
  max-width: 240px;
}

.field > .upload-preview-card {
  height: 180px;
  max-width: 330px;
}

.field > .upload-preview-square {
  height: 170px;
  width: 170px;
}

.upload-preview-audio {
  aspect-ratio: auto;
  height: 82px;
  width: 280px;
}

.upload-preview-audio::after {
  content: attr(data-size);
}

.leader-tools {
  align-items: center;
  display: flex;
  gap: 10px;
}

.stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 16px;
}

.stat {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  font-size: 30px;
  margin-top: 8px;
}

.table-wrap {
  overflow: auto;
  padding: 0 16px 16px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.pill.win {
  background: rgba(47, 191, 113, 0.18);
  color: #bfffd8;
}

.pill.played {
  background: rgba(242, 193, 78, 0.16);
  color: #ffe8a6;
}

.game-shell {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  height: 100vh;
  height: 100dvh;
  isolation: isolate;
  min-height: 0;
  overflow: hidden;
  position: relative;
  touch-action: manipulation;
  user-select: none;
}

.game-shell * {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-drag: none;
  user-select: none;
}

.game-shell input,
.game-shell textarea,
.game-shell select {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  touch-action: manipulation;
  user-select: text;
}

.game-shell img,
.game-shell video {
  -webkit-user-drag: none;
  pointer-events: none;
  user-drag: none;
}

.game-shell::before {
  background:
    linear-gradient(180deg, rgba(4, 10, 18, 0.46), rgba(4, 10, 18, 0.72)),
    radial-gradient(circle at 50% 14%, rgba(255, 255, 255, 0.12), transparent 42%);
  content: "";
  inset: 0;
  position: fixed;
  z-index: -1;
}

.game-shell.has-intro-video::before {
  background: transparent;
}

.game-bg {
  background-position: center;
  background-size: cover;
  inset: 0;
  position: fixed;
  z-index: -3;
}

.game-bg-video {
  height: 100%;
  inset: 0;
  object-fit: cover;
  position: fixed;
  width: 100%;
  z-index: -2;
}

.game-bg::after {
  background:
    linear-gradient(180deg, rgba(4, 10, 18, 0.62), rgba(4, 10, 18, 0.82)),
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.12), transparent 40%);
  content: "";
  inset: 0;
  position: absolute;
}

.game-stage {
  display: grid;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: clamp(18px, 3vh, 32px) clamp(22px, 4vw, 70px);
}

.theme-picker {
  align-self: center;
  display: grid;
  gap: 24px;
}

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

.game-header .logo-img {
  border-radius: 8px;
  max-height: 72px;
  max-width: 180px;
  object-fit: contain;
}

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

.theme-card {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  min-height: 190px;
  overflow: hidden;
  padding: 18px;
  position: relative;
  text-align: left;
}

.theme-card::before {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  content: "";
  height: 8px;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}

.theme-card h3 {
  font-size: 25px;
  margin: 14px 0 8px;
}

.theme-card p {
  color: var(--muted);
  margin: 0;
}

.setup-card,
.result-card,
.intro-card {
  align-self: center;
  background: rgba(12, 24, 37, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  justify-self: center;
  max-width: 720px;
  padding: 26px;
  width: min(720px, 100%);
}

.intro-card {
  position: relative;
}

.intro-flow {
  align-self: center;
  display: grid;
  justify-items: center;
}

.is-hidden {
  display: none !important;
}

.intro-media {
  border-radius: 8px;
  max-height: 46vh;
  object-fit: contain;
  width: 100%;
}

.event-wait {
  display: grid;
  gap: 16px;
}

.event-finish-hotspot {
  background: rgba(239, 71, 111, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  height: 34px;
  opacity: 0.12;
  position: absolute;
  right: 10px;
  top: 10px;
  transition:
    opacity 160ms ease,
    background 160ms ease;
  width: 34px;
}

.event-finish-hotspot:focus-visible,
.event-finish-hotspot:hover {
  background: rgba(239, 71, 111, 0.82);
  opacity: 1;
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}

.event-finish-hotspot::before,
.event-finish-hotspot::after {
  background: #fff;
  border-radius: 2px;
  content: "";
  height: 2px;
  left: 9px;
  position: absolute;
  top: 16px;
  width: 14px;
}

.event-finish-hotspot::before {
  transform: rotate(45deg);
}

.event-finish-hotspot::after {
  transform: rotate(-45deg);
}

.board-screen {
  display: grid;
  gap: 16px;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.hud {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr auto;
}

.hud-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.hud-box {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  min-width: 120px;
  padding: 10px 14px;
  text-align: center;
}

.hud-box span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  text-transform: uppercase;
}

.hud-box strong {
  display: block;
  font-size: 24px;
  margin-top: 3px;
}

.board-wrap {
  align-items: center;
  display: grid;
  min-height: 0;
  overflow: hidden;
}

.board {
  aspect-ratio: var(--board-ratio, 1);
  display: grid;
  gap: clamp(8px, 1vw, 16px);
  justify-self: center;
  max-width: 1680px;
  width: min(100%, var(--board-width, 100%));
}

@media (orientation: portrait) {
  .game-stage {
    padding: clamp(16px, 2vh, 34px) clamp(14px, 2.4vw, 28px);
  }

  .game-shell .game-title {
    font-size: clamp(36px, 6vw, 66px);
  }

  .game-shell .game-header p {
    font-size: clamp(18px, 2.4vw, 28px);
  }

  .game-shell .primary-btn,
  .game-shell .secondary-btn,
  .game-shell .danger-btn {
    border-radius: 8px;
    font-size: clamp(22px, 2.8vw, 34px);
    min-height: 72px;
    padding: 0 30px;
  }

  .intro-card,
  .setup-card,
  .result-card {
    max-width: min(860px, 100%);
    padding: clamp(24px, 4vw, 44px);
  }

  .intro-card h2,
  .setup-card h2,
  .result-card h2 {
    font-size: clamp(34px, 6vw, 64px);
  }

  .intro-card p,
  .setup-card p,
  .result-card p {
    font-size: clamp(18px, 2.2vw, 28px);
  }

  .intro-media {
    max-height: 52vh;
  }

  .game-shell .form-grid {
    grid-template-columns: 1fr;
  }

  .game-shell .field label {
    font-size: 18px;
  }

  .game-shell .field input,
  .game-shell .field select {
    font-size: 28px;
    min-height: 76px;
    padding: 14px 18px;
  }

  .board {
    gap: clamp(7px, 1vw, 12px);
    width: min(100%, var(--board-width, 100%));
  }
}

@media (orientation: portrait) and (min-height: 1400px) {
  .game-stage {
    padding: 28px 24px;
  }

  .theme-picker {
    align-self: start;
    gap: 42px;
    padding-top: 120px;
  }

  .theme-grid {
    gap: 22px;
    grid-template-columns: 1fr;
  }

  .theme-card {
    min-height: 230px;
    padding: 34px;
  }

  .theme-card h3 {
    font-size: 44px;
    margin: 16px 0 12px;
  }

  .theme-card p {
    font-size: 24px;
  }

  .intro-card,
  .setup-card,
  .result-card {
    max-width: 930px;
    padding: 54px;
  }

  .intro-media {
    max-height: 980px;
  }

  .event-wait {
    gap: 26px;
  }

  .event-finish-hotspot {
    height: 44px;
    right: 14px;
    top: 14px;
    width: 44px;
  }

  .event-finish-hotspot::before,
  .event-finish-hotspot::after {
    left: 12px;
    top: 21px;
    width: 18px;
  }

  .board-screen {
    gap: 16px;
  }

  .hud {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .hud-stats {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }

  .hud-box {
    min-width: 0;
    padding: 12px;
  }

  .hud-box span {
    font-size: 16px;
  }

  .hud-box strong {
    font-size: 34px;
  }

  .board {
    gap: 10px;
    width: min(100%, var(--board-width, 100%));
  }

  .card-back {
    font-size: clamp(28px, 5vw, 58px);
  }

  .promo {
    font-size: clamp(36px, 5.4vw, 64px);
    padding: 24px;
  }
}

@media (orientation: landscape) {
  .board {
    width: min(100%, var(--board-width, 100%));
  }
}

.match-card {
  aspect-ratio: var(--card-ratio, 1);
  background: transparent;
  border: 0;
  display: block;
  min-height: 0;
  padding: 0;
  perspective: 1000px;
  touch-action: manipulation;
  width: 100%;
}

.match-card * {
  pointer-events: none;
}

.card-inner {
  -webkit-transform-style: preserve-3d;
  border-radius: 8px;
  box-shadow: 0 15px 28px rgba(0, 0, 0, 0.3);
  display: block;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(0.2, 0.72, 0.16, 1);
  will-change: transform;
  width: 100%;
}

.match-card.flipped .card-inner,
.match-card.matched .card-inner {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.match-card.just-matched .card-inner {
  animation: match-pop 820ms ease both;
}

.match-card.just-matched .card-front {
  box-shadow:
    0 0 0 5px rgba(242, 193, 78, 0.9) inset,
    0 0 34px rgba(242, 193, 78, 0.72);
}

@keyframes match-pop {
  0% {
    transform: rotateY(180deg) scale(1);
  }

  32% {
    transform: rotateY(180deg) scale(1.08);
  }

  56% {
    transform: rotateY(180deg) scale(0.98);
  }

  100% {
    transform: rotateY(180deg) scale(1);
  }
}

.card-face {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  display: grid;
  height: 100%;
  inset: 0;
  overflow: hidden;
  padding: clamp(8px, 1.1vw, 18px);
  place-items: center;
  position: absolute;
  transform: rotateY(0deg);
  width: 100%;
}

.card-back {
  z-index: 2;
}

.card-front {
  -webkit-transform: rotateY(180deg);
  background: #f7fafc;
  color: #07131e;
  transform: rotateY(180deg);
  z-index: 1;
}

.card-front img,
.card-back img {
  display: block;
  height: auto;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
  width: auto;
}

.card-title {
  font-size: clamp(18px, 2vw, 42px);
  font-weight: 900;
  padding: 10px;
  text-align: center;
}

.card-back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 12px, transparent 12px 24px),
    linear-gradient(135deg, var(--primary), var(--accent));
  color: #07131e;
  font-size: clamp(18px, 2vw, 44px);
  font-weight: 950;
}

.card-back-has-image {
  background: #101820;
  padding: 0;
}

.card-back-has-image img {
  height: auto;
  max-height: 100%;
  max-width: 100%;
  width: auto;
}

.result-card h2,
.setup-card h2,
.intro-card h2 {
  font-size: 34px;
  line-height: 1.1;
  margin: 0 0 12px;
}

.result-card p,
.setup-card p,
.intro-card p {
  color: var(--muted);
}

.promo {
  background: rgba(242, 193, 78, 0.16);
  border: 1px dashed rgba(242, 193, 78, 0.7);
  border-radius: 8px;
  color: #fff2bd;
  font-size: 28px;
  font-weight: 900;
  margin: 18px 0;
  padding: 16px;
  text-align: center;
}

.empty-state {
  color: var(--muted);
  padding: 28px 16px;
  text-align: center;
}

[dir="rtl"] {
  font-family: Tahoma, Arial, Helvetica, sans-serif;
}

[dir="rtl"] th,
[dir="rtl"] td,
[dir="rtl"] .theme-card,
[dir="rtl"] .theme-row {
  text-align: right;
}

@media (max-width: 900px) {
  .admin-layout,
  .form-grid,
  .form-grid.three,
  .hud {
    grid-template-columns: 1fr;
  }

  .topbar,
  .game-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-line,
  .field-line {
    grid-template-columns: 70px 1fr;
  }

  .card-line > :last-child,
  .field-line > :last-child {
    grid-column: 1 / -1;
  }

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

}
