/* ══════════════════════════════════════
   Base — Reset · Layout · Navigation
   ══════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: #0a0a0a; /* WebView 預設白底；縫隙露出時改深色 */
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-base);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg-base);
  color: var(--text-primary);
  transition: background 0.25s, color 0.25s;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea {
  font-family: inherit;
  font-size: inherit;
  outline: none;
  border: none;
}

a { color: inherit; text-decoration: none; }

img { display: block; max-width: 100%; }

/* ── App Shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  height: var(--real-vh, 100vh);
  position: relative;
  overflow: hidden;
}

#page-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-bottom: var(--nav-height);
}

.page.hidden { display: none; }

/* ── Bottom Navigation ── */
#bottom-nav {
  display: flex;
  align-items: stretch;
  min-height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px) + var(--app-inset-bottom, 0px));
  flex-shrink: 0;
  z-index: 100;
}

/* iOS App 殼：僅 env safe-area，不叠加 JS visualViewport inset */
html.in-app-ios #bottom-nav {
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}

html.in-app-ios #app {
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  height: var(--real-vh-ios, var(--real-vh, 100dvh));
}

html.in-app-ios .toast {
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-tertiary);
  transition: color 0.15s;
  padding: 8px 4px;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.nav-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-badge {
  position: absolute;
  top: -3px;
  right: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid var(--bg-primary);
  pointer-events: none;
}

.nav-badge.hidden {
  display: none;
}

.nav-item.active {
  color: var(--accent);
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ── Center Nav Button ── */
.nav-center {
  color: var(--text-tertiary);
}

.nav-center-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(230, 57, 70, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.nav-center-btn svg {
  width: 20px;
  height: 20px;
  color: #fff;
}

.nav-center.active .nav-center-btn,
.nav-center:active .nav-center-btn {
  transform: scale(0.93);
  box-shadow: 0 1px 6px rgba(230, 57, 70, 0.3);
}

.nav-center.active {
  color: var(--accent);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 0; background: transparent; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--app-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-base);
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.hidden { display: none; }

/* ── Utility ── */
.hidden { display: none !important; }

/* ══════════════════════════════════════
   Desktop Layout (≥ 768px) — Threads style
   ══════════════════════════════════════ */
.desktop-nav-logo { display: none; }

@media (min-width: 768px) {

  /* App shell: side-by-side */
  #app {
    flex-direction: row;
    align-items: stretch;
    height: 100dvh;
    height: 100vh;
  }

  /* ── Left sidebar — narrow icon rail ── */
  #bottom-nav {
    order: -1;
    flex-direction: column;
    align-items: center;
    width: 72px;
    min-width: 72px;
    height: 100%;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 8px 8px 20px;
    justify-content: flex-start;
    gap: 2px;
    overflow: visible;
    flex-shrink: 0;
  }

  /* Desktop logo */
  .desktop-nav-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 0 16px;
    width: 100%;
  }

  .desktop-logo-text {
    font-size: 18px;
    font-weight: 900;
    letter-spacing: -0.5px;
    color: var(--text-primary);
  }

  .desktop-logo-text em {
    font-style: normal;
    color: var(--accent);
  }

  /* Nav items: icon-only, centred */
  .nav-item {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: var(--radius-md);
  }

  .nav-item svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  /* Hide text labels on narrow sidebar */
  .nav-label { display: none; }

  .nav-item:hover { background: var(--bg-elevated); }

  .nav-item.active { color: var(--accent); }

  /* Post button — compact icon circle */
  .nav-center {
    order: 10;
    margin-top: 8px;
    width: 52px;
    height: 52px;
    padding: 0;
    background: none;
    border-radius: var(--radius-full);
  }

  .nav-center-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--accent);
    box-shadow: 0 2px 10px rgba(230,57,70,0.35);
  }

  .nav-center-btn svg { width: 20px; height: 20px; color: #fff; }
  .nav-center:hover .nav-center-btn { opacity: 0.88; }

  .nav-center.active .nav-center-btn,
  .nav-center:active .nav-center-btn { transform: scale(0.93); box-shadow: none; }

  /* Content area */
  #page-content {
    flex: 1;
    overflow: hidden;
    min-width: 0;
  }

  .page {
    padding-bottom: 32px;
    max-width: 640px;
    margin: 0 auto;
  }

  .toast { bottom: 32px; }

  .bottom-sheet-panel {
    max-width: 560px;
    margin: 0 auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}
