* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "M PLUS Rounded 1c", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(160deg, #FFE1EF 0%, #E7DBFF 45%, #CDEFFF 100%);
  color: #4a3b63;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
  padding-bottom: 64px;
}

.subpage {
  position: fixed;
  inset: 0;
  z-index: 800;
  max-width: 480px;
  margin: 0 auto;
  background: linear-gradient(160deg, #FFE1EF 0%, #E7DBFF 45%, #CDEFFF 100%);
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  padding-bottom: 80px;
}
.subpage .subpage-header {
  background: rgba(255, 253, 249, 0.7);
  backdrop-filter: blur(6px);
}
.subpage.subpage-active {
  transform: translateX(0);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #fff;
  border-top: 1px solid #eee0f2;
  box-shadow: 0 -2px 12px rgba(185, 140, 240, 0.15);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  z-index: 500;
}
.bottom-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: #9a7fc0;
  font-size: 0.7rem;
  padding: 6px 2px;
  cursor: pointer;
}
.bottom-nav-btn.active {
  color: #B98CF0;
  font-weight: 600;
}
.bottom-nav-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.subpage-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(max(env(safe-area-inset-top, 0px), 24px) + 16px) 16px 16px;
  border-bottom: 1px solid #f3e8fb;
  background: #FFFDF9;
}
.subpage-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: #4a3b63;
}
.back-btn {
  background: none;
  border: none;
  color: #B98CF0;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 0;
}
.subpage-body {
  padding: 16px;
}

.announcement-banner {
  position: fixed;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  box-sizing: border-box;
  z-index: 490;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #FFF1C9;
  color: #7a5a1e;
  padding: 10px 14px;
  font-size: 0.85rem;
  line-height: 1.4;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
}
.announcement-banner button {
  background: none;
  border: none;
  color: #7a5a1e;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.searching-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 32px;
  color: #9a7fc0;
  font-size: 0.9rem;
}
.searching-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f0e4fb;
  border-top-color: #B98CF0;
  border-radius: 50%;
  animation: searching-spin 0.9s linear infinite;
}
@keyframes searching-spin {
  to { transform: rotate(360deg); }
}

/* --- お手紙(ボトルメール) --- */
.letter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.letter-tabs .bottom-nav-btn {
  flex-direction: row;
  flex: 1;
  background: #f6effc;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.85rem;
  color: #9a7fc0;
}
.letter-tabs .bottom-nav-btn.active {
  background: #B98CF0;
  color: #fff;
}
#letter-body-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #e6d6f7;
  border-radius: 12px;
  padding: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  color: #4a3b63;
}
#letter-body-input:focus {
  outline: none;
  border-color: #B98CF0;
}
#letter-write-panel .find-btn,
#letter-receive-panel .find-btn {
  margin-top: 12px;
}
#letter-confirm,
#letter-reader {
  margin-top: 20px;
  background: #FFFDF9;
  border: 1px solid #f0e4fb;
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}
.letter-page {
  min-height: 160px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  color: #4a3b63;
  line-height: 1.7;
  text-align: left;
  padding: 4px 2px;
}
.letter-page-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.letter-page-controls button {
  border: 1px solid #e6d6f7;
  background: #fff;
  color: #9a7fc0;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}
.letter-page-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}
#letter-page-indicator {
  font-size: 0.8rem;
  color: #9a7fc0;
}

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(74, 59, 99, 0.35);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}
.modal-body {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: #FFFDF9;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 30px rgba(74, 59, 99, 0.25);
  transform: translateY(24px);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal:not(.hidden) .modal-body {
  transform: translateY(0);
}
.modal-body h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: #4a3b63;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
}

.splash {
  position: fixed;
  inset: 0;
  background: #FFF8EF;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: opacity 0.4s ease;
}
.splash img {
  width: 60%;
  max-width: 280px;
}
.splash.fade-out {
  opacity: 0;
  pointer-events: none;
}

