/* layout.css : 헤더, 메뉴, 그리드, 챗 레이아웃 */

/* HEADER */

.app-header {
  padding: clamp(12px, 3vw, 14px) clamp(14px, 3vw, 18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #05070d;
  border-bottom: 1px solid #262833;
  position: relative;
  z-index: 100;
}

.menu-icon {
  width: clamp(20px, 5vw, 22px);
  height: clamp(14px, 4vw, 16px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3px 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.menu-icon span {
  height: 2px;
  border-radius: 999px;
  background: #f5f5f7;
}

.header-title {
  font-size: clamp(0.85rem, 2.5vw, 0.95rem);
  font-weight: 500;
}

.lang-toggle {
  font-size: clamp(0.8rem, 2.5vw, 0.9rem);
  cursor: pointer;
  min-height: 24px;
  display: flex;
  align-items: center;
  padding: 4px 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* MENU OVERLAY */

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.menu-overlay.visible {
  display: flex;
}

.menu-panel {
  width: min(90vw, 420px);
  max-height: 90vh;
  background: #05070d;
  border-radius: clamp(14px, 3vw, 18px);
  border: 1px solid #262833;
  padding: clamp(14px, 3vw, 16px) clamp(16px, 3vw, 18px) clamp(16px, 3vw, 18px);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2vw, 12px);
  overflow-y: auto;
}

.menu-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.menu-title {
  font-size: clamp(0.95rem, 2.5vw, 1rem);
  font-weight: 600;
}

.menu-close {
  cursor: pointer;
  font-size: clamp(1rem, 2.5vw, 1.1rem);
  line-height: 1;
  padding: 4px 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.5vw, 8px);
  margin-top: 6px;
  overflow-y: auto;
}

.menu-item {
  font-size: clamp(0.85rem, 2vw, 0.9rem);
  padding: clamp(7px, 1.5vw, 8px) clamp(9px, 2vw, 10px);
  border-radius: 999px;
  border: 1px solid #262833;
  background: #070914;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease;
}

.menu-item:hover,
.menu-item:focus {
  background: #0a0d16;
}

/* PERSONA GRID */

.persona-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr));
  gap: clamp(8px, 2vw, 10px);
  margin-top: clamp(10px, 2vw, 12px);
  width: 100%;
}

@media (min-width: 400px) {
  .persona-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 768px) {
  .persona-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.persona-card {
  border-radius: clamp(12px, 3vw, 16px);
  border: 1px solid #262833;
  background: #070914;
  padding: clamp(6px, 1.5vw, 8px);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s ease, background 0.2s ease;
}

.persona-card:hover,
.persona-card:focus {
  background: #0a0d16;
  transform: translateY(-2px);
}

.persona-card:active {
  transform: translateY(0);
}

.persona-thumb {
  width: 100%;
  border-radius: clamp(10px, 2.5vw, 12px);
  height: clamp(90px, 20vw, 110px);
  object-fit: cover;
  margin-bottom: 6px;
}

.persona-name {
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  font-weight: 600;
  margin-bottom: 3px;
  line-height: 1.3;
}

.persona-desc {
  font-size: clamp(0.75rem, 1.8vw, 0.8rem);
  color: #9ca0b5;
  line-height: 1.4;
}

/* CHAT PAGE */

.chat-page {
  width: 100%;
  height: calc(100vh - clamp(48px, 10vw, 52px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.persona-stage {
  position: relative;
  flex: 1;
  background: #05070d;
  overflow: hidden;
  min-height: 0;
}

.persona-photo-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.persona-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  filter: saturate(1.05);
}

@media (min-width: 768px) {
  .persona-img {
    object-position: center center;
  }
}

.persona-overlay-top {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.15) 45%,
    rgba(5, 7, 13, 0.95) 100%
  );
}

.persona-label {
  position: absolute;
  left: 14px;
  top: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(5, 7, 13, 0.9);
  border: 1px solid rgba(200, 210, 240, 0.6);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.persona-label-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #f5d46b;
  box-shadow: 0 0 10px rgba(245, 212, 107, 0.9);
}

/* Drift text over portrait */

.persona-drift-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(20vh, 25vh, 28vh);
  padding: 0 clamp(12px, 3vw, 16px);
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.5vw, 8px);
  pointer-events: none;
}

@media (min-width: 768px) {
  .persona-drift-text {
    bottom: clamp(26vh, 30vh, 35vh);
    max-width: 600px;
    margin: 0 auto;
  }
}

.drift-line-primary,
.drift-line-secondary {
  display: inline-block;
  max-width: 96%;
  border-radius: clamp(3px, 1vw, 4px);
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  line-height: 1.5;
}

.drift-line-primary {
  background: rgba(0, 0, 0, 0.75);
  color: #f5d46b;
  padding: clamp(5px, 1.2vw, 6px) clamp(8px, 2vw, 10px);
}

.drift-line-secondary {
  background: rgba(0, 0, 0, 0.55);
  color: #f5f5f7;
  padding: clamp(4px, 1vw, 4px) clamp(8px, 2vw, 10px) clamp(5px, 1.2vw, 5px);
}

