﻿* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: #f5f5f5;
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body[data-theme='dark'] {
  background: #1a1a1a;
  color: #f5f5f5;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 2px solid #0FA8DB;
  background: #f5f5f5;
}

body.subpage header {
  min-height: 3.125rem;
}

body[data-theme='dark'] header {
  background: #2a2a2a;
  border-bottom-color: #0FA8DB;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.15em;
  font-size: 1.1rem;
  flex: 1;
  text-align: center;
  color: #0FA8DB;
}

@media (min-width: 601px) {
  .brand {
    font-size: 1.4rem;
  }
}

.header-left,
.header-right {
  display: flex;
  gap: 0.5rem;
}

main {
  margin-top: 3.5rem;
  padding: 1.5rem;
  padding-bottom: 5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 3.5rem - 4rem);
  position: relative;
  z-index: 2;
}

.game-layout {
  width: 100%;
  max-width: 1400px;
  display: grid;
  grid-template-columns: 180px minmax(0, 500px) 180px;
  justify-content: center;
  gap: 1.25rem;
  align-items: start;
}

.game-center {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ad-rail {
  display: none;
  position: sticky;
  top: 5.2rem;
  align-items: center;
}

.desktop-side-ad {
  width: 160px;
  min-height: 600px;
}

@media (min-width: 1200px) {
  .ad-rail {
    display: flex;
    flex-direction: column;
  }
}

@media (max-width: 1199px) {
  .game-layout {
    max-width: 500px;
    display: block;
  }
}

main.content {
  align-items: flex-start;
  text-align: left;
  width: 100%;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

body.subpage main.content {
  margin-top: 3.125rem;
  min-height: 0;
  padding-bottom: 5rem;
}

.subtitle {
  font-size: 0.95rem;
  color: #666;
  margin-bottom: 1.5rem;
  text-align: center;
}

body[data-theme='dark'] .subtitle {
  color: #aaa;
}

.guess-board {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 500px;
  margin-bottom: 1.5rem;
}

.guess-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border: 2px solid #999;
  border-radius: 0.375rem;
  background: white;
  font-size: 0.95rem;
  min-height: 2.5rem;
}

.guess-row.hint-anchor {
  position: relative;
  overflow: visible;
}

body[data-theme='dark'] .guess-row {
  background: #333;
  border-color: #555;
}

.guess-row.correct {
  background: #d4edda;
  border-color: #28a745;
}

body[data-theme='dark'] .guess-row.correct {
  background: #1b4d2b;
  border-color: #28a745;
}

.guess-content {
  flex: 1;
  font-weight: 500;
}

.distance {
  font-size: 0.85rem;
  color: #666;
  margin-left: 0.5rem;
}

body[data-theme='dark'] .distance {
  color: #aaa;
}

.player-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 500px;
  margin-bottom: 1.5rem;
}

.play-button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #d3d3d3;
  color: #333;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background-color 0.2s;
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 16px solid currentColor;
  margin-left: 3px;
}

.play-icon.is-pause {
  width: 14px;
  height: 16px;
  border: 0;
  margin-left: 0;
  position: relative;
}

.play-icon.is-pause::before,
.play-icon.is-pause::after {
  content: '';
  position: absolute;
  top: 0;
  width: 4px;
  height: 16px;
  border-radius: 1px;
  background: currentColor;
}

.play-icon.is-pause::before {
  left: 0;
}

.play-icon.is-pause::after {
  right: 0;
}

body[data-theme='dark'] .play-button {
  background: #555;
  color: #f5f5f5;
}

.play-button:hover {
  background: #b0b0b0;
}

body[data-theme='dark'] .play-button:hover {
  background: #666;
}

.audio-progress {
  width: 100%;
  height: 3px;
  background: #ddd;
  position: relative;
  cursor: pointer;
}

.audio-progress .progress-fill {
  height: 100%;
  background: #007bff;
}

body[data-theme='dark'] .audio-progress {
  background: #444;
}

