/* ==========================================================================
   MahjongOnline.co.uk — Responsive Mobile & Desktop Layout Styles
   ========================================================================== */

:root {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, Cambria, 'Times New Roman', Times, serif;

  /* Primary Theme Colors */
  --bg-primary: #0a101d;
  --bg-surface: #111a2e;
  --bg-surface-elevated: #1a2744;
  --border-subtle: #233559;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --accent-gold: #f59e0b;
  --accent-gold-hover: #d97706;
  --accent-emerald: #10b981;
  --accent-crimson: #ef4444;
  --accent-blue: #3b82f6;

  --max-content-width: 1200px;
}

/* Base Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.6;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent-gold);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: #fbbf24;
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Header & Navigation
   -------------------------------------------------------------------------- */
.site-header {
  width: 100%;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.header-container {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 0.6rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.logo-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}

.logo-link:hover {
  text-decoration: none;
  color: var(--accent-gold);
}

.logo-badge {
  font-size: 0.68rem;
  font-weight: 700;
  background-color: var(--accent-gold);
  color: #000000;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.nav-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
  min-height: 36px;
  white-space: nowrap;
}

.nav-btn:hover {
  background: #24355a;
  border-color: var(--accent-gold);
  color: #ffffff;
}

.nav-btn.active {
  background: var(--accent-gold);
  color: #000000;
  border-color: var(--accent-gold);
}

/* Mobile Header (< 640px) */
@media (max-width: 640px) {
  .site-header {
    width: 100%;
    overflow: hidden;
  }
  .header-container {
    padding: 0.35rem 0.5rem;
    gap: 0.25rem;
    width: 100%;
    box-sizing: border-box;
  }
  .logo-link {
    font-size: 0.95rem;
    gap: 0.3rem;
  }
  .logo-link svg {
    width: 22px;
    height: 28px;
  }
  .logo-desktop-text {
    display: none !important;
  }
  .logo-badge {
    display: none !important;
  }
  .nav-controls {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
  }
  .nav-btn {
    padding: 0;
    width: 32px;
    height: 32px;
    min-height: 32px;
    min-width: 32px;
    border-radius: 7px;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .nav-btn .btn-label {
    display: none !important;
  }
}

/* --------------------------------------------------------------------------
   Game Status Bar & Control Toolbar
   -------------------------------------------------------------------------- */
.game-section {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0.5rem auto 1.5rem;
  padding: 0 0.5rem;
}

@media (max-width: 480px) {
  .game-section {
    padding: 0 0.25rem;
    margin-top: 0.25rem;
  }
}

.game-toolbar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.55rem;
}

@media (min-width: 768px) {
  .game-toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0.85rem;
  }
}

/* Compact Stats Row */
.game-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  width: 100%;
}

@media (min-width: 768px) {
  .game-stats {
    display: flex;
    width: auto;
    gap: 0.75rem;
  }
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  background: var(--bg-surface-elevated);
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

.stat-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 800;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.stat-value.highlight {
  color: var(--accent-gold);
}

/* 4-in-a-row Action Buttons (Never Wrap on Mobile) */
.game-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  width: 100%;
}

@media (min-width: 768px) {
  .game-actions {
    display: flex;
    width: auto;
    gap: 0.5rem;
  }
}

.action-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: #ffffff;
  padding: 0.45rem 0.25rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: all 0.15s ease;
  user-select: none;
  min-height: 38px;
  white-space: nowrap;
}

.action-btn:hover:not(:disabled) {
  background: #253760;
  border-color: var(--accent-gold);
  transform: translateY(-1px);
}

.action-btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.action-btn.primary {
  background: var(--accent-gold);
  color: #000000;
  border-color: var(--accent-gold);
}

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

@media (max-width: 480px) {
  .action-btn {
    font-size: 0.76rem;
    padding: 0.4rem 0.2rem;
  }
  .action-btn .shortcut {
    display: none !important;
  }
}

/* --------------------------------------------------------------------------
   Editorial Content Section (Below the Game Board)
   -------------------------------------------------------------------------- */
.editorial-container {
  max-width: 900px;
  margin: 2.5rem auto 2rem;
  padding: 0 1rem;
}

.editorial-header {
  text-align: center;
  margin-bottom: 2rem;
}

.editorial-header h1 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 0.65rem;
  color: #ffffff;
}

.editorial-header p {
  color: var(--text-muted);
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
}

.content-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: clamp(1.2rem, 3vw, 2rem);
  margin-bottom: 1.5rem;
}

.content-card h2 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.content-card h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-gold);
  margin: 1.25rem 0 0.5rem;
}

.content-card p {
  color: #d1d5db;
  margin-bottom: 1rem;
  font-size: 0.96rem;
  line-height: 1.7;
}