.app-topbar {
  display: flex;
  justify-content: center;
  padding-top: calc(max(env(safe-area-inset-top, 0px), 24px) + 10px);
}
.app-logo {
  height: 120px;
  width: auto;
  display: block;
}

.link-btn {
  background: none;
  border: none;
  color: #9a7fc0;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.4rem;
  font-family: inherit;
}

/* --- 検索前画面 --- */
#screen-search {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 1.5rem 2rem;
  gap: 0.9rem;
}
#screen-search .app-topbar {
  margin: 0 -1.5rem 0.5rem;
}
.tagline {
  margin: 0 0 1rem;
  text-align: center;
  color: #8a6fae;
  font-size: 0.9rem;
  font-weight: 500;
}
.avatar-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.avatar-picker-btn {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: #fff;
  box-shadow: 0 4px 12px rgba(185, 140, 240, 0.3);
  padding: 0;
  cursor: pointer;
}
.avatar-picker-clip {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-picker-btn .avatar-svg {
  width: 62px;
}
.avatar-picker-btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.avatar-picker-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF9ECF 0%, #B98CF0 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  border: 2px solid #fff;
}
.avatar-picker-status {
  min-height: 1.1em;
  margin: 0;
  color: #9a7fc0;
  font-size: 0.75rem;
  font-weight: 600;
}
.avatar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-photo.hidden {
  display: none;
}
.field-hint {
  margin: -0.5rem 0 0;
  font-size: 0.75rem;
  color: #9a86bd;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: #7a5fa0;
}
.field select,
.field input[type="text"] {
  background: #fff;
  border: 2px solid #f0c6e0;
  color: #4a3b63;
  border-radius: 14px;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
}
.field select:focus,
.field input[type="text"]:focus {
  outline: none;
  border-color: #d998c0;
}
.find-btn {
  margin-top: 0.5rem;
  padding: 1.05rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #FF9ECF 0%, #B98CF0 100%);
  color: white;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 6px 0 #d977b3, 0 8px 16px rgba(185, 140, 240, 0.35);
}
.find-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #d977b3, 0 4px 10px rgba(185, 140, 240, 0.3);
}
.find-btn:disabled {
  opacity: 0.5;
}
.setup-status {
  text-align: center;
  min-height: 1.2em;
  color: #9a7fc0;
  font-size: 0.9rem;
  font-weight: 600;
}
.advanced {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: #9a86bd;
}
.advanced summary {
  cursor: pointer;
  padding: 0.4rem 0;
  font-weight: 600;
}
.advanced label {
  display: block;
  margin: 0.4rem 0;
}

/* --- マッチ確認画面 --- */
#screen-matched {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.matched-header {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 800;
  padding: 1.2rem 1rem;
  background: linear-gradient(135deg, #FFB6DC, #C7A6F5);
  color: white;
}
.matched-body {
  flex: 1;
  padding: 1.4rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}
.matched-question {
  text-align: center;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #6a4a9c;
}
.matched-actions {
  display: flex;
  gap: 0.8rem;
  width: 100%;
}
.matched-action-btn {
  flex: 1;
  padding: 0.9rem;
  border-radius: 16px;
  border: 2px solid #f0c6e0;
  background: #fff;
  color: #7a5fa0;
  font-size: 1rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}
.matched-action-btn.primary {
  background: linear-gradient(135deg, #FF9ECF 0%, #B98CF0 100%);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 0 #d977b3;
}
.matched-avatar {
  position: relative;
  display: flex;
  justify-content: center;
  background: #fff;
  border-radius: 50%;
  width: 120px;
  height: 120px;
  align-items: center;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(185, 140, 240, 0.25);
}
.matched-avatar .avatar-svg {
  width: 80px;
}
.matched-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(185, 140, 240, 0.18);
}
.matched-table th,
.matched-table td {
  text-align: left;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid #f5e6f2;
}
.matched-table th {
  width: 38%;
  color: #b08fd6;
  font-weight: 700;
}
.matched-table td {
  color: #4a3b63;
  font-weight: 500;
}
.matched-status {
  min-height: 1.2em;
  color: #9a7fc0;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
  text-align: center;
}