body[data-theme='dark'] .audio-progress .progress-fill {
  background: #007bff;
}

.input-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 500px;
  margin-bottom: 1.5rem;
}

.input-section input {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
  font-size: 1rem;
  width: 100%;
}

body[data-theme='dark'] .input-section input {
  background: #333;
  color: #f5f5f5;
  border-color: #555;
}

.input-section button {
  padding: 0.6rem 1rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
  font-weight: 600;
  width: 100%;
}

.input-section button:hover {
  background: #0056b3;
}

/* Custom country dropdown */
.country-input-wrapper {
  position: relative;
  width: 100%;
}

.country-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 0.25rem 0.25rem;
  max-height: min(55dvh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

body[data-theme='dark'] .country-dropdown {
  background: #333;
  border-color: #555;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.country-dropdown.hidden {
  display: none;
}

.dropdown-options {
  display: flex;
  flex-direction: column;
}

.dropdown-option {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-left: 3px solid transparent;
  transition: background-color 0.1s, border-color 0.1s;
}

.dropdown-option:hover {
  background-color: #f0f0f0;
}

body[data-theme='dark'] .dropdown-option:hover {
  background-color: #444;
}

.dropdown-option.highlighted {
  background-color: #dbeafe;
  border-left-color: #2563eb;
}

body[data-theme='dark'] .dropdown-option.highlighted {
  background-color: #1f3552;
  border-left-color: #60a5fa;
}

.dropdown-option .flag {
  font-size: 1.25rem;
  min-width: 1.5rem;
  display: inline-block;
}

.dropdown-option .flag img,
.flag-img {
  width: 20px;
  height: 15px;
  vertical-align: middle;
}

.dropdown-option .country-name {
  flex: 1;
  font-size: 0.95rem;
}

/* Datalist styling */
datalist {
  display: none;
}

.hint-text {
  text-align: center;
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 2rem;
  max-width: 500px;
}

.distance-center-hint-inline {
  position: absolute;
  top: 50%;
  right: -0.75rem;
  transform: translate(100%, -50%);
  display: inline-block;
  font-size: 0.78rem;
  color: #4b5563;
  opacity: 0.95;
  user-select: none;
  white-space: nowrap;
  background: none;
  border: none;
  padding: 0 1rem 0 0;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgba(75, 85, 99, 0.45);
  text-underline-offset: 0.18rem;
  cursor: pointer;
  z-index: 2;
  pointer-events: auto;
}

.distance-center-hint-inline:hover {
  opacity: 1;
}

.distance-center-hint-qmark {
  position: absolute;
  top: -0.35rem;
  right: -0.1rem;
  width: 0.74rem;
  height: 0.74rem;
  border-radius: 999px;
  border: 1px solid rgba(75, 85, 99, 0.4);
  background: transparent;
  color: #4b5563;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 0.68rem;
  text-align: center;
  pointer-events: none;
}

body[data-theme='dark'] .hint-text {
  color: #aaa;
}

body[data-theme='dark'] .distance-center-hint-inline {
  color: #cbd5e1;
  text-decoration-color: rgba(203, 213, 225, 0.45);
}

body[data-theme='dark'] .distance-center-hint-inline:hover {
  opacity: 1;
}

body[data-theme='dark'] .distance-center-hint-qmark {
  border-color: rgba(203, 213, 225, 0.5);
  color: #cbd5e1;
}

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: #f5f5f5;
  border-top: 2px solid #0FA8DB;
  padding: 0.75rem;
  text-align: center;
  font-size: 0.85rem;
}

body.dropdown-open footer {
  z-index: 1;
}

body[data-theme='dark'] footer {
  background: #2a2a2a;
  border-top-color: #0FA8DB;
}

.kofi-link {
  color: #007bff;
  text-decoration: none;
  display: inline-block;
  margin-bottom: 0.25rem;
}

.kofi-link:hover {
  text-decoration: underline;
}

