/* ==========================================================================
   Maharsho — design tokens

   Concept: a private ember shared by two people. Dark, warm, intimate —
   the opposite of a cold utility app. The room code and connection state
   are treated as a small flame: it flickers to life, glows while both
   people are present, and goes out the instant either of you leaves.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,wght@0,400;0,600;1,500&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  /* Color */
  --bg: #191531;
  --bg-glow: #241d42;
  --surface: #2a2350;
  --surface-raised: #342b63;
  --ember: #f0637c;
  --ember-soft: #f0637c33;
  --gold: #dba966;
  --text-primary: #f4efe6;
  --text-muted: #a89fc9;
  --text-faint: #746a97;
  --danger: #e8748a;
  --success: #7fd8b0;

  /* Type */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Layout */
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --shadow-ambient: 0 20px 60px rgba(10, 8, 25, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(120% 120% at 50% -10%, var(--bg-glow) 0%, var(--bg) 55%);
  color: var(--text-primary);
  font-family: var(--font-body);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* -- Ambient ember field (decorative, behind everything) -- */
.ember-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(2px 2px at 12% 22%, var(--ember-soft) 0%, transparent 60%),
    radial-gradient(2px 2px at 82% 68%, var(--ember-soft) 0%, transparent 60%),
    radial-gradient(3px 3px at 68% 18%, rgba(219, 169, 102, 0.18) 0%, transparent 60%),
    radial-gradient(2px 2px at 30% 82%, rgba(219, 169, 102, 0.15) 0%, transparent 60%);
  opacity: 0.9;
}

/* ==========================================================================
   Landing page
   ========================================================================== */

.landing {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 20px 56px;
  max-width: 560px;
  margin: 0 auto;
}

.landing__mark {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.landing__ember {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd7a8, var(--ember) 60%, transparent 100%);
  box-shadow: 0 0 12px 3px var(--ember-soft);
  animation: flicker 2.6s ease-in-out infinite;
}

.landing__ember--small {
  width: 9px;
  height: 9px;
}

.landing__wordmark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 28px;
  letter-spacing: 0.02em;
}

.landing__tagline {
  font-size: 17px;
  color: var(--text-muted);
  max-width: 380px;
  line-height: 1.55;
  margin: 0 0 40px;
}

.landing__footnote {
  margin-top: 40px;
  font-size: 13px;
  color: var(--text-faint);
  max-width: 400px;
  line-height: 1.6;
}

/* -- Banner (error/status messages) -- */
.banner {
  width: 100%;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: rgba(232, 116, 138, 0.14);
  border: 1px solid rgba(232, 116, 138, 0.35);
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.banner__reconnect-btn {
  flex-shrink: 0;
  background: var(--danger);
  color: #1b1531;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.banner__reconnect-btn:hover {
  filter: brightness(1.1);
}

.banner__reconnect-btn--hidden {
  display: none;
}

.typing-indicator {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0;
  padding: 0 4px;
  height: 16px;
}

.typing-indicator--hidden {
  visibility: hidden;
}

.banner--hidden {
  display: none;
}

.start-new-room {
  display: block;
  text-align: center;
  color: var(--gold);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 0 4px;
  border-bottom: 1px solid rgba(244, 239, 230, 0.08);
  margin-bottom: 4px;
  transition: opacity 0.15s ease;
}

.start-new-room:hover {
  opacity: 0.8;
}

.start-new-room--hidden {
  display: none;
}

/* -- Choice cards -- */
.choice-row {
  display: flex;
  gap: 16px;
  width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}

.choice-card {
  flex: 1 1 200px;
  min-width: 190px;
  background: linear-gradient(180deg, var(--surface-raised), var(--surface));
  border: 1px solid rgba(244, 239, 230, 0.08);
  border-radius: var(--radius-lg);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text-primary);
  font-family: inherit;
  box-shadow: var(--shadow-ambient);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.choice-card:hover,
.choice-card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(240, 99, 124, 0.45);
  box-shadow: 0 24px 70px rgba(10, 8, 25, 0.55), 0 0 0 1px var(--ember-soft);
}

.choice-card:active {
  transform: translateY(-1px);
}

