:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #08111f;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #ffea00;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  width: min(100vw, 480px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  position: relative;
  overflow: hidden;
}

.scene {
  min-height: calc(100vh - 38px);
  min-height: calc(100dvh - 38px);
  display: flex;
  flex-direction: column;
}

.scene[hidden] {
  display: none;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 18px 0 12px;
}

.app-logo {
  max-height: clamp(44px, 13vw, 66px);
  width: auto;
  display: block;
}

.about-btn {
  position: absolute;
  right: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.28);
  background: transparent;
  color: #222;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 150ms, color 150ms;
}

.about-btn:hover,
.about-btn:focus-visible {
  border-color: rgba(0, 0, 0, 0.6);
  outline: none;
}

.compose-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(16px, 5vh, 36px);
}

.compose-heading {
  font-size: clamp(30px, 11vw, 68px);
  font-weight: 900;
  color: #111;
  text-align: center;
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.input-pill {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.38);
  border-radius: 999px;
  padding: 8px 8px 8px 22px;
  gap: 8px;
}

.input-pill input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: clamp(15px, 4vw, 17px);
  color: #333;
}

.input-pill input::placeholder {
  color: rgba(0, 0, 0, 0.32);
}

textarea {
  width: 100%;
  min-height: 180px;
  resize: none;
  border: 1px solid rgba(148, 163, 184, 0.42);
  border-radius: 8px;
  padding: 16px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.76);
  outline: none;
  line-height: 1.6;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

textarea:focus {
  border-color: #2dd4bf;
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.18);
}

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

#counter,
.form-message {
  color: #928c4e;
  font-size: 13px;
}

#sendButton {
  width: clamp(46px, 12vw, 54px);
  height: clamp(46px, 12vw, 54px);
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.52);
  color: #444;
  font-size: clamp(16px, 4.5vw, 20px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 150ms;
}

#sendButton:hover {
  background: rgba(255, 255, 255, 0.72);
}

#sendButton:disabled {
  opacity: 0.45;
}

.launch-scene {
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
}

.sky {
  position: relative;
  width: min(78vw, 320px);
  height: min(62vh, 520px);
  display: grid;
  place-items: end center;
  padding-bottom: 42px;
  touch-action: none;
}

.sky::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background:
    linear-gradient(rgba(248, 250, 252, 0.5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(248, 250, 252, 0.5) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, transparent, black 22%, black 78%, transparent);
}

.orb {
  width: clamp(100px, 30vw, 130px);
  height: clamp(100px, 30vw, 130px);
  border: 0;
  display: block;
  position: relative;
  z-index: 1;
  touch-action: none;
  transition: transform 180ms ease, opacity 180ms ease;
  cursor: pointer;
}

.orb--pair {
  width: min(72vw, 200px);
}

.trail {
  position: absolute;
  bottom: 34px;
  width: 52px;
  height: 160px;
  opacity: 0;
  border-radius: 50%;
  background: radial-gradient(ellipse 60% 45% at 50% 60%, var(--trail-color, #5eead4) 30%, transparent 100%);
  filter: blur(4px);
  transform: translateY(50px) scale(0.7, 0.4);
}

.launching .orb {
  animation: fly-away 1100ms linear forwards;
}

.launching .trail {
  animation: trail-burst 600ms ease-out forwards;
}

.launch-hint,
.sent-message {
  min-height: 32px;
  margin: 0;
  color: #e2e8f0;
  font-weight: 800;
}

.sent-message {
  color: #788645;
}

@keyframes fly-away {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  32% {
    opacity: 1;
    transform: translateY(-45vh) scale(0.80);
  }
  70% {
    opacity: 0;
    transform: translateY(-90vh) scale(0.50);
  }
  100% {
    opacity: 0;
    transform: translateY(-92vh) scale(0.38);
  }
}

/* World Scene */
.world-scene {
  background: #edf8f5;
  padding: 0;
  position: relative;
  overflow: hidden;
  flex-direction: column;
  align-items: stretch;
}

.world-scene.scene-active {
  animation: world-fade-in 500ms ease forwards;
}

@keyframes world-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.world-header {
  position: absolute;
  top: max(64px, env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  text-align: center;
  z-index: 2;
  pointer-events: none;
  user-select: none;
}

.world-title {
  font-size: clamp(32px, 10vw, 52px);
  font-weight: 900;
  color: #111;
  margin: 0;
  letter-spacing: 0.08em;
  line-height: 1.15;
}

.world-subtitle {
  font-size: 15px;
  color: #333;
  margin: 10px 0 0;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.world-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

@keyframes trail-burst {
  0% {
    opacity: 0;
    transform: translateY(50px) scale(0.7, 0.4);
    filter: blur(8px);
  }
  12% {
    opacity: 1;
    transform: translateY(0px) scale(1.15, 0.65);
    filter: blur(3px);
  }
  42% {
    opacity: 0.9;
    transform: translateY(-140px) scale(0.72, 1.8);
    filter: blur(3px);
  }
  100% {
    opacity: 0;
    transform: translateY(-380px) scale(0.2, 3.0);
    filter: blur(12px);
  }
}

/* 横向き防止オーバーレイ */
.rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #ffea00;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #111;
  text-align: center;
  padding: 24px;
}

.rotate-overlay svg {
  width: 56px;
  height: 56px;
  animation: rotate-hint 2s ease-in-out infinite;
}

.rotate-overlay p {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  40%       { transform: rotate(-90deg); }
  60%       { transform: rotate(-90deg); }
}

@media (orientation: landscape) {
  .rotate-overlay {
    display: flex;
  }
}

/* 極小画面 (340px 以下) */
@media (max-width: 340px) and (orientation: portrait) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }
  .about-btn {
    font-size: 10px;
    padding: 7px 8px 7px 6px;
    gap: 3px;
  }
  .input-pill {
    padding-left: 14px;
  }
}
