/* ロゴ（Cormorant Garamond）のみWebフォントを使用。他はすべてシステムフォント。 */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600&display=swap');

/* ─── Variables ─────────────────────────────────────── */
:root {
  --bg:          #f4f7fb;
  --surface:     #ffffff;
  --surface2:    #eef3fa;
  --surface3:    #e3ebf5;
  --border:      #dde5ef;
  --border-light:#c9d5e5;
  --gold:        #1959b4;
  --gold2:       #2f7fd9;
  --gold3:       #5bbdff;
  --gold-bg:     #1959b414;
  --gold-dim:    #8fb5e0;
  --text:        #14233a;
  --text-2:      #3d4f66;
  --text-muted:  #6c7a8c;
  --text-dim:    #9aa8b8;
  --red:         #d64545;
  --red-bg:      #d6454514;
  --green:       #2e9e63;
  --green-bg:    #2e9e6314;
  --radius:      6px;
  --radius-lg:   10px;
  --transition:  0.18s ease;
  --font-serif:  'Cormorant Garamond', Georgia, serif;
  --font-gothic: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic Medium', 'Yu Gothic', 'Meiryo', sans-serif;
  --font-sans:   -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic Medium', 'Yu Gothic', 'Meiryo', sans-serif;
  --font-mono:   ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, Consolas, monospace;
  --logo-gradient: linear-gradient(135deg, #1959b4, #5bbdff);
}

/* ─── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-gothic);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold2); }
img { max-width: 100%; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

/* ─── Logo gradient utility ──────────────────────────── */
.logo-text {
  background: var(--logo-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ─── Navbar ─────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  backdrop-filter: blur(10px);
}
.navbar-brand { display: flex; flex-direction: column; gap: 3px; text-decoration: none; }
.navbar-brand .brand-name {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 2px;
  line-height: 1;
  background: var(--logo-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.navbar-brand .brand-sub {
  font-family: var(--font-gothic);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--text-dim);
  line-height: 1;
  -webkit-text-fill-color: var(--text-dim);
}
.navbar-right { display: flex; align-items: center; gap: 20px; }
.nav-links { display: flex; gap: 2px; }
.nav-link {
  padding: 6px 12px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  transition: var(--transition);
  font-family: var(--font-gothic);
}
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--gold); background: var(--gold-bg); }
.nav-user {
  display: flex; align-items: center; gap: 12px;
  padding-left: 20px; border-left: 1px solid var(--border);
}
.nav-remaining {
  font-family: var(--font-gothic);
  font-size: 11px; color: var(--text-muted);
}
.nav-remaining span { color: var(--gold2); font-weight: 500; }
.nav-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--gold-bg); border: 1px solid var(--gold-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  font-family: var(--font-gothic);
  background: var(--logo-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.nav-logout {
  font-size: 12px; color: var(--text-dim);
  padding: 4px 8px; border-radius: var(--radius);
  transition: var(--transition);
  font-family: var(--font-gothic);
}
.nav-logout:hover { color: var(--red); }

/* ─── Layout ─────────────────────────────────────────── */
.page { min-height: calc(100vh - 64px); }
.container { max-width: 900px; margin: 0 auto; padding: 40px 24px; }
.container-lg { max-width: 1100px; margin: 0 auto; padding: 40px 24px; }

/* ─── Page Header ────────────────────────────────────── */
.page-header { margin-bottom: 36px; }
.page-header h1 {
  font-family: var(--font-gothic);
  font-size: 28px; font-weight: 700;
  color: var(--text); letter-spacing: 0.04em;
  margin-bottom: 8px; line-height: 1.4;
}
.page-header p { color: var(--text-muted); font-size: 14px; }

/* ─── Cards ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.card-gold {
  background: var(--gold-bg);
  border-color: var(--gold-dim);
}
.card + .card { margin-top: 16px; }

/* ─── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  font-family: var(--font-gothic);
  transition: var(--transition); cursor: pointer;
  border: 1px solid transparent;
  letter-spacing: 0.02em;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--gold); color: #ffffff;
  border-color: var(--gold);
}
.btn-primary:hover:not(:disabled) { background: var(--gold2); border-color: var(--gold2); }
.btn-outline {
  background: transparent; color: var(--gold);
  border-color: var(--gold-dim);
}
.btn-outline:hover:not(:disabled) { border-color: var(--gold); background: var(--gold-bg); }
.btn-ghost {
  background: transparent; color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface2); }
.btn-danger {
  background: transparent; color: var(--red);
  border-color: transparent;
}
.btn-danger:hover:not(:disabled) { background: var(--red-bg); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 13px 28px; font-size: 14px; }
.btn-icon { width: 34px; height: 34px; padding: 0; }

/* ─── Forms ──────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block; margin-bottom: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  letter-spacing: 0.06em; text-transform: uppercase;
  font-family: var(--font-gothic);
}
.form-label .required { color: var(--gold); margin-left: 2px; }
.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-gothic);
  font-size: 14px;
  padding: 10px 14px;
  transition: var(--transition);
  outline: none;
  appearance: none;
}
.form-input::placeholder, .form-textarea::placeholder {
  color: var(--text-dim);
  opacity: 1;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px var(--gold-bg);
}
.form-textarea {
  resize: vertical; min-height: 120px;
  font-family: var(--font-gothic); font-size: 13px; line-height: 1.65;
}
.form-hint { margin-top: 5px; font-size: 12px; color: var(--text-muted); }
.form-error { margin-top: 5px; font-size: 12px; color: var(--red); }
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a7888' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px; cursor: pointer;
}
.form-select option { background: var(--surface2); }

/* ─── Toggle / Tab ───────────────────────────────────── */
.toggle-group {
  display: inline-flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.toggle-btn {
  padding: 8px 20px; font-size: 13px; font-weight: 500;
  color: var(--text-muted); transition: var(--transition);
  border: none; background: none; cursor: pointer;
  font-family: var(--font-gothic);
}
.toggle-btn.active { background: var(--gold); color: #ffffff; }
.toggle-btn:not(.active):hover { color: var(--text); }

/* ─── Alerts ─────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; display: flex; align-items: flex-start; gap: 10px;
  line-height: 1.5;
}
.alert-error { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); }
.alert-success { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }
.alert-info { background: var(--gold-bg); border: 1px solid var(--gold-dim); color: var(--gold2); }

/* ─── Badges ─────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.06em;
  font-family: var(--font-gothic);
}
.badge-gold { background: var(--gold-bg); color: var(--gold2); border: 1px solid var(--gold-dim); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-muted { background: var(--surface3); color: var(--text-muted); }
.badge-light    { background: var(--surface3); color: var(--text-muted); border: 1px solid var(--border); }
.badge-standard { background: var(--gold-bg); color: var(--gold2); border: 1px solid var(--gold-dim); }
.badge-premium  { background: linear-gradient(135deg, #1959b428, #5bbdff18); color: var(--gold); border: 1px solid var(--gold); }

/* ─── Post Card ──────────────────────────────────────── */
.post-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
}
.post-card + .post-card { margin-top: 12px; }
.post-card.adopted { border-color: var(--green); }
.post-card.rejected { border-color: var(--text-dim); opacity: 0.55; }
.post-body {
  font-family: var(--font-gothic);
  font-size: 13px; line-height: 1.85;
  white-space: pre-wrap; color: var(--text);
}
.post-body[contenteditable] {
  cursor: text; outline: none;
  border-radius: var(--radius);
  padding: 8px 10px; margin: -8px -10px;
  transition: background 0.15s, box-shadow 0.15s;
}
.post-body[contenteditable]:hover {
  background: rgba(25,89,180,0.05);
}
.post-body[contenteditable]:focus {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.post-actions {
  display: flex; align-items: center; gap: 8px; margin-top: 14px;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.post-meta { margin-left: auto; font-size: 10px; color: var(--text-muted); font-family: var(--font-gothic); }
.thread-label {
  font-size: 10px; color: var(--text-dim); font-family: var(--font-gothic);
  letter-spacing: 0.05em; margin-bottom: 8px;
}

/* ─── Theme Selector ─────────────────────────────────── */
.theme-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.theme-card {
  padding: 14px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer; transition: var(--transition);
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font-gothic);
}
.theme-card:hover { border-color: var(--gold-dim); color: var(--text); }
.theme-card.selected { border-color: var(--gold); background: var(--gold-bg); color: var(--gold2); }
.theme-card .theme-icon { font-size: 20px; display: block; margin-bottom: 6px; }

/* ─── Stats ──────────────────────────────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.stat-label {
  font-size: 11px; color: var(--text-muted); margin-bottom: 10px;
  font-family: var(--font-gothic); letter-spacing: 0.05em; text-transform: uppercase;
}
.stat-value {
  font-family: var(--font-gothic);
  font-size: 36px; font-weight: 600; line-height: 1;
  background: var(--logo-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ─── Progress bar ───────────────────────────────────── */
.progress-wrap { margin-top: 8px; }
.progress-bar {
  height: 3px; background: var(--surface3); border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--logo-gradient);
  border-radius: 2px; transition: width 0.4s ease;
}

/* ─── Table ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { border-bottom: 1px solid var(--border); }
th {
  padding: 10px 14px; text-align: left;
  color: var(--text-dim); font-weight: 500;
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  font-family: var(--font-gothic);
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* ─── Spinner ────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Loading overlay ────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(244,247,251,0.9);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 20px;
  z-index: 999; backdrop-filter: blur(6px);
}
.loading-overlay .spinner { width: 40px; height: 40px; border-width: 3px; }
.loading-overlay p { color: var(--text-muted); font-size: 14px; font-family: var(--font-gothic); }

/* ─── Auth Pages ─────────────────────────────────────── */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #dbe9fb 0%, var(--bg) 65%);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
}
.auth-logo { text-align: center; margin-bottom: 36px; }
.auth-logo .brand-name {
  font-family: var(--font-serif);
  font-size: 26px; font-weight: 600;
  letter-spacing: 2px; line-height: 1;
  background: var(--logo-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: block;
}
.auth-logo .brand-sub {
  font-family: var(--font-gothic);
  font-size: 9px; letter-spacing: 3px;
  color: var(--text-dim); margin-top: 6px;
  display: block;
}
.auth-title {
  font-size: 16px; font-weight: 500; margin-bottom: 24px;
  text-align: center; color: var(--text-2);
  font-family: var(--font-gothic);
}
.auth-footer { margin-top: 20px; text-align: center; font-size: 13px; color: var(--text-muted); line-height: 1.7; }
.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0; color: var(--text-dim); font-size: 11px;
  font-family: var(--font-gothic); letter-spacing: 0.05em;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ─── Section headers ─────────────────────────────────── */
.section-title {
  font-family: var(--font-gothic);
  font-size: 15px; font-weight: 600; color: var(--text);
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  letter-spacing: 0.03em;
}
.section-title::before {
  content: ''; display: block;
  width: 2px; height: 14px;
  background: var(--logo-gradient);
  border-radius: 2px; flex-shrink: 0;
}

/* ─── Empty state ────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 16px; opacity: 0.6; }
.empty-state h3 {
  font-family: var(--font-gothic);
  font-size: 18px; color: var(--text-2); margin-bottom: 8px;
}
.empty-state p { font-size: 14px; line-height: 1.7; }
.empty-state .btn { margin-top: 20px; }

/* ─── Toast ──────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px; font-size: 13px;
  min-width: 240px; max-width: 360px;
  display: flex; align-items: center; gap: 10px;
  animation: slideIn 0.2s ease;
  box-shadow: 0 4px 24px rgba(20,35,58,0.14);
  font-family: var(--font-gothic);
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─── Confirm dialog ─────────────────────────────────── */
.confirm-overlay {
  display: none; position: fixed; inset: 0; z-index: 3000;
  background: rgba(20,35,58,.45); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; padding: 20px;
}
.confirm-overlay.open { display: flex; }
.confirm-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 28px 24px;
  width: 100%; max-width: 380px;
  animation: confirmIn 0.15s ease;
}
.confirm-message {
  font-size: 15px; line-height: 1.6; margin-bottom: 24px; color: var(--text);
}
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }
@keyframes confirmIn {
  from { transform: scale(0.96); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ─── Skeleton loading ───────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--radius);
}
/* ナビが空のとき（JS読み込み前）にロゴプレースホルダーを表示 */
.navbar:empty::before {
  content: 'Toukou TASUKALE';
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 2px;
  background: var(--logo-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ─── Responsive ─────────────────────────────────────── */
.bottom-nav { display: none; }

@media (max-width: 640px) {
  .container, .container-lg { padding: 24px 16px; }
  .navbar { padding: 0 16px; height: 52px; }
  .nav-links { display: none; }
  .stat-grid, .theme-grid { grid-template-columns: 1fr 1fr; }
  .nav-user { padding-left: 0; border-left: none; gap: 8px; }
  .progress-wrap, .nav-avatar, .nav-logout { display: none; }
  body { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); overscroll-behavior-y: none; }
  .toast-container { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); right: 16px; }
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
    backdrop-filter: blur(10px);
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 2px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-item.active { color: var(--gold); }
  .bottom-nav-item:active { color: var(--gold2); }
  .bottom-nav-label {
    font-size: 10px;
    font-family: var(--font-gothic);
    letter-spacing: 0.02em;
    line-height: 1;
  }
}

/* iOS Safari はフォーカス時に font-size < 16px の入力要素を自動ズームするため、
   モバイルではすべての入力要素を 16px に統一する。
   inline style を持つ要素も上書きするため !important を使用。 */
@media (max-width: 768px) {
  input, textarea, select {
    font-size: 16px !important;
  }
}
