* {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Kufi Arabic", "Noto Naskh Arabic", sans-serif;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #020617, #020617 35%, #000000 100%);
  color: #f9fafb;
  direction: rtl;
}

#app {
  max-width: 1150px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Top bar */

.top-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.top-bar h1 {
  margin: 0;
  font-size: 2.3rem;
  letter-spacing: 0.06em;
}

.top-tag {
  font-size: 0.85rem;
  opacity: 0.85;
  background: rgba(15, 23, 42, 0.96);
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid rgba(51, 65, 85, 0.75);
}

/* Panels */

.panel {
  position: relative;
  background: radial-gradient(circle at top right, #020617, #020617 40%, #000 100%);
  border-radius: 28px;
  padding: 20px 22px 24px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(30, 64, 175, 0.4);
  overflow: hidden;
}

/* glowing tiles background */
.panel::before {
  content: "";
  position: absolute;
  inset: -60px;
  background:
    radial-gradient(circle at 10% 20%, rgba(56, 189, 248, 0.18) 0, transparent 55%),
    radial-gradient(circle at 80% 80%, rgba(52, 211, 153, 0.18) 0, transparent 55%),
    linear-gradient(
      135deg,
      rgba(15, 23, 42, 0.3) 0,
      rgba(15, 23, 42, 0.7) 45%,
      rgba(15, 23, 42, 0.3) 100%
    ),
    repeating-linear-gradient(
      45deg,
      rgba(30, 64, 175, 0.5) 0,
      rgba(30, 64, 175, 0.5) 1px,
      transparent 1px,
      transparent 26px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(15, 23, 42, 0.7) 0,
      rgba(15, 23, 42, 0.7) 1px,
      transparent 1px,
      transparent 26px
    );
  opacity: 0.28;
  mix-blend-mode: screen;
  pointer-events: none;
}

/* keep inside content above tiles */
.panel > * {
  position: relative;
  z-index: 1;
}

.panel-center {
  text-align: center;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.section-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.section-header p {
  margin: 0;
  opacity: 0.8;
  font-size: 0.9rem;
}

/* Buttons */

.btn {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.95rem;
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.1s ease,
    background 0.12s ease;
  white-space: nowrap;
}

.btn-primary {
  background: radial-gradient(circle at 0 0, #22c55e, #16a34a);
  color: #022c22;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(34, 197, 94, 0.55);
}

.btn-ghost {
  background: rgba(15, 23, 42, 0.96);
  color: #e5e7eb;
  border: 1px solid rgba(148, 163, 184, 0.7);
}

.btn-chrome {
  background: rgba(15, 23, 42, 0.94);
  color: #e5e7eb;
  border: 1px solid rgba(55, 65, 81, 0.9);
}

.btn.small {
  font-size: 0.83rem;
  padding: 5px 11px;
}

.btn.wide {
  width: 100%;
}

.btn:hover {
  opacity: 0.98;
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.9);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.back-btn {
  margin-bottom: 12px;
}

/* Mode screen */

.mode-subtitle {
  max-width: 560px;
  margin: 8px auto 18px;
  opacity: 0.8;
}

.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}

.hint {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* Form & controls row */

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 6px 0 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(51, 65, 85, 0.9);
  font-size: 0.88rem;
}

select {
  border-radius: 999px;
  border: none;
  padding: 4px 12px;
  background: rgba(15, 23, 42, 0.98);
  color: #e5e7eb;
  font-size: 0.86rem;
}

select:focus {
  outline: none;
  box-shadow: 0 0 0 1px #22c55e;
}

.multi-config {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
}

input {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.75);
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.96);
  color: #f9fafb;
}

input::placeholder {
  color: rgba(148, 163, 184, 0.9);
}

/* Game layouts */

/* two-column layout for desktop: left = game tiles, right = info/controls */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.9fr);
  gap: 18px;
  margin-top: 8px;
}

/* single-player: board+keyboard stacked in left column to look like a “tile area” */
#single-screen .game-layout {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
}

/* put board+keyboard in a glowing tile shell */
.board-wrapper {
  position: relative;
  padding: 18px 18px 14px;
  border-radius: 24px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(30, 64, 175, 0.8);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

/* faint inner tile grid */
.board-wrapper::before {
  content: "";
  position: absolute;
  inset: 10px 8px;
  border-radius: 20px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(30, 64, 175, 0.18) 0,
      rgba(30, 64, 175, 0.18) 1px,
      transparent 1px,
      transparent 32px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(15, 23, 42, 0.65) 0,
      rgba(15, 23, 42, 0.65) 1px,
      transparent 1px,
      transparent 32px
    );
  opacity: 0.28;
  pointer-events: none;
}