/* --- 通話画面 --- */
#screen-call {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #2d1f45;
}
.moderator-banner {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  z-index: 30;
}
.split {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}
.pane {
  position: relative;
  flex: 1;
  background: linear-gradient(160deg, #4a3672, #2d1f45);
  overflow: hidden;
  border-bottom: 3px solid #1f1533;
  cursor: pointer;
}
.pane::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  box-shadow: inset 0 0 0 0 rgba(255, 158, 207, 0);
  transition: box-shadow 0.15s ease;
}
.pane.speaking::after {
  box-shadow: inset 0 0 0 4px #FF9ECF, inset 0 0 24px 4px rgba(255, 158, 207, 0.55);
  animation: pane-speaking-pulse 1s ease-in-out infinite;
}
.pane.speaking .pane-label {
  color: #FF9ECF;
  text-shadow: 0 0 6px rgba(255, 158, 207, 0.8);
}
@keyframes pane-speaking-pulse {
  0%, 100% { box-shadow: inset 0 0 0 4px #FF9ECF, inset 0 0 24px 4px rgba(255, 158, 207, 0.55); }
  50% { box-shadow: inset 0 0 0 4px #FFD1E8, inset 0 0 30px 8px rgba(255, 158, 207, 0.3); }
}

/* 相手側の画面をタップすると、相手を大きく・自分を小さいワイプ表示に切り替える */
.split.expanded #pane-remote {
  flex: 1;
  border-bottom: none;
}
.split.expanded #pane-local {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 30%;
  max-width: 140px;
  aspect-ratio: 3 / 4;
  flex: none;
  border-radius: 16px;
  border: 3px solid #fff;
  z-index: 5;
  cursor: default;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.pane video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pane video.hidden-video {
  display: none;
}
.avatar-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-wrap.hidden {
  display: none;
}
.avatar-svg {
  width: 34%;
  max-width: 120px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25));
}
.avatar-wrap .avatar-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pane-top {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  pointer-events: none;
}
/* 通話画面の一番上(相手側ペイン)だけ、ステータスバーと被らないよう余白を足す。
   下側のペイン(自分側)は画面の物理的な上端ではないので対象外。 */
#pane-remote .pane-top {
  top: calc(max(env(safe-area-inset-top, 0px), 24px) + 10px);
}
.timer-badge {
  background: rgba(255, 255, 255, 0.9);
  color: #7a4fc9;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
}
.pane-label {
  background: rgba(255, 255, 255, 0.25);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  color: #fff;
}

.report-btn {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: rgba(255, 255, 255, 0.85);
  color: #ff6b8b;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}
.block-btn {
  position: absolute;
  left: 10px;
  top: calc(50% + 42px);
  transform: translateY(-50%);
  border: none;
  background: rgba(255, 255, 255, 0.85);
  color: #6a4a9c;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

.status-icons {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 1.1rem;
}
.status-icon.off {
  opacity: 0.4;
}

.control-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.1rem;
  padding: 1rem 1rem calc(env(safe-area-inset-bottom, 1rem) + 0.6rem);
  background: #1f1533;
}
.control-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #4a3672;
  color: #fff;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.control-btn[aria-pressed="false"] {
  background: #372a54;
  color: #9a86bd;
}
.control-btn.danger {
  background: linear-gradient(135deg, #FF9ECF, #FF6B8B);
}
.control-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.whip-flash {
  position: fixed;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}
.whip-flash.active {
  animation: flash-fade 0.25s ease-out;
}
@keyframes flash-fade {
  0% { opacity: 0.75; }
  100% { opacity: 0; }
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  transform: translate(-50%, -20px);
  background: #4a3672;
  color: #fff;
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(74, 54, 114, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
  max-width: 85%;
  text-align: center;
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.shake {
  animation: shake-anim 0.35s ease-in-out;
}
@keyframes shake-anim {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}
