:root {
  --bg: #fafafa;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6b6b7a;
  --accent: #e94560;
  --accent-hover: #d63a55;
  --accent-soft: #fff0f2;
  --border: #e5e5e5;
  --success: #22c55e;
  --success-soft: #f0fdf4;
  --shadow: 0 4px 24px rgba(0,0,0,0.06);
  --shadow-hover: 0 8px 32px rgba(0,0,0,0.1);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.brand {
  text-align: center;
  padding: 0.5rem 0;
}

.brand h1 {
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.brand h1 .logo {
  width: 1em;
  height: 1em;
  color: var(--accent);
  flex-shrink: 0;
}

.tagline {
  color: var(--muted);
  margin-top: 0.35rem;
  font-size: clamp(0.95rem, 2.5vw, 1.05rem);
  font-weight: 400;
}

.view {
  background: var(--card);
  border-radius: var(--radius);
  padding: clamp(1.5rem, 4vw, 2rem);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  width: 100%;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.view:hover { box-shadow: var(--shadow-hover); }

.view.hidden { display: none !important; }

/* Buttons */
.btn {
  width: 100%;
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(233,69,96,0.25);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px rgba(233,69,96,0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--card);
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
  border-color: var(--muted);
}

/* Inputs */
input, select {
  width: 100%;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder { color: var(--muted); }

/* Error messages */
.error {
  color: var(--accent);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  min-height: 1.25rem;
}

.error.hidden { display: none; }

/* Lists */
ul, ol { list-style: none; }

#player-list li {
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 500;
  border: 1px solid var(--border);
}

#player-list li.host::after {
  content: 'Host';
  font-size: 0.7rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Lobby PIN display */
#lobby-pin {
  text-align: center;
  padding: 1rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  border: 1px solid rgba(233,69,96,0.2);
}

#lobby-pin.hidden { display: none; }

#game-pin {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Share box */
#share-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  margin: 1rem 0;
  border: 1px solid var(--border);
}

#share-box h3 {
  margin-bottom: 0.75rem;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#share-link-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

#share-link {
  flex: 1;
  margin-bottom: 0;
  font-size: 0.875rem;
  padding: 0.75rem;
  background: var(--card);
}

#qr-code {
  text-align: center;
  margin-top: 0.5rem;
}

#qr-code img {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-width: 100%;
  height: auto;
}

.toast {
  color: var(--success);
  font-size: 0.875rem;
  font-weight: 600;
  margin-top: 0.75rem;
  animation: fadeInOut 2s ease;
}

.toast.hidden { display: none; }

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(-4px); }
  10% { opacity: 1; transform: translateY(0); }
  90% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-4px); }
}

/* Preview view */
#preview-view .hint {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.5;
  text-align: center;
}

#preview-img {
  width: 100%;
  max-height: 50vh;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  margin: 0.75rem 0;
  box-shadow: var(--shadow);
  background: var(--bg);
}

#selecting-status {
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

/* Game view */
#round-info {
  text-align: center;
  margin-bottom: 1.25rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--muted);
}

#photo-stage { text-align: center; }

#photo-img {
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
  border-radius: var(--radius);
  border: 3px solid var(--accent);
  box-shadow: var(--shadow-hover);
  background: var(--bg);
}

#timer {
  margin-top: 1rem;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

#timer > div {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--accent));
  width: 100%;
  transition: width 0.1s linear;
  border-radius: 3px;
}

#guess-stage { text-align: center; }

#guess-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
  margin-top: 1.25rem;
}

#guess-buttons .btn {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: 0.95rem;
}

#guess-stage > p {
  font-weight: 600;
  color: var(--text);
}

#result-stage { text-align: center; }

#result-text {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  line-height: 1.3;
}

#result-text.correct { color: var(--success); }
#result-text.wrong { color: var(--accent); }

/* End view */
#end-stage { text-align: center; }

#end-stage h2 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

#score-list {
  margin: 1rem 0;
}

#score-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin: 0.4rem 0;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: all 0.15s;
}

#score-list li:first-child {
  border-color: var(--accent);
  background: var(--accent-soft);
}

#score-list li .name { color: var(--text); }
#score-list li .score {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Highscore */
.hs-title {
  margin: 1.5rem 0 0.75rem;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
}

#score-list-top {
  margin: 0.5rem 0;
}

#score-list-top li {
  display: flex;
  justify-content: space-between;
  padding: 0.625rem 0.875rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin: 0.25rem 0;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--border);
}

#score-list-top li:first-child {
  border-color: var(--accent);
  background: var(--accent-soft);
}

#score-list-top li .name { color: var(--text); }
#score-list-top li .score { color: var(--accent); font-weight: 700; }

/* Upload status */
#upload-status {
  font-size: 0.875rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.25rem;
  margin-top: 0.25rem;
}

/* Footer */
footer.brand {
  margin-top: 2rem;
  padding: 1.25rem 0 0.75rem;
  border-top: 1px solid var(--border);
  text-align: center;
  width: 100%;
  max-width: 480px;
}

footer.brand p {
  color: var(--muted);
  font-size: 0.8rem;
}

footer.brand a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

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

/* SVG Icons */
.icon {
  width: 1.125em;
  height: 1.125em;
  vertical-align: -0.125em;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm { width: 1em; height: 1em; }
.icon-lg { width: 1.375em; height: 1.375em; }

/* Responsive */
@media (max-width: 480px) {
  body { padding: 1rem; align-items: stretch; }
  .view { padding: 1.25rem; border-radius: 12px; }
  .brand h1 { font-size: 1.625rem; }
  .btn { padding: 0.875rem 1rem; font-size: 0.95rem; }
  #photo-img { max-height: 50vh; }
  #guess-buttons { grid-template-columns: 1fr; }
  #lobby-pin { padding: 0.875rem; }
  #game-pin { font-size: 1.5rem; letter-spacing: 0.1em; }
  footer.brand { padding: 1rem 0 0.5rem; }
}

@media (min-width: 768px) {
  .view { max-width: 480px; }
  body { padding: 2rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for accessibility */
.btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .view { box-shadow: none; border: 1px solid #ccc; }
  .btn, input, #share-box, #qr-code { display: none !important; }
}