:root {
  --ink: #1e1a15;
  --ink-soft: #6b6259;
  --sand: #f4eee1;
  --sand-deep: #e6dccb;
  --gold: #c59c4d;
  --gold-light: #d4b06a;
  --sage: #5a7a68;
  --ember: #c25a3a;
  --white: #ffffff;
  --panel-bg: rgba(255, 255, 255, 0.85);
  --panel-border: rgba(30, 26, 21, 0.1);
  --shadow-sm: 0 2px 8px rgba(30, 26, 21, 0.08);
  --shadow-md: 0 8px 32px rgba(30, 26, 21, 0.12);
  --shadow-lg: 0 16px 48px rgba(30, 26, 21, 0.16);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --font-display: "Bodoni MT", "Didot", "Playfair Display", Georgia, serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background: linear-gradient(145deg, #f8f4eb 0%, #efe6d5 50%, #e4d8c4 100%);
  line-height: 1.5;
  overflow-x: hidden;
  width: 100%;
}

/* Ambient background */
.ambient-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.orb {
  position: absolute;
  border-radius: 50%;
  opacity: 0.4;
}

.orb-sand {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(214, 190, 140, 0.5), transparent 70%);
  top: -200px;
  left: -150px;
}

.orb-ink {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(60, 52, 44, 0.25), transparent 70%);
  bottom: -150px;
  right: -100px;
}

/* Main app container */
.app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(248, 244, 235, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  margin: -20px -20px 0;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
  /* Mobile Safari fix */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.header.scrolled {
  border-bottom-color: var(--panel-border);
  box-shadow: 0 2px 12px rgba(30, 26, 21, 0.08);
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

.day-label {
  font-size: 0.875rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bankroll {
  background: var(--white);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--panel-border);
}

.bankroll-value {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--white);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--sand);
  color: var(--ink);
}

/* Decks bar */
.decks-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px 20px;
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-sm);
}

.deck-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 100px;
}

.deck-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}

.deck-composition {
  display: flex;
  gap: 12px;
}

.suit {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 1.1rem;
}

.suit::before {
  font-size: 1rem;
}

.suit.spades::before {
  content: "♠";
  color: var(--ink);
}

.suit.hearts::before {
  content: "♥";
  color: var(--ember);
}

.vs {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

/* Play area */
.play-area {
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-md);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.card-history {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 24px;
}

.card-history img {
  width: 40px;
  height: auto;
  border-radius: 3px;
  box-shadow: var(--shadow-sm);
}

.card-stage {
  width: 100%;
  display: flex;
  justify-content: center;
}

.card-slot {
  width: 160px;
  height: 224px;
  border-radius: var(--radius-md);
  border: 2px dashed var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.5);
  transition: all 0.3s;
}

.card-slot.has-card {
  border: none;
  background: transparent;
}

.card-slot img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
  animation: cardReveal 0.4s ease-out;
}

.card-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  color: var(--ink-soft);
}

.placeholder-hint {
  font-size: 0.9rem;
  line-height: 1.4;
  max-width: 140px;
}

.round-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.round-label {
  font-weight: 600;
  color: var(--ink);
}

.round-cost {
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.bonus-indicator {
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 999px;
  margin-top: 4px;
}

.bonus-indicator:empty {
  display: none;
}

.bonus-indicator.active {
  background: rgba(90, 122, 104, 0.15);
  color: var(--sage);
  font-weight: 600;
}

.bonus-indicator.expired {
  background: rgba(107, 98, 89, 0.1);
  color: var(--ink-soft);
}

/* Buttons */
.actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

button {
  font-family: var(--font-body);
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gold);
  color: var(--ink);
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(197, 156, 77, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--gold-light);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(197, 156, 77, 0.5);
}

.btn-large {
  padding: 16px 32px;
  font-size: 1.1rem;
}

.cost-badge {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.9em;
}

.btn-secondary {
  background: var(--sand-deep);
  color: var(--ink);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 500;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--sand);
}

.guess-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-guess {
  background: var(--white);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.btn-guess:hover:not(:disabled) {
  border-color: var(--gold);
  background: rgba(197, 156, 77, 0.05);
}

.btn-guess:not(:disabled) {
  box-shadow: var(--shadow-sm);
}

.guess-label {
  font-weight: 600;
  font-size: 1rem;
}

.guess-hint {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.status-message {
  margin: 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--ink-soft);
  min-height: 1.5em;
}

/* Wager section */
.wager-section {
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

.wager-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: transparent;
  font-weight: 500;
  color: var(--ink-soft);
}

.wager-toggle:hover {
  background: rgba(0, 0, 0, 0.02);
}

.toggle-arrow {
  font-size: 1.25rem;
  font-weight: 400;
  transition: transform 0.2s;
}

.wager-section.open .toggle-arrow {
  transform: rotate(45deg);
}

.wager-drawer {
  display: none;
  padding: 0 20px 20px;
}

.wager-section.open .wager-drawer {
  display: block;
}

.wager-section.locked .wager-toggle {
  color: var(--sage);
}

.wager-section.locked .wager-drawer {
  display: none;
}

.wager-controls {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
}

.wager-amount {
  flex: 0 0 auto;
}

.wager-amount label,
.wager-target label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.amount-input-wrap {
  display: flex;
  align-items: center;
  background: var(--white);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  cursor: text;
}

.currency {
  color: var(--ink-soft);
  font-weight: 500;
}

.amount-input-wrap input {
  width: 80px;
  padding: 10px 8px;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-family: var(--font-body);
}

.amount-input-wrap input:focus {
  outline: none;
}

.wager-target {
  flex: 1;
}

.target-options {
  display: flex;
  gap: 8px;
}

.target-option {
  flex: 1;
  cursor: pointer;
}

.target-option input {
  display: none;
}

.option-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: var(--white);
  transition: all 0.2s;
}