.choice-card__flame {
  width: 20px;
  height: 20px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(45deg);
  background: radial-gradient(circle at 35% 30%, #ffd7a8, var(--ember) 65%, transparent 100%);
  margin-bottom: 4px;
}

.choice-card__title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.choice-card__sub {
  font-size: 13px;
  color: var(--text-muted);
}

.choice-card--create:hover .choice-card__flame,
.choice-card--create:focus-visible .choice-card__flame {
  box-shadow: 0 0 18px 4px var(--ember-soft);
}

/* -- Join form -- */
.join-form {
  width: 100%;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.join-form--hidden {
  display: none;
}

.join-form__label {
  font-size: 13px;
  color: var(--text-muted);
  align-self: flex-start;
  margin-left: 4px;
}

.join-form__input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(244, 239, 230, 0.14);
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 20px;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
}

.join-form__input::placeholder {
  color: var(--text-faint);
  letter-spacing: 0.18em;
}

.join-form__submit {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(135deg, var(--ember), #d9506c);
  color: #1b1531;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.join-form__submit:hover,
.join-form__submit:focus-visible {
  filter: brightness(1.08);
}

.join-form__submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

/* ==========================================================================
   Room page
   ========================================================================== */

.room {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 20px 40px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.room__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px 24px;
  border-bottom: 1px solid rgba(244, 239, 230, 0.08);
  margin-bottom: 28px;
  flex-shrink: 0;
}

.room__wordmark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 18px;
  flex: 1;
}

.room__code-chip {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--gold);
  background: rgba(219, 169, 102, 0.12);
  border: 1px solid rgba(219, 169, 102, 0.3);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}

/* -- Name entry panel (Phase 3: shown before the WebSocket connects) -- */
.name-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 40px 20px;
}

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

.name-panel .join-form {
  max-width: 320px;
}

.join-form__input--name {
  font-family: var(--font-body);
  font-size: 16px;
  letter-spacing: normal;
  text-align: left;
  text-transform: none;
}

/* -- Waiting panel -- */
.waiting-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 40px 20px;
}

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

/* ==========================================================================
   Chat panel (Phase 4)
   ========================================================================== */

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 14px;
}

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

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 12px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(244, 239, 230, 0.12);
  border-radius: 999px;
}

.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 3px;
  line-height: 1.45;
  word-break: break-word;
  animation: bubble-in 0.18s ease;
}

.chat-bubble--partner {
  align-self: flex-start;
  background: var(--surface-raised);
  border: 1px solid rgba(244, 239, 230, 0.08);
  border-bottom-left-radius: 4px;
}

.chat-bubble--self {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--ember), #d9506c);
  color: #1b1531;
  border-bottom-right-radius: 4px;
}

.chat-bubble__text {
  margin: 0;
  font-size: 15px;
  white-space: pre-wrap;
}

.chat-bubble__meta {
  font-size: 11px;
  opacity: 0.65;
  align-self: flex-end;
}

.chat-system-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  margin: 6px 0;
}

.message-form {
  display: flex;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid rgba(244, 239, 230, 0.08);
}

.message-form__input {
  flex: 1;
  padding: 13px 16px;
  border-radius: 999px;
  border: 1px solid rgba(244, 239, 230, 0.14);
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
}

.message-form__input:disabled {
  opacity: 0.5;
}

.message-form__submit {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--ember), #d9506c);
  color: #1b1531;
  font-size: 17px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.message-form__submit:hover:not(:disabled) {
  filter: brightness(1.08);
}

.message-form__submit:active:not(:disabled) {
  transform: scale(0.96);
}

.message-form__submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.waiting-panel__pulse {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd7a8, var(--ember) 65%, transparent 100%);
  box-shadow: 0 0 0 0 var(--ember-soft);
  animation: pulse-ring 1.8s ease-out infinite;
  margin-bottom: 16px;
}

.waiting-panel__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  margin: 0;
}

.waiting-panel__body {
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.6;
  margin: 0;
}

.waiting-panel__code {
  font-family: var(--font-mono);
  font-size: 32px;
  letter-spacing: 0.22em;
  color: var(--gold);
  margin: 18px 0 6px;
}

.copy-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 13px 24px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--ember), #d9506c);
  color: #1b1531;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.copy-link-btn:hover {
  filter: brightness(1.08);
}

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

.waiting-panel__code-fallback {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--text-faint);
}

.waiting-panel__code-inline {
  font-family: var(--font-mono);
  color: var(--gold);
  letter-spacing: 0.14em;
}

.waiting-panel__note {
  color: var(--text-faint);
  font-size: 13px;
  max-width: 340px;
  line-height: 1.6;
  margin-top: 18px;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes flicker {
  0%, 100% { opacity: 1; transform: scale(1); }
  45% { opacity: 0.75; transform: scale(0.92); }
  60% { opacity: 1; transform: scale(1.04); }
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 var(--ember-soft); }
  70% { box-shadow: 0 0 0 16px rgba(240, 99, 124, 0); }
  100% { box-shadow: 0 0 0 0 rgba(240, 99, 124, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .landing__ember,
  .waiting-panel__pulse {
    animation: none;
  }
}

@media (max-width: 480px) {
  .waiting-panel__code {
    font-size: 24px;
  }
  .landing__wordmark {
    font-size: 24px;
  }
}
