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

[hidden] {
  display: none !important;
}

:root {
  --bg: #f0f0f3;
  --card: #ffffff;
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --secondary: #a29bfe;
  --accent: #fd79a8;
  --green: #00b894;
  --text: #2d3436;
  --text-muted: #636e72;
  --border: #dfe6e9;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --radius: 16px;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ---- Screens ---- */

.screen {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 16px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen.active {
  display: flex;
}

/* ---- Card ---- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.center-card {
  align-items: center;
  text-align: center;
}

/* ---- Landing ---- */

.logo {
  font-size: 2.2rem;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 8px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---- Inputs ---- */

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--primary);
}

/* ---- Buttons ---- */

.btn {
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.1s;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-sm {
  padding: 10px 18px;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

/* ---- Error / Status ---- */

.error {
  color: #d63031;
  font-size: 0.9rem;
  text-align: center;
}

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

.text-muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---- Player List ---- */

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 10px;
  font-weight: 500;
}

.player-list .admin-badge {
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  margin-left: auto;
}

.player-list .you-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--green);
}

/* ---- Round Badge ---- */

.round-badge {
  align-self: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  background: #f0edff;
  padding: 4px 14px;
  border-radius: 20px;
}

/* ---- Draw Layout (full-viewport) ---- */

#screen-draw,
#screen-sandbox {
  padding: 0;
}

#screen-chain {
  justify-content: flex-start;
}

.draw-layout {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 6px 6px calc(env(safe-area-inset-bottom, 0px) + 6px);
  gap: 4px;
  background: var(--bg);
}

.draw-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
  min-height: 0;
}

.draw-header .round-badge {
  align-self: auto;
  flex-shrink: 0;
  font-size: 0.7rem;
  padding: 2px 10px;
}

.draw-header-word {
  font-weight: 700;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canvas-wrap {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
}

/* ---- Header Buttons ---- */

.draw-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.draw-footer .fab-menu {
  position: relative;
  bottom: auto;
  right: auto;
}

.draw-footer .fab-options {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(8px) scale(0.9);
}

.draw-footer .fab-menu.open .fab-options {
  transform: translateX(-50%) translateY(0) scale(1);
}

.fab-submit {
  flex: 1;
  padding: 12px 0;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition:
    background 0.15s,
    transform 0.1s;
}

.fab-submit:active {
  background: var(--primary-dark);
  transform: scale(0.97);
}

.fab-submit:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.header-back {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

/* ---- FAB Menu ---- */

.fab-menu {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 10;
}

.fab-options {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.fab-menu.open .fab-options {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.fab-opt {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition:
    border-color 0.15s,
    background 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

.fab-opt.active {
  border-color: var(--primary);
  background: #f0edff;
}

.fab-toggle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
  transition:
    transform 0.2s ease,
    background 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

.fab-toggle:active {
  background: var(--primary-dark);
}

.fab-menu.open .fab-toggle {
  transform: rotate(45deg);
}

.pen-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--text);
  display: block;
}

/* ---- Pen Popup ---- */

.pen-popup {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  padding: 0 12px 24px;
}

.pen-popup[hidden] {
  display: none;
}

.pen-popup-inner {
  background: var(--card);
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: popup-slide 0.2s ease-out;
}

@keyframes popup-slide {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.pen-popup-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.color-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}

.color-swatch.active {
  border-color: var(--text);
}

.size-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.size-btn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}

.size-btn.active {
  border-color: var(--primary);
  background: #f0edff;
}

.dot {
  border-radius: 50%;
  background: var(--text);
  display: block;
}

.dot-sm {
  width: 6px;
  height: 6px;
}

.dot-md {
  width: 10px;
  height: 10px;
}

.dot-lg {
  width: 16px;
  height: 16px;
}

/* ---- Guess Screen ---- */

.reveal-img-wrap {
  width: 100%;
  max-width: 400px;
  align-self: center;
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.reveal-img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---- Waiting ---- */

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.waiting-text {
  font-weight: 600;
  font-size: 1.1rem;
}

/* ---- Reveal ---- */

.reveal-card {
  max-width: 500px;
}

.reveal-entry {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.reveal-entry .reveal-word {
  font-size: 1.5rem;
  font-weight: 700;
  word-break: break-word;
  padding: 20px 0;
}

.reveal-entry .reveal-img-wrap {
  max-width: 100%;
}

.reveal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#reveal-counter {
  font-variant-numeric: tabular-nums;
}

.reveal-summary {
  max-width: 500px;
}

.chain-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.chain-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.chain-item:active {
  border-color: var(--primary);
  background: #f0edff;
}

.chain-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chain-item-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.chain-item-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chain-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chain-export-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition:
    border-color 0.15s,
    color 0.15s;
}

.chain-export-btn:active {
  border-color: var(--primary);
  color: var(--primary);
}

.chain-item-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
}

/* ---- Chain Page (full-page vertical browse) ---- */

.chain-page {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.chain-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 4px 0 8px;
  z-index: 5;
}

.chain-page-title {
  font-size: 1.1rem;
  margin: 0;
}

.chain-page-entries {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.chain-page-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.chain-page-entry .reveal-word {
  font-size: 1.3rem;
  font-weight: 700;
  word-break: break-word;
  text-align: center;
  padding: 16px 12px;
  background: #f0edff;
  border-radius: 12px;
  width: 100%;
}

.chain-page-entry .reveal-img-wrap {
  width: 100%;
}

.chain-page-author {
  font-size: 0.8rem;
  margin-top: 2px;
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* ---- Utility ---- */

h2 {
  text-align: center;
  font-size: 1.4rem;
}

@media (max-height: 680px) {
  .card {
    padding: 20px 16px;
    gap: 12px;
  }
  .logo {
    font-size: 1.8rem;
  }
}
