* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Hiragino Sans', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #333;
  background: #f5f5f5;
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.logo {
  font-size: 1.25rem;
  font-weight: bold;
  color: #4a90d9;
  text-decoration: none;
}

/* ヘッダーナビ（アイコンのみ・コンパクト） */
.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  color: #666;
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.header-nav-item:hover {
  color: #4a90d9;
  background: #f0f7ff;
}

.header-nav-item.active {
  color: #4a90d9;
}

.header-nav-item svg {
  width: 24px;
  height: 24px;
}

.header-nav-item:not(:has(svg)) {
  font-size: 0.8rem;
}

.main {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 12px;
  min-height: calc(100vh - 52px);
}

/* Auth forms */
.auth-form {
  background: #fff;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.auth-form h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
  color: #555;
}

.form-group input {
  width: 100%;
  padding: 8px 10px;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.btn-primary {
  width: 100%;
  padding: 10px;
  font-size: 1rem;
  font-weight: 500;
  color: #fff;
  background: #4a90d9;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn-primary:hover {
  background: #3a7bc8;
}

.error {
  margin-bottom: 12px;
  padding: 10px;
  color: #c00;
  background: #ffe0e0;
  border-radius: 4px;
  font-size: 0.9rem;
}

.success {
  margin-bottom: 12px;
  padding: 10px;
  color: #155724;
  background: #d4edda;
  border-radius: 4px;
  font-size: 0.9rem;
}

.auth-divider {
  margin: 16px 0;
  text-align: center;
  color: #999;
  font-size: 0.9rem;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 500;
  color: #333;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-google:hover {
  background: #f8f9fa;
  border-color: #ccc;
}

.btn-google-icon {
  flex-shrink: 0;
}

.auth-link {
  margin-top: 16px;
  text-align: center;
}

.auth-link a {
  color: #4a90d9;
  text-decoration: none;
}

/* Casts list */
.casts-page h1 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

/* チャットルーム一覧 */
.cast-list {
  width: 100%;
  margin-top:6px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.cast-room-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 12px;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid #eee;
  gap: 6px;
}

.cast-room-item:hover {
  background: #f8f9fa;
}

.cast-room-item:hover .col-name {
  color: #4a90d9;
}

.cast-room-top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.col-icon {
  flex-shrink: 0;
  width: 48px;
  min-height: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.col-icon-avatar {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cast-list .avatar-placeholder.small {
  width: 40px;
  height: 40px;
  font-size: 1rem;
}

.cast-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.col-intimacy {
  font-size: 0.75rem;
  line-height: 1;
  color: #666;
}

.col-name {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-datetime {
  flex-shrink: 0;
  font-size: 0.9rem;
  color: #666;
}

.col-preview {
  width: 100%;
  font-size: 0.9rem;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-unread {
  flex-shrink: 0;
}

.unread-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  background: #e74c3c;
  color: #fff;
  border-radius: 4px;
}

.cast-list .no-casts {
  padding: 24px;
  text-align: center;
  color: #666;
}

/* デスクトップ: 1行レイアウト（アイコン|名前|日時|プレビュー|未読） */
@media (min-width: 601px) {
  .cast-room-item {
    flex-wrap: nowrap;
  }

  .cast-room-top {
    flex: 0 0 auto;
    min-width: 0;
  }

  .col-name {
    min-width: 120px;
  }

  .col-datetime {
    width: 160px;
  }

  .col-preview {
    width: auto;
    flex: 1;
    min-width: 0;
    max-width: 200px;
  }
}

/* スマホ: 2行レイアウト（上段: アイコン|キャスト名|日時、下段: メッセージ内容） */
@media (max-width: 600px) {
  .cast-room-item {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .cast-room-top {
    flex: none;
  }

  .col-preview {
    padding-left: 48px; /* アイコン幅 + gap でインデント */
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.cast-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
  border-radius: 50%;
  overflow: hidden;
  background: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cast-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-placeholder {
  font-size: 2rem;
  font-weight: bold;
  color: #999;
}

.cast-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.cast-description {
  margin: 0;
  font-size: 0.85rem;
  color: #666;
  line-height: 1.4;
}

.no-casts {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
  color: #666;
}

/* キャスト検索 */
.search-page h1 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  padding: 8px 10px;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

/* キャスト検索 表示切替 */
.cast-view-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.cast-view-label {
  font-size: 0.9rem;
  color: #666;
}

.cast-view-toggle {
  display: flex;
  gap: 0;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
}

.cast-view-btn {
  padding: 6px 12px;
  font-size: 0.9rem;
  border: none;
  background: #fff;
  color: #666;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.cast-view-btn:hover {
  background: #f5f5f5;
}

.cast-view-btn.active {
  background: #4a90d9;
  color: #fff;
}

.cast-view-btn + .cast-view-btn {
  border-left: 1px solid #ddd;
}

.cast-view-btn.active + .cast-view-btn,
.cast-view-btn + .cast-view-btn.active {
  border-left-color: transparent;
}

/* キャスト検索結果 - カード表示 */
.cast-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.cast-results[data-view="card"] .cast-result-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
}

.cast-results[data-view="card"] .cast-result-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.cast-results[data-view="card"] .cast-result-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 8px;
  border-radius: 50%;
  overflow: hidden;
  background: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cast-results[data-view="card"] .cast-result-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cast-results[data-view="card"] .cast-result-info {
  width: 100%;
  text-align: center;
}

.cast-results[data-view="card"] .cast-result-name {
  display: block;
  margin: 0 0 2px;
  font-size: 1rem;
  font-weight: 600;
}

.cast-results[data-view="card"] .cast-result-age {
  display: block;
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 4px;
}

.cast-results[data-view="card"] .cast-result-desc {
  display: -webkit-box;
  font-size: 0.85rem;
  color: #666;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* キャスト検索結果 - 一覧表示 */
.cast-results[data-view="list"] {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.cast-results[data-view="list"] .cast-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid #eee;
  transition: background 0.2s;
}

.cast-results[data-view="list"] .cast-result-item:last-child {
  border-bottom: none;
}

.cast-results[data-view="list"] .cast-result-item:hover {
  background: #f8f9fa;
}

.cast-results[data-view="list"] .cast-result-item:hover .cast-result-name {
  color: #4a90d9;
}

.cast-results[data-view="list"] .cast-result-avatar {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  background: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cast-results[data-view="list"] .cast-result-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cast-results[data-view="list"] .cast-result-avatar .avatar-placeholder {
  font-size: 1.25rem;
}

.cast-results[data-view="list"] .cast-result-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cast-results[data-view="list"] .cast-result-name {
  font-size: 1rem;
  font-weight: 600;
}

.cast-results[data-view="list"] .cast-result-age {
  font-size: 0.85rem;
  color: #888;
  margin-right: 8px;
}

.cast-results[data-view="list"] .cast-result-desc {
  font-size: 0.85rem;
  color: #666;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cast-results .no-casts {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
  color: #666;
}

.cast-results[data-view="list"] .no-casts {
  grid-column: unset;
}

/* キャストプロフィール */
.cast-profile-page {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.cast-profile-header {
  margin-bottom: 16px;
}

.cast-profile-header .back-link {
  color: #4a90d9;
  text-decoration: none;
  font-size: 0.9rem;
}

.cast-profile-card {
  text-align: center;
}

.cast-profile-avatar {
  width: 120px;
  height: 120px;
  margin: 0 auto 16px;
  border-radius: 50%;
  overflow: hidden;
  background: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cast-profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cast-profile-avatar .avatar-placeholder.large {
  font-size: 3rem;
  font-weight: bold;
  color: #999;
}

.cast-profile-name {
  margin: 0 0 12px;
  font-size: 1.5rem;
}

.cast-profile-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin: 0 0 16px;
  padding: 0;
  font-size: 0.9rem;
  color: #555;
}


.cast-profile-description {
  margin: 0 0 16px;
  text-align: left;
  line-height: 1.6;
  white-space: pre-wrap;
}

.btn-chat {
  display: inline-block;
  padding: 10px 24px;
  font-size: 1rem;
  font-weight: 500;
  color: #fff;
  background: #4a90d9;
  text-decoration: none;
  border-radius: 8px;
}

.btn-chat:hover {
  background: #3a7bc8;
}

.cast-profile-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.cast-profile-actions .inline-form {
  display: inline;
}

.btn-end-chat {
  padding: 8px 20px;
  font-size: 0.9rem;
  color: #c00;
  background: transparent;
  border: 1px solid #c00;
  border-radius: 8px;
  cursor: pointer;
}

.btn-end-chat:hover {
  background: #ffe0e0;
}

/* Chat */
.chat-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 52px);
  height: calc(100dvh - 52px);
  margin: 0 -12px;
  background: #fff;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.back-link {
  color: #4a90d9;
  text-decoration: none;
  font-size: 0.9rem;
}

.chat-cast-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-cast-info .cast-icon-link {
  display: flex;
  text-decoration: none;
  flex-shrink: 0;
}

.chat-cast-info .cast-icon-link:hover {
  opacity: 0.9;
}

.chat-intimacy {
  font-size: 0.75rem;
  color: #666;
  flex-shrink: 0;
}

.cast-avatar-small,
.avatar-placeholder.small {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-placeholder.small {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e0e0e0;
  font-size: 1rem;
  color: #999;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-loading {
  color: #999;
  font-size: 0.9rem;
  padding: 12px 0;
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 90%;
  align-self: flex-start;
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-assistant .message-bubble {
  background: #f0f0f0;
  color: #333;
}

.message-user .message-bubble {
  background: #4a90d9;
  color: #fff;
}

.message-bubble {
  padding: 6px 10px;
  border-radius: 12px;
}

.message-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.message-time {
  font-size: 0.7rem;
  color: #666;
  line-height: 1.3;
}

.message-user .message-time {
  color: #999;
}

.message-emotion {
  font-size: 1.2em;
  line-height: 1;
}

.chat-input-area {
  width:100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid #e0e0e0;
  box-sizing: border-box;
}

.send-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.send-form textarea {
  flex: 1;
  padding: 8px 10px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #ddd;
  border-radius: 8px;
  resize: none;
  min-height: 44px;
  max-height: 120px;
}

.btn-send {
  padding: 8px 16px;
  font-size: 1rem;
  font-weight: 500;
  color: #fff;
  background: #4a90d9;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-send:hover {
  background: #3a7bc8;
}

.btn-send:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Profile */
.profile-page {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.profile-page h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.profile-form .form-group select {
  width: 100%;
  max-width: 300px;
  padding: 8px 10px;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.profile-form .form-group input[type="date"] {
  width: 100%;
  max-width: 200px;
  padding: 8px 10px;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.profile-form .form-group textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  resize: vertical;
}

.char-count {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: #666;
}

.photo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photo-item {
  position: relative;
  width: 100px;
  height: 100px;
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.btn-delete-photo {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 4px 8px;
  font-size: 0.75rem;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.photo-upload input {
  padding: 8px 0;
}

.photo-hint {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: #666;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn-secondary {
  display: inline-block;
  padding: 8px 16px;
  background: #6c757d;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.9rem;
}

.btn-secondary:hover {
  color: #fff;
  background: #5a6268;
}
