/* Header.css */

.app-header {
  background: var(--header-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 0;
  border-bottom: 2px solid var(--glass-border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
  z-index: 50;
  position: sticky;
  top: 0;
  transition: all 0.3s ease-in-out;
  -webkit-tap-highlight-color: transparent;
  color: var(--fg);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.app-header.selecting-phase {
  cursor: default;
}

.app-header.login-phase {
  cursor: default;
}

@media (max-width: 768px) {
  .app-header.login-phase {
    padding: 0;
  }
  .app-header.login-phase .header-inner {
    padding: 12px 16px;
  }
}

.header-bottom {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 48px;
}

.desktop-hidden {
  display: none !important;
}

/* 3分割レイアウト */
.header-left {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.header-center {
  display: flex;
  justify-content: center;
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex: 1;
}

/* 中央スロットが空（plain/login や タイマー非表示時）は3分割をやめ、
   タイトルへ残り幅をすべて割り当てる。3分割はタイマー等を正確に
   中央寄せするための等幅レイアウトで、中央が空だとタイトルが
   余白を残したまま省略される（#127 レビュー時に発覚） */
.header-center:empty {
  display: none;
}

.header-bottom:has(.header-center:empty) .header-left {
  flex: 1 1 auto;
}

.header-bottom:has(.header-center:empty) .header-right {
  flex: 0 0 auto;
}

.app-title {
  display: flex;
  align-items: baseline;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--fg);
  overflow: hidden;
  transition: all 0.3s ease-in-out;
}

.test-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
}

.app-title-name {
  color: var(--fg-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 1024px) {
  .app-title-name {
    display: none;
  }
}

/* タイトルの短縮表記（HeaderShell の shortTitle）:
   モバイルでは見切れ防止のため短縮表記に切り替える */
.app-title .title-short {
  display: none;
}

@media (max-width: 768px) {
  .app-title .title-full {
    display: none;
  }

  .app-title .title-short {
    display: inline;
  }
}

/* タイトル左の先頭ボタン（ホーム / 戻る。HeaderShell の leading 位置） */
.home-btn,
.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 8px;
  margin-right: 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.home-btn:hover,
.back-btn:hover {
  background: transparent;
  color: var(--primary);
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: transparent;
  border: 2px solid var(--glass-border);
  color: var(--fg);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 0;
  flex-shrink: 0;
  line-height: 0; /* Prevent baseline text offset */
}

.theme-toggle-btn:hover {
  background: var(--glass-border-hover);
  transform: scale(1.08) rotate(15deg);
}

.theme-toggle-btn svg {
  display: block; /* Eliminate inline spacing */
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center; /* Fix rotation axis offset */
}

.theme-toggle-btn:hover svg {
  transform: rotate(45deg);
}

.theme-toggle-btn .sun-icon {
  color: #fbbf24;
}

.theme-toggle-btn .moon-icon {
  color: #3b82f6;
}

/* タイマー。左=時間表示、右=状態ボタンを塗り分ける2色カプセル(錠剤)形状。
   ボタンが独立した枠を持つと外枠と二重になるため、ボタンはカプセルの
   右半分として全高で塗る。全高は 48px(= .header-bottom の min-height)
   ちょうどに固定する(box-sizing: border-box のため border 込みで 48)。
   これを超えるとヘッダが受験画面だけ高くなり、他画面・公開ページの
   74px と揃わない */
.timer-controls {
  display: flex;
  align-items: stretch;
  background: var(--eval-bg);
  height: 48px;
  border-radius: 9999px;
  border: 2px solid var(--border-color);
  overflow: hidden;
  flex-wrap: nowrap;
}

.timer-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 14px 0 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.2;
}

.elapsed-time {
  font-weight: 700;
  font-size: 1rem;
  color: var(--fg);
}

.time-limit {
  color: var(--fg-muted);
  font-size: 0.75rem;
}

.timer-buttons {
  display: flex;
  align-items: stretch;
}

/* カプセル右半分。枠・角丸は持たず(器の .timer-controls が持つ)、
   塗りの色だけで状態(停止=琥珀 / 再開=紺)を示す */
.timer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 20px 0 16px;
  border: none;
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
  box-shadow: none;
  white-space: nowrap;
}

.start-btn {
  background: #10b981;
  color: white;
}
.start-btn:hover {
  background: #059669;
}

.pause-btn {
  background: #f59e0b;
  color: white;
}
.pause-btn:hover {
  background: #d97706;
}

.resume-btn {
  background: var(--secondary);
  color: var(--bg);
}
.resume-btn:hover {
  background: var(--bg);
  color: var(--secondary);
}

/* 終了・エラーはボタンではないため塗らず、区切り線だけで右半分を分ける */
.timer-status {
  display: flex;
  align-items: center;
  padding: 0 18px 0 14px;
  border-left: 2px solid var(--border-color);
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 13px;
}

/* 提出ボタン */
.submit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 24px;
  background: var(--secondary);
  color: var(--bg);
  border: 2px solid var(--bg);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: none;
}