.target-option input:checked + .option-content {
  border-color: var(--gold);
  background: rgba(197, 156, 77, 0.1);
}

.option-content strong {
  font-size: 0.75rem;
  white-space: nowrap;
}

.option-content em {
  font-style: normal;
  font-weight: 700;
  color: var(--gold);
  font-size: 0.9rem;
}

.wager-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.wager-summary {
  font-size: 0.875rem;
  color: var(--ink-soft);
}

/* Result panel */
.result-panel {
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-md);
  padding: 32px 24px;
  text-align: center;
}

.result-panel.hidden {
  display: none;
}

.result-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin: 0 0 16px;
}

.result-summary {
  color: var(--ink-soft);
  margin-bottom: 24px;
  line-height: 1.6;
}

.result-actions {
  margin-bottom: 0;
}

.share-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Help modal */
.help-modal {
  position: fixed;
  inset: 0;
  margin: auto;
  max-width: 400px;
  max-height: 90vh;
  width: calc(100% - 40px);
  padding: 0;
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  background: var(--white);
}

.help-modal::backdrop {
  background: rgba(30, 26, 21, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--panel-border);
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sand);
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--sand-deep);
  color: var(--ink);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rule-step {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rule-step p {
  margin: 0;
  padding-top: 4px;
  color: var(--ink);
  line-height: 1.4;
}

.modal-footer {
  padding: 16px 24px 24px;
  border-top: 1px solid var(--panel-border);
}

.full-rules summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.full-rules p {
  margin: 12px 0 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* Animations */
@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Responsive */
@media (max-width: 500px) {
  .app {
    padding: 12px 12px 32px;
    gap: 16px;
  }

  .header {
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    margin: -12px -12px 0;
    gap: 8px;
  }

  h1 {
    font-size: 1.25rem;
  }

  .day-label {
    font-size: 0.75rem;
  }

  .bankroll {
    padding: 6px 12px;
  }

  .bankroll-value {
    font-size: 1.1rem;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  .decks-bar {
    padding: 12px 16px;
    gap: 12px;
  }

  .deck-info {
    min-width: 70px;
  }

  .deck-name {
    font-size: 0.8rem;
  }

  .suit {
    font-size: 1rem;
    gap: 2px;
  }

  .suit::before {
    font-size: 0.9rem;
  }

  .vs {
    font-size: 0.7rem;
  }

  .wager-section {
    border-radius: var(--radius-md);
  }

  .wager-toggle {
    padding: 14px 16px;
    font-size: 0.9rem;
  }

  .wager-drawer {
    padding: 0 16px 16px;
  }

  .play-area {
    padding: 16px 12px;
    border-radius: var(--radius-md);
    gap: 16px;
  }

  .card-history img {
    width: 32px;
  }

  .card-slot {
    width: 130px;
    height: 182px;
  }

  .round-info {
    gap: 2px;
  }

  .round-label {
    font-size: 0.95rem;
  }

  .round-cost {
    font-size: 0.8rem;
  }

  .bonus-indicator {
    font-size: 0.75rem;
    padding: 3px 10px;
  }

  .btn-primary {
    padding: 12px 20px;
    font-size: 0.95rem;
  }

  .btn-large {
    padding: 14px 24px;
    font-size: 1rem;
  }

  .btn-guess {
    padding: 12px 8px;
  }

  .guess-label {
    font-size: 0.9rem;
  }

  .guess-hint {
    font-size: 0.75rem;
  }

  .wager-controls {
    flex-direction: column;
    gap: 14px;
  }

  .wager-amount label,
  .wager-target label {
    font-size: 0.75rem;
    margin-bottom: 6px;
  }

  .amount-input-wrap {
    padding: 0 10px;
  }

  .amount-input-wrap input {
    width: 70px;
    padding: 8px 6px;
    font-size: 0.95rem;
  }

  .target-options {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .option-content {
    padding: 8px 4px;
  }

  .option-content strong {
    font-size: 0.7rem;
  }

  .option-content em {
    font-size: 0.85rem;
  }

  .wager-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .wager-summary {
    text-align: center;
    font-size: 0.8rem;
  }

  .btn-secondary {
    padding: 10px 16px;
    font-size: 0.9rem;
  }

  .result-panel {
    padding: 24px 16px;
    border-radius: var(--radius-md);
  }

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

  .result-summary {
    font-size: 0.9rem;
  }

  .share-text {
    font-size: 0.8rem;
    padding: 10px;
  }

  .help-modal {
    width: calc(100% - 24px);
  }

  .modal-header {
    padding: 16px 20px;
  }

  .modal-header h2 {
    font-size: 1.25rem;
  }

  .modal-body {
    padding: 20px;
    gap: 14px;
  }

  .step-num {
    width: 24px;
    height: 24px;
    font-size: 0.8rem;
  }

  .rule-step {
    gap: 12px;
  }

  .rule-step p {
    font-size: 0.9rem;
  }

  .modal-footer {
    padding: 14px 20px 20px;
  }
}

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