body.subpage main.content a[href^="mailto:"] {
  color: #007bff;
  text-decoration: none;
}

body.subpage main.content a[href^="mailto:"]:hover {
  text-decoration: underline;
}

.footer-links {
  color: #666;
}

body[data-theme='dark'] .footer-links {
  color: #aaa;
}

.footer-links a {
  color: inherit;
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

.icon-button {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.icon-button:hover {
  opacity: 0.7;
}

/* Modal Styles */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  z-index: 200;
}

.modal-card {
  background: white;
  border-radius: 0.5rem;
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

body[data-theme='dark'] .modal-card {
  background: #2a2a2a;
  color: #f5f5f5;
}

.modal-card h2 {
  margin-top: 0;
  margin-bottom: 1rem;
}

.modal-card p {
  margin: 0.5rem 0;
}

.modal-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.modal-card button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
  font-weight: 600;
}

.modal-card button.primary {
  background: #007bff;
  color: white;
}

.modal-card button.primary:hover {
  background: #0056b3;
}

.modal-card button.secondary-light {
  background: #f0f0f0;
  color: #333;
}

body[data-theme='dark'] .modal-card button.secondary-light {
  background: #444;
  color: #f5f5f5;
}

.modal-card button.secondary-light:hover {
  background: #e0e0e0;
}

body[data-theme='dark'] .modal-card button.secondary-light:hover {
  background: #555;
}

.modal-card label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.modal-card input[type='checkbox'] {
  cursor: pointer;
}

/* Toast Styles */
.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.25rem;
  z-index: 300;
  transition: transform 0.3s;
}

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

.mobile-ad-overlay {
  z-index: 320;
}

.mobile-ad-card {
  width: min(92vw, 360px);
  padding-top: 1rem;
}

.mobile-ad-card h2 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.mobile-popup-ad {
  width: 100%;
  min-height: 260px;
}

/* Stats Overlay */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  text-align: center;
  margin: 1rem 0;
}

.scoreboard > div {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.scoreboard strong {
  font-size: 0.85rem;
  color: #666;
}

body[data-theme='dark'] .scoreboard strong {
  color: #aaa;
}

.scoreboard span {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.stat-bar {
  flex: 1;
  height: 24px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
}

body[data-theme='dark'] .stat-bar {
  background: #444;
}

.stat-bar div {
  height: 100%;
  background: #007bff;
}

/* Confetti */
.confetti-piece {
  position: fixed;
  pointer-events: none;
  animation: confetti-fall 1.5s ease-out forwards;
  z-index: 250;
}

@keyframes confetti-fall {
  to {
    transform: translateY(100vh) rotateZ(360deg);
    opacity: 0;
  }
}

/* Responsive */
@media (max-width: 600px) {
  body.dropdown-open {
    overflow: hidden;
  }

  body.dropdown-open .country-dropdown {
    z-index: 160;
  }

  .country-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    bottom: auto;
    max-height: min(45dvh, 320px);
    border: 1px solid #ccc;
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
  }

  main {
    margin-top: 3rem;
  }

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

  body.subpage main.content {
    margin-top: 3rem;
    min-height: 0;
    padding-bottom: 5rem;
  }

  .guess-board {
    max-width: 100%;
  }

  .distance-center-hint-inline {
    position: static;
    transform: none;
    margin-top: 0.45rem;
    display: inline-block;
    white-space: normal;
    text-align: right;
    font-size: 0.74rem;
  }

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

/* Phone landscape lock: keep gameplay portrait-only on small phones.
   iPads/tablets are intentionally excluded by the max-height threshold. */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  body::before {
    content: 'Please rotate your phone to portrait mode to play LINGLE.';
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.25rem;
    background: rgba(245, 245, 245, 0.98);
    color: #1f2937;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.4;
  }

  body[data-theme='dark']::before {
    background: rgba(26, 26, 26, 0.98);
    color: #e5e7eb;
  }

  header,
  main,
  footer {
    visibility: hidden;
    pointer-events: none;
  }
}