.submit-btn:hover:not(:disabled) {
  background: var(--bg);
  color: var(--secondary);
  border-color: var(--secondary);
  box-shadow: none;
}

.submit-btn:disabled {
  background: var(--input-border);
  border-color: var(--input-border);
  color: var(--fg-muted);
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.6;
}

/* 注意事項ボタン (Standalone) */
.instruction-standalone-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--fg-muted);
  color: #f9ffff;
  border: 2px solid #f9ffff;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: none;
}

.instruction-standalone-btn:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--bg);
  box-shadow: none;
}

.instruction-standalone-btn svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* メニューボタンとドロップダウン (常時表示) */
.menu-container {
  display: block;
  position: relative;
}

.menu-toggle-btn {
  background: var(--input-bg);
  border: 2px solid var(--input-border);
  color: var(--fg);
  border-radius: 6px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.menu-toggle-btn:hover,
.menu-toggle-btn.open {
  background: var(--eval-bg);
  border-color: var(--fg-muted);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  box-shadow: none;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

.dark-mode .dropdown-menu {
  background: var(--input-bg);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--glass-border);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}

.dropdown-item svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  transform-origin: center;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: var(--eval-bg);
  color: var(--fg);
}

.dropdown-item.active {
  color: var(--primary);
  font-weight: 600;
}

.dropdown-item.active:hover {
  background: var(--eval-bg);
}

.signout-item {
  color: #ef4444;
}
.signout-item:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.mobile-only-menu-item {
  display: none;
}

/* モバイル用展開ヒント */
.header-expand-hint {
  display: none;
  width: 100%;
  height: 12px;
  justify-content: center;
  align-items: center;
  position: absolute;
  bottom: 0;
  left: 0;
  opacity: 0.5;
}

.hint-bar {
  width: 40px;
  height: 4px;
  background-color: var(--input-border);
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* ====================================================
   Mobile Layout (768px以下)
   ==================================================== */
@media (max-width: 768px) {
  .app-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    gap: 0;
    position: sticky;
    top: 0;
    cursor: pointer;
  }

  .header-inner {
    padding: 12px 16px 16px 16px;
  }

  .app-header.selecting-phase .header-inner {
    padding-bottom: 12px;
  }

  .desktop-hidden {
    display: flex !important;
  }

  .mobile-hidden {
    display: none !important;
  }

  .mobile-only-menu-item {
    display: block;
  }

  .header-expand-hint {
    display: flex;
  }

  .app-header:hover .header-expand-hint {
    opacity: 0.8;
  }

  .app-header.expanded .hint-bar {
    width: 6px;
    height: 6px;
    border-radius: 50%;
  }

  /* 上段：タイトルと提出 */
  .header-top {
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 12px;
    overflow: hidden;
    transition:
      max-height 0.3s ease-in-out,
      opacity 0.3s ease-in-out,
      margin 0.3s ease-in-out;
  }

  .header-top .header-left {
    flex: 1;
    min-width: 0;
    margin-right: 12px;
  }

  .app-title {
    font-size: 1rem;
  }

  .submit-btn {
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* 展開していないときは上段（タイトル・提出）を隠す */
  .app-header:not(.expanded) .header-top {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
  }

  .app-header.expanded .header-top {
    max-height: 60px;
    opacity: 1;
    margin-bottom: 12px;
  }

  /* 下段：タイマーとメニューボタンを横並び */
  .header-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 12px;
  }

  .header-center {
    flex: 1;
    min-width: 0;
  }

  .timer-controls {
    width: 100%;
    justify-content: space-between;
  }

  .timer-btn {
    padding: 0 14px;
    font-size: 12px;
  }

  .elapsed-time {
    font-size: 0.9rem;
  }

  .header-right {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
  }
}

/* Dropdown User Info & Trial Badge Styles */
.dropdown-user-info {
  padding: 10px 16px;
  background: var(--eval-bg);
  border-bottom: 2px solid var(--glass-border);
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dropdown-user-info.trial {
  background: rgba(245, 158, 11, 0.08);
}

.dropdown-user-info .user-email-label {
  font-weight: 600;
  color: var(--fg);
}

.dropdown-user-info .user-email {
  font-weight: 500;
  color: var(--fg);
  word-break: break-all;
}

.status-badge.trial {
  align-self: flex-start;
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(245, 158, 11, 0.2);
  color: #d97706;
}

.dark-mode .status-badge.trial {
  background: rgba(245, 158, 11, 0.25);
  color: #fbbf24;
}
