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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #2e2019;
  color: #e2e8f0;
  min-height: 100vh;
  min-height: 100dvh; /* respects Safari's collapsing toolbar on iOS */
  -webkit-text-size-adjust: 100%; /* stop iOS resizing text on rotate */
  -webkit-tap-highlight-color: transparent; /* no gray flash when tapping */
}

.container {
  max-width: 600px;
  margin: 0 auto;
  /* max() keeps the normal padding but grows it under the notch / home indicator */
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---- Language switch ---- */
.lang-switch {
  text-align: right;
  margin-bottom: 8px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* ---- Home page ---- */
.home {
  text-align: center;
  padding-top: 40px;
}

.home h1 {
  font-size: 3rem;
  margin-bottom: 8px;
}

.subtitle {
  color: #c4a882;
  font-size: 1.1rem;
  margin-bottom: 40px;
}

.how-it-works {
  text-align: left;
  margin-top: 48px;
  background: #3d2e22;
  border-radius: 12px;
  padding: 24px 28px;
}

.how-it-works h2 {
  font-size: 1.1rem;
  margin-bottom: 12px;
  color: #c4a882;
}

.how-it-works ol {
  padding-left: 20px;
}

.how-it-works li {
  margin-bottom: 8px;
  line-height: 1.5;
}

/* ---- Cards ---- */
.card {
  background: #3d2e22;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 1rem;
  color: #c4a882;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---- Buttons ---- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  touch-action: manipulation; /* removes the 300ms tap delay / double-tap zoom */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* no long-press menu on buttons */
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: #F5C9F1;
  color: #1e293b;
}

.btn-primary:hover {
  background: #f9ddf6;
}

.btn-large {
  padding: 16px 40px;
  font-size: 1.2rem;
  border-radius: 12px;
}

.btn-small {
  padding: 6px 14px;
  font-size: 0.85rem;
  background: #5a4233;
  color: #cbd5e1;
}

.btn-small:hover {
  background: #6b503b;
}

.btn-danger {
  background: #991b1b;
  color: #fecaca;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-draw {
  background: linear-gradient(135deg, #F5C9F1, #e9a5e3);
  color: #1e293b;
  padding: 18px 48px;
  font-size: 1.3rem;
  border-radius: 16px;
  width: 100%;
}

.btn-draw:hover:not(:disabled) {
  background: linear-gradient(135deg, #f9ddf6, #F5C9F1);
}

.btn-draw:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ---- Inputs ---- */
input[type="text"] {
  background: #2e2019;
  border: 2px solid #5a4233;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 1rem;
  color: #e2e8f0;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: #F5C9F1;
}

input[readonly] {
  cursor: default;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input {
  flex: 1;
}

.input-row-vertical {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-row-vertical textarea {
  flex: 1;
}

.input-hint {
  color: #a08060;
  font-size: 0.8rem;
  margin-bottom: 8px;
}

textarea {
  background: #2e2019;
  border: 2px solid #5a4233;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: #e2e8f0;
  width: 100%;
  outline: none;
  resize: none;
  overflow: hidden;
  min-height: 42px;
  line-height: 1.5;
  transition: border-color 0.2s;
}

textarea:focus {
  border-color: #F5C9F1;
}

/* ---- Room header ---- */
.room-header {
  margin-bottom: 20px;
}

.room-header h1 {
  font-size: 1.8rem;
  margin-bottom: 12px;
}

.room-link-section label {
  font-size: 0.85rem;
  color: #a08060;
}

.copy-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.copy-row input {
  font-size: 0.85rem;
}

/* ---- Name card ---- */
.name-card {
  border: 2px solid #F5C9F1;
}

/* ---- Lots list ---- */
.lots-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-message {
  color: #6b503b;
  font-style: italic;
  text-align: center;
  padding: 16px 0;
}

.lot-item {
  background: #2e2019;
  border-radius: 8px;
  padding: 10px 14px;
  animation: slideIn 0.2s ease-out;
}

.lot-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.lot-item-top > div:first-child {
  flex: 1;
  min-width: 0;
}

/* Inline vote bar inside lot item */
.lot-vote-bar-row {
  margin-top: 6px;
  height: 4px;
  background: #5a4233;
  border-radius: 2px;
  overflow: hidden;
}

.lot-vote-bar {
  height: 100%;
  background: #F5C9F1;
  border-radius: 2px;
  transition: width 0.3s ease;
}

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

.lot-text {
  font-weight: 500;
}

.lot-author {
  color: #a08060;
  font-size: 0.85rem;
  margin-left: 8px;
}

.lot-remove {
  background: none;
  border: none;
  color: #6b503b;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 4px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
  transition: color 0.2s;
}

.lot-remove:hover {
  color: #ef4444;
}

.lot-remove-placeholder {
  display: inline-block;
  width: 24px;
  flex-shrink: 0;
}

/* ---- Badge ---- */
.badge {
  background: #F5C9F1;
  color: #1e293b;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 99px;
  margin-left: 8px;
  vertical-align: middle;
}

/* ---- Mode toggle ---- */
.mode-section {
  margin-bottom: 16px;
}

.mode-toggle {
  display: flex;
  gap: 0;
  background: #3d2e22;
  border-radius: 12px;
  padding: 4px;
}

.btn-mode {
  flex: 1;
  background: transparent;
  color: #a08060;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-mode:hover {
  color: #c4a882;
  transform: none;
}

.btn-mode.active {
  background: #F5C9F1;
  color: #1e293b;
}

.btn-mode.active:hover {
  background: #f9ddf6;
}

/* ---- Vote button in lot list ---- */
.lot-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.btn-vote {
  background: #5a4233;
  color: #cbd5e1;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  min-width: 90px;
  text-align: center;
}

.btn-vote:hover {
  background: #F5C9F1;
  color: #1e293b;
  transform: none;
}

.btn-vote.voted {
  background: #F5C9F1;
  color: #1e293b;
}

/* ---- Winner banner (above pool) ---- */
.winner-banner {
  border: 2px solid #F5C9F1;
  text-align: center;
}

.winner-banner-text {
  font-size: 1.6rem;
  font-weight: 700;
  padding: 12px;
  color: #F5C9F1;
}

.winner-banner-author {
  color: #a08060;
  margin-bottom: 12px;
}

/* ---- Winner popup overlay ---- */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.popup-card {
  background: #3d2e22;
  border: 2px solid #F5C9F1;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  max-width: 440px;
  width: 90%;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.popup-book-title {
  font-size: 2rem;
  font-weight: 700;
  padding: 20px 0;
  color: #F5C9F1;
  white-space: pre-line;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.popup-book-author {
  color: #a08060;
  margin-bottom: 20px;
}

/* ---- Wheel of Fortune ---- */
.wheel-section {
  margin: 20px 0;
}

.wheel-container {
  position: relative;
  width: min(340px, 100%); /* never wider than the screen on small iPhones */
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.wheel-pointer {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 30px solid #F5C9F1;
  z-index: 10;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

#wheel-canvas {
  display: block;
  width: 100%; /* scales the canvas down to fit narrow screens */
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 0 0 6px #5a4233, 0 0 0 10px #3d2e22, 0 4px 20px rgba(0,0,0,0.5);
}

/* ---- Draw section ---- */
.draw-section {
  margin: 20px 0;
}

/* ---- Result animation ---- */
@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---- History ---- */
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-list li {
  color: #c4a882;
  font-size: 0.9rem;
  padding: 6px 0;
  border-bottom: 1px solid #3d2e22;
}

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

/* ---- Danger zone ---- */
.danger-zone {
  background: transparent;
  border: 1px dashed #5a4233;
  text-align: center;
}

/* ---- Utility ---- */
.hidden {
  display: none !important;
}

/* ---- Touch devices (iPhone/iPad): undo hover effects that otherwise "stick"
       after a tap until you tap somewhere else ---- */
@media (hover: none) {
  .btn:hover { transform: none; }
  .btn-primary:hover { background: #F5C9F1; }
  .btn-small:hover { background: #5a4233; }
  .btn-danger:hover { background: #991b1b; }
  .btn-draw:hover:not(:disabled) { background: linear-gradient(135deg, #F5C9F1, #e9a5e3); }
  .btn-mode:hover { color: #a08060; }
  .btn-mode.active:hover { background: #F5C9F1; }
  .btn-vote:not(.voted):hover { background: #5a4233; color: #cbd5e1; }
  .lot-remove:hover { color: #6b503b; }
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
  .home h1 {
    font-size: 2.2rem;
  }

  .btn-draw {
    font-size: 1.1rem;
    padding: 14px 24px;
  }

  .result-display {
    font-size: 1.5rem;
  }
}