.drift-left {
  text-align: left;
  direction: ltr;
}

.drift-right {
  text-align: right;
  direction: rtl;
}

.drift-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
}

.drift-cta {
  align-self: center;
  pointer-events: auto;
  margin-top: clamp(12px, 3vw, 16px);
  padding: clamp(5px, 1.2vw, 6px) clamp(12px, 2.5vw, 14px);
  border-radius: 999px;
  border: none;
  background: #f5d46b;
  color: #000;
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s ease;
}

.drift-cta:active {
  transform: scale(0.95);
}

/* Bottom sheet */

.chat-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to top,
    #050509 0%,
    rgba(5, 7, 13, 0.96) 35%,
    rgba(5, 7, 13, 0.0) 100%
  );
  backdrop-filter: blur(24px);
  border-top-left-radius: clamp(14px, 3vw, 18px);
  border-top-right-radius: clamp(14px, 3vw, 18px);
  border-top: 1px solid #262833;
  box-shadow: 0 -8px 25px rgba(0, 0, 0, 0.7);
  transition: transform 0.25s ease-out;
  display: flex;
  flex-direction: column;
  max-height: 88%;
  will-change: transform;
}

@media (min-width: 768px) {
  .chat-sheet {
    max-height: 75%;
  }
}

.chat-sheet.collapsed {
  transform: translateY(100%);
}

.chat-sheet.expanded {
  transform: translateY(0%);
}

.sheet-handle {
  padding: clamp(5px, 1.2vw, 6px) clamp(10px, 2vw, 12px) clamp(8px, 1.5vw, 10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(5px, 1.2vw, 6px);
  cursor: pointer;
  background-color: #050509;
  border-top-left-radius: clamp(14px, 3vw, 18px);
  border-top-right-radius: clamp(14px, 3vw, 18px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sheet-handle-bar {
  width: clamp(38px, 8vw, 42px);
  height: clamp(3px, 0.8vw, 4px);
  border-radius: 999px;
  background: rgb(245, 212, 108);
}

.sheet-handle-hint {
  font-size: clamp(0.65rem, 1.5vw, 0.7rem);
  color: #9ca0b5;
}

.messages {
  flex: 1;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2vw, 12px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.8vw, 10px);
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.status-text {
  font-size: clamp(0.7rem, 1.6vw, 0.75rem);
  color: #9ca0b5;
  padding: 2px clamp(10px, 2vw, 12px) 4px;
  flex-shrink: 0;
  min-height: 18px;
}

.input-bar {
  border-top: 1px solid #262833;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2vw, 12px) clamp(8px, 1.8vw, 10px);
  display: flex;
  gap: clamp(8px, 1.8vw, 10px);
  background: linear-gradient(to top, #050509, rgba(5, 7, 13, 0.9));
  flex-shrink: 0;
  align-items: flex-end;
}

@media (min-width: 768px) {
  .input-bar {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
  }
}

.input-area {
  flex: 1;
  min-width: 0;
}

textarea {
  width: 100%;
  min-height: clamp(44px, 9vw, 48px);
  max-height: clamp(100px, 20vw, 110px);
  resize: none;
  border-radius: clamp(16px, 3vw, 20px);
  border: 1px solid rgba(120, 130, 160, 0.6);
  padding: clamp(9px, 2vw, 10px) clamp(12px, 2.5vw, 14px);
  background: rgba(8, 10, 18, 0.95);
  color: #f5f5f7;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}

.send-btn {
  border-radius: clamp(20px, 4vw, 24px);
  border: none;
  padding: 0 clamp(14px, 3vw, 18px);
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  font-weight: 600;
  cursor: pointer;
  background: #f5d46b;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  height: clamp(42px, 8vw, 44px);
  min-width: clamp(70px, 15vw, 80px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* 메시지 버블 */

.bubble-row {
  display: flex;
  flex-direction: column;
  max-width: min(82%, 450px);
}

@media (max-width: 400px) {
  .bubble-row {
    max-width: 88%;
  }
}

.bubble-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble-row.ai {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble-meta {
  font-size: clamp(0.75rem, 1.8vw, 0.8rem);
  color: #9ca0b5;
  margin-bottom: clamp(3px, 0.8vw, 4px);
}

.bubble {
  border-radius: clamp(14px, 3vw, 18px);
  padding: clamp(9px, 2vw, 10px) clamp(12px, 2.5vw, 14px);
  line-height: 1.5;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  border: 1px solid rgba(120, 130, 160, 0.4);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.bubble.user {
  background: #273349;
}

.bubble.ai {
  background: #11171f;
  border-color: rgba(245, 212, 107, 0.5);
}

/* Responsive adjustments */

@media (max-width: 360px) {
  .persona-thumb {
    height: clamp(80px, 18vw, 96px);
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .chat-sheet {
    max-height: 80%;
  }

  .persona-drift-text {
    bottom: 15vh;
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  .app-header {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .input-bar {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}