/* ============================================================
   Study Bot LIFF — mobile-stable shell for LINE in-app browser
   ============================================================ */
:root {
  --app-bg: #F4F6FB;
  --app-card: rgba(255,255,255,0.92);
  --app-border: rgba(226,232,240,0.95);
  --app-text: #1A1A2E;
  --app-muted: #8A94A6;
  --app-shell-max: 680px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --tabs-h: 58px; /* inner height of tab bar buttons */
}

* {
  box-sizing: border-box;
  font-family: 'Prompt', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  background: var(--app-bg);
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.85), rgba(244,246,251,0.98)),
    var(--app-bg);
  color: var(--app-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior-y: none;
}

#root {
  width: 100%;
  /* --app-height is set by JS in index.html (window.innerHeight).
     This is the only reliable height in LINE's in-app WebView on both
     iOS and Android — 100vh/100dvh can report wrong values there. */
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

input, select, textarea, button {
  font-size: 16px !important;
  font-family: 'Prompt', sans-serif;
}

button, input, select, textarea {
  touch-action: manipulation;
}

.material-symbols-rounded {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.app-shell {
  width: min(100%, var(--app-shell-max));
  margin: 0 auto;
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: transparent;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: calc(var(--safe-top) + 10px);
  padding-left: max(16px, calc(var(--safe-left) + 12px));
  padding-right: max(16px, calc(var(--safe-right) + 12px));
  padding-bottom: 10px;
  background: rgba(255,255,255,0.88);
  border-bottom: 1px solid rgba(226,232,240,0.75);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
}

.app-content {
  flex: 1;
  min-height: 0; /* critical: allows flex child to shrink for scroll to work */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-left: max(16px, calc(var(--safe-left) + 12px));
  padding-right: max(16px, calc(var(--safe-right) + 12px));
  padding-top: 14px;
  padding-bottom: 90px; /* clearance for FAB (tabs-bar is in flex flow, not fixed) */
}

.app-tabs {
  position: sticky;
  bottom: 0;
  z-index: 40;
  padding-left: max(10px, calc(var(--safe-left) + 8px));
  padding-right: max(10px, calc(var(--safe-right) + 8px));
  padding-bottom: max(8px, var(--safe-bottom));
  background: linear-gradient(180deg, rgba(244,246,251,0) 0%, rgba(244,246,251,0.9) 20%, rgba(255,255,255,0.96) 45%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.tabs-surface {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(226,232,240,0.9);
  border-radius: 24px;
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.08);
}

.tab-active { color: #1A1A2E; }
.tab-active::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 3px;
  background: #1A1A2E;
  border-radius: 999px;
}

.safe-bottom {
  padding-bottom: max(8px, var(--safe-bottom));
}

.modal-backdrop {
  background: rgba(15,15,30,0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Modal max-height: svh excludes browser chrome + keyboard */
.modal-sheet {
  max-height: 88vh;   /* fallback */
  max-height: 88svh;  /* small viewport height — shrinks when keyboard opens */
}

/* Hide FAB when keyboard is open (any input/textarea focused) */
body:has(input:focus, textarea:focus, select:focus) .fab-btn {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8) translateY(4px);
}

@media (hover: hover) {
  .card-hover:hover {
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
  }
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%,100%{ transform: translateX(0);} 25%{ transform: translateX(-4px);} 75%{ transform: translateX(4px);} }
@keyframes checkDraw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
@keyframes circleDraw { from { stroke-dashoffset: 166; } to { stroke-dashoffset: 0; } }
@keyframes popIn { 0% { transform: scale(0); opacity: 0; } 60% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
@keyframes shimmer { 0% { background-position: -200px 0; } 100% { background-position: calc(200px + 100%) 0; } }

.slide-up { animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1); }
.fade-in { animation: fadeIn 0.2s ease-out; }
.scale-in { animation: scaleIn 0.25s cubic-bezier(0.32, 0.72, 0, 1); }
.shake { animation: shake 0.3s ease-out; }
.pop-in { animation: popIn 0.4s cubic-bezier(0.32, 0.72, 0, 1); }

.check-circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: circleDraw 0.6s ease-in-out forwards;
  animation-delay: 0.1s;
}
.check-mark {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: checkDraw 0.4s ease-in-out forwards;
  animation-delay: 0.5s;
}
.skeleton {
  background: linear-gradient(90deg, #F0F0F0 25%, #E0E0E0 50%, #F0F0F0 75%);
  background-size: 200px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

@supports (padding: max(0px)) {
  body {
    padding-left: 0;
    padding-right: 0;
  }
}

/* Tab bar: flex item at the bottom of app-shell (NO position:fixed — avoids LIFF WebKit bug) */
.tabs-bar {
  flex-shrink: 0;
}

/* FAB: sits just above tab bar — 4px gap only */
.fab-btn {
  bottom: calc(var(--tabs-h) + max(var(--safe-bottom), 8px) + 4px);
}

/* ── Desktop layout ── */
@media (min-width: 681px) {
  html {
    display: flex;
    justify-content: center;
    background:
      radial-gradient(ellipse at 20% 35%, rgba(99,102,241,0.08) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 70%, rgba(16,185,129,0.06) 0%, transparent 50%),
      #d8dded;
  }

  body {
    width: var(--app-shell-max);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.07), 0 8px 64px rgba(0,0,0,0.18);
  }

  /* FAB: position relative to the centered shell, not viewport */
  .fab-btn {
    right: calc((100vw - var(--app-shell-max)) / 2 + 20px);
  }
}