.board-wrapper > * {
  position: relative;
  z-index: 1;
}

/* Right info column (status + anything else) */
.game-layout .status {
  margin-top: 4px;
}

/* Board */

.board {
  display: grid;
  justify-content: center;
  gap: 7px;
  margin-top: 4px;
}

.board-row {
  display: grid;
  grid-auto-flow: column;
  gap: 7px;
}

.board-cell {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: 2px solid rgba(51, 65, 85, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 600;
  background: radial-gradient(circle at top, #020617, #020617 60%, #020617);
  color: #e5e7eb;
  transition: background 0.12s ease, border-color 0.12s ease,
    transform 0.08s ease;
}

.board-cell.filled {
  border-color: rgba(148, 163, 184, 0.98);
}

.board-cell.reveal {
  transform: scale(1.04);
}

/* Tile colors */

.board-cell.correct {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-color: #22c55e;
  color: #022c22;
}

.board-cell.present {
  background: linear-gradient(135deg, #facc15, #eab308);
  border-color: #facc15;
  color: #1f2937;
}

.board-cell.absent {
  background: #020617;
  border-color: #020617;
  color: #6b7280;
}

/* Status */

.status {
  min-height: 24px;
  font-size: 0.9rem;
  text-align: center;
  opacity: 0.96;
}

.status.error {
  color: #fb7185;
}

.status.success {
  color: #4ade80;
}

/* Keyboard */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 10px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.key {
  min-width: 34px;
  padding: 7px 11px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: radial-gradient(circle at 0 0, #2563eb, #1d4ed8);
  color: #e5e7eb;
  font-size: 1rem;
  font-weight: 500;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.9);
}

.key-large {
  min-width: 60px;
  font-size: 0.82rem;
}

.key.correct {
  background: linear-gradient(135deg, #22c55e, #16a34a);
}

.key.present {
  background: linear-gradient(135deg, #facc15, #eab308);
  color: #111827;
}

.key.absent {
  background: #020617;
  color: #9ca3af;
  box-shadow: none;
}

.key:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* Side / feed (multiplayer) */

.side-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-block {
  background: rgba(15, 23, 42, 0.96);
  border-radius: 18px;
  padding: 8px 10px;
  border: 1px solid rgba(51, 65, 85, 0.9);
}

.side-block h3 {
  font-size: 0.9rem;
  margin: 0 0 6px;
  opacity: 0.9;
}

.feed {
  max-height: 150px;
  overflow-y: auto;
  font-size: 0.8rem;
}

.feed-entry {
  padding: 4px 0;
  border-bottom: 1px dashed rgba(55, 65, 81, 0.7);
}

.feed-entry:last-child {
  border-bottom: none;
}

/* Room info */

.room-info {
  margin: 8px 0 6px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(55, 65, 81, 0.95);
  font-size: 0.86rem;
}

/* Helper */

.hidden {
  display: none !important;
}

/* Modal + Stats */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  z-index: 31;
  background: rgba(15, 23, 42, 0.98);
  border-radius: 22px;
  padding: 16px 16px 18px;
  width: 100%;
  max-width: 430px;
  border: 1px solid rgba(148, 163, 184, 0.75);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.85);
}

.modal-content h3 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 10px;
}

.stat-item {
  text-align: center;
  padding: 6px;
  background: rgba(15, 23, 42, 0.96);
  border-radius: 14px;
  border: 1px solid rgba(51, 65, 85, 0.95);
}

.stat-number {
  font-size: 1.2rem;
  font-weight: 600;
}

.stat-label {
  font-size: 0.75rem;
  opacity: 0.8;
}

.stats-section h4 {
  margin: 6px 0 4px;
  font-size: 0.9rem;
}

.attempts-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.attempts-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(55, 65, 81, 0.7);
}

.attempts-list li:last-child {
  border-bottom: none;
}

/* Mobile tweaks */

body.mobile #app {
  padding: 10px 8px 24px;
}

body.mobile .top-bar h1 {
  font-size: 1.7rem;
}

body.mobile .panel {
  padding: 14px 12px 18px;
  border-radius: 22px;
}

body.mobile .top-tag {
  display: none;
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .board-wrapper {
    margin-bottom: 10px;
  }
}

@media (max-width: 720px) {
  .board-cell {
    width: 46px;
    height: 46px;
    font-size: 1.35rem;
  }

  .keyboard-row {
    flex-wrap: wrap;
  }

  .side-column {
    flex-direction: column-reverse;
  }

  .modal-content {
    margin: 0 12px;
  }
}