.content-card ul, .content-card ol {
  color: #d1d5db;
  padding-left: 1.5rem;
  margin-bottom: 1.25rem;
}

.content-card li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

/* Tile Suit Showcase Grid */
.suits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.suit-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1.15rem;
}

.suit-card h4 {
  color: #ffffff;
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}

.suit-card p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

/* FAQ Accordion */
.faq-item {
  border-bottom: 1px solid var(--border-subtle);
  padding: 1.15rem 0;
}

.faq-item:last-child {
  border-bottom: none;
}

.faq-question {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.faq-answer {
  color: #d1d5db;
  margin-top: 0.65rem;
  line-height: 1.65;
  font-size: 0.95rem;
}

/* --------------------------------------------------------------------------
   Modern Modal Dialogs (Native Web Guidance)
   -------------------------------------------------------------------------- */
dialog:modal {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 500px;
  width: 92vw;
  margin: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.75);
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(5, 10, 20, 0.75);
  backdrop-filter: blur(6px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-header h2 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
}

.close-btn:hover {
  color: #ffffff;
  background: var(--bg-surface-elevated);
}

.modal-body {
  margin-bottom: 1.5rem;
  line-height: 1.6;
  color: #d1d5db;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* Victory Modal Highlights */
.victory-card {
  text-align: center;
  padding: 0.5rem 0;
}

.victory-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  animation: bounce 1s infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

.victory-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent-gold);
  margin-bottom: 0.5rem;
}

.victory-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.v-stat {
  background: var(--bg-surface-elevated);
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
}

.v-stat .label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.v-stat .val {
  font-size: 1.2rem;
  font-weight: 800;
  color: #ffffff;
}

/* Enhanced Dialog Sizing */
dialog#statsModal {
  max-width: 580px;
  width: 95vw;
}

/* Daily Challenge Card */
.daily-status-card {
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.12), rgba(16, 185, 129, 0.08));
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.daily-status-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.daily-status-title {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--accent-gold);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.daily-status-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.daily-streak-badge {
  background: rgba(212, 175, 55, 0.2);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  font-size: 0.85rem;
  font-weight: 800;
  padding: 0.35rem 0.65rem;
  border-radius: 20px;
  white-space: nowrap;
}

/* Personal Records / Leaderboard Table */
.stats-section-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: #ffffff;
  margin: 1.25rem 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.records-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-surface-elevated);
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  text-align: left;
}

.records-table th {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  letter-spacing: 0.04em;
}

.records-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}

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

.records-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.records-table .rank-cell {
  font-weight: 800;
  width: 36px;
}

.records-table .time-cell {
  font-weight: 800;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.rank-gold { color: #f59e0b; }
.rank-silver { color: #9ca3af; }
.rank-bronze { color: #b45309; }

.badge-mode {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-mode-daily {
  background: rgba(212, 175, 55, 0.2);
  color: var(--accent-gold);
}

.badge-mode-classic {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.empty-records {
  text-align: center;
  padding: 1.25rem;
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.85rem;
}

/* Button variants */
.action-btn.btn-share {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border-color: #34d399;
}

.action-btn.btn-share:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.action-btn.btn-danger {
  background: transparent;
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
  font-size: 0.8rem;
  padding: 0.45rem 0.75rem;
}

.action-btn.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
}

/* Floating Toast Notification */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  opacity: 0;
  background: #111e18;
  color: #f8fafc;
  border: 1px solid var(--accent-gold);
  border-radius: 30px;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.7), 0 0 15px rgba(212, 175, 55, 0.25);
  z-index: 9999;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease-out;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast-container.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Layout Selector Modal & Cards */
dialog#layoutModal {
  max-width: 520px;
  width: 94vw;
}

.layout-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.layout-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: 12px;
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  width: 100%;
}

.layout-card:hover {
  border-color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.08);
  transform: translateY(-1px);
}

.layout-card.active {
  border-color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.14);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.2);
}

.layout-card-icon {
  font-size: 2rem;
  flex-shrink: 0;
  line-height: 1;
}

.layout-card-info {
  flex: 1;
}

.layout-card-title {
  font-weight: 800;
  font-size: 1rem;
  color: #ffffff;
}

.layout-card.active .layout-card-title {
  color: var(--accent-gold);
}

.layout-card-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
  line-height: 1.35;
}

.layout-card-badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.2);
  border: 1px solid rgba(212, 175, 55, 0.5);
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.site-footer {
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 2rem 1rem;
  margin-top: auto;
}

.footer-container {
  max-width: var(--max-content-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  justify-content: center;
  font-size: 0.88rem;
}

.footer-nav a {
  color: var(--text-muted);
}

.footer-nav a:hover {
  color: #ffffff;
}

.footer-copy {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
}
