/* Shared five-tab navigation; compact screens use the same controls at the bottom. */
:root { --compact-gutter: 24px; --nav-height: 68px; }
body { background: #f4f5f6; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 2px solid #297356; outline-offset: 3px; }
.ui-icon { width: 22px; height: 22px; flex: 0 0 22px; display: inline-block; vertical-align: middle; }
.app-shell { grid-template-columns: 208px minmax(0,1fr); background: #fff; max-width: 1600px; }
.sidebar { position: sticky; top: 0; height: 100dvh; grid-row: auto; background: #f7f8fa; gap: 36px; }
.sidebar .nav-group { gap: 12px; }
.sidebar .nav-item { border-radius: 8px; font-size: 15px; }
.nav-item.active .ui-icon { stroke-width: 2.4; }
.main { padding: 32px 40px 64px; }
.topbar { gap: 16px; margin-bottom: 32px; flex-wrap: nowrap; }
.topbar-title { flex: 1; }
.topbar-title h1:focus { outline: none; }
.topbar-actions { flex: 0 1 auto; flex-wrap: nowrap; }
.topbar-actions .search { width: 200px; }
.icon-btn { display: inline-flex; justify-content: center; align-items: center; min-width: 44px; min-height: 44px; border-radius: 6px; }
.page-back { flex-shrink: 0; }
.compact-search, .chat-back { display: none; }
.primary-btn, .secondary-btn { min-height: 44px; border-radius: 6px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.page-heading > .heading-actions { flex: 0 1 auto; }
.page-panel { animation: none; }
.module-card { border-radius: 0; }
.study-shortcuts { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; margin: 0 0 32px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.study-shortcuts > button { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 8px 0; min-height: 52px; background: transparent; color: var(--ink); text-align: left; font-size: 14px; }
.study-shortcuts > button > span:nth-child(2) { flex: 1; }
.study-shortcuts > button > .ui-icon { width: 16px; flex-basis: 16px; color: #a1aaa7; }
.shortcut-icon { width: 36px; height: 36px; flex: 0 0 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
.shortcut-icon.blue { color: #3176a3; background: #eaf3fb; }
.shortcut-icon.teal { color: #28755a; background: #eaf5ee; }
.shortcut-icon.coral { color: #bf616b; background: #fceff1; }
.shortcut-icon.gold { color: #9b7b28; background: #faf4e4; }
.shortcut-icon.neutral { color: #697383; background: #eff1f5; }
.my-page { max-width: 920px; }
.my-identity { width: 100%; display: flex; align-items: center; gap: 22px; padding: 24px 0 40px; background: transparent; text-align: left; color: var(--ink); }
.my-avatar { width: 72px; height: 72px; border-radius: 8px; flex: 0 0 72px; display: grid; place-items: center; overflow: hidden; color: #6d8296; background: #edf1f5; }
.my-avatar > .ui-icon { width: 32px; height: 32px; }
.my-avatar img { width: 100%; height: 100%; object-fit: cover; }
.my-identity-copy { flex: 1; min-width: 0; display: grid; gap: 8px; }
.my-identity-copy strong { font-size: 23px; line-height: 1.4; overflow-wrap: anywhere; }
.my-identity-copy span, .my-identity-copy small { font-size: 13px; color: #77818b; line-height: 1.6; overflow-wrap: anywhere; }
.my-identity > .ui-icon, .my-row > .ui-icon { color: #a6adb4; width: 18px; flex-basis: 18px; }
.my-section { margin: 0 0 28px; border-top: 1px solid var(--line); }
.my-row { display: flex; width: 100%; min-height: 76px; align-items: center; gap: 16px; padding: 16px 0; border-bottom: 1px solid #eff1f3; background: transparent; color: var(--ink); text-decoration: none; text-align: left; }
.my-row:hover, .my-identity:hover { background: #fafbfc; }
.my-row-label { flex: 1; min-width: 0; font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }
.my-row-value { max-width: 38%; font-size: 13px; line-height: 1.6; color: #7b8490; text-align: right; overflow-wrap: anywhere; }
#my-points[data-loaded="true"] { color: #3176a3; font-weight: 600; }
.my-circles { padding: 0 0 0 52px; }
.my-circles .empty-state { margin: 0; padding: 0 0 16px; text-align: left; font-size: 12px; }
.my-circles .circle-card { margin: 0; padding: 0 0 16px; border: 0; background: transparent; border-radius: 0; }
.my-circles .circle-cover { display: none; }
.my-circles .circle-info strong { font-size: 13px; color: #65796c; white-space: normal; }
.my-circles .circle-info span { display: none; }
.my-logout { width: 100%; padding: 16px; min-height: 52px; color: #a54c51; background: #f7f8fa; border-radius: 6px; }
body[data-page="my"] .topbar-actions [data-page-jump="my"] { display: none; }
.chat-layout { border-radius: 8px; grid-template-columns: 200px minmax(0,1fr); }
.chat-contact { min-height: 68px; gap: 12px; }
.chat-contact > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.chat-contact strong { font-size: 14px; color: var(--ink); }
.chat-contact .avatar { display: grid; place-items: center; color: #fff; border-radius: 8px; width: 38px; height: 38px; }
.chat-window { min-height: 430px; max-height: 680px; }
.messages { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.messages > :first-child { margin-top: auto; }
.message { flex: 0 0 auto; }
.chat-compose input { min-height: 44px; font-size: 16px; }
.chat-compose button { min-width: 60px; }
.chat-header strong { overflow-wrap: anywhere; min-width: 0; }
.life-tabs { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); overflow: visible; gap: 8px; }
.life-tab { min-width: 0; min-height: 44px; padding: 10px 4px; text-align: center; }
.topic-list { flex-wrap: wrap; }
.topic-chip { min-height: 40px; }
.modal-backdrop { z-index: 1000; }
.modal-head { position:sticky; top:-1px; z-index:5; background:#fff; padding-bottom:12px; }
.modal-close { min-width:44px; min-height:44px; touch-action:manipulation; }
.modal-card { max-height: calc(var(--visible-height, 100dvh) - 32px); overscroll-behavior: contain; }
body:has(.modal-backdrop.open) { overflow: hidden; }
.toast { z-index: 2000; max-width: calc(100vw - 32px); white-space: normal; overflow-wrap: anywhere; }

@media (max-width:1180px), (max-width:1440px) and (hover:none) and (pointer:coarse) {
  html { scroll-padding-top: 88px; scroll-padding-bottom: 92px; }
  .app-shell { display: block; min-height: 100dvh; }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: 100%; height: auto; z-index: 40; display: block; padding: 0 16px env(safe-area-inset-bottom); background: #fafbfd; border: 0; border-top: 1px solid #e3e7eb; }
  .sidebar .brand, .sidebar-bottom { display: none; }
  .sidebar .nav-group { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 0; overflow: visible; max-width: 720px; margin: auto; }
  .sidebar .nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-width: 0; height: var(--nav-height); min-height: var(--nav-height); padding: 8px 2px; gap: 5px; border-radius: 0; font-size: 12px; color: #737e88; background: transparent; }
  .sidebar .nav-item.active { color: #25805b; }
  .sidebar .nav-item .ui-icon { width: 24px; height: 24px; flex-basis: 24px; }
  .main { padding: 0 var(--compact-gutter) calc(var(--nav-height) + 32px + env(safe-area-inset-bottom)); }
  .topbar { position: sticky; top: 0; z-index: 20; min-height: 72px; padding: calc(12px + env(safe-area-inset-top)) var(--compact-gutter) 12px; margin: 0 calc(-1 * var(--compact-gutter)) 28px; gap: 8px; background: #f6f7f9; border-bottom: 1px solid #e9ecef; align-items: center; }
  .topbar-title h1 { font-size: 20px; line-height: 1.4; }
  .topbar-title p, .topbar-actions .search, #header-account { display: none; }
  .topbar-actions { gap: 4px; flex: 0 0 auto; }
  .compact-search { display: inline-flex; }
  .topbar .icon-btn { background: transparent; color: #4a5763; }
  .page-heading { padding-bottom: 24px; gap: 16px; align-items: center; }
  .page-heading h2 { display: none; }
  .page-heading > div { flex: 1 1 160px; }
  .page-heading p { margin: 0; font-size: 13px; color: #79838b; line-height: 1.8; }
  .page-heading > .heading-actions { flex: 0 1 auto; }
  .feed-layout, .connect-layout, .study-layout, .play-layout, .life-layout { grid-template-columns: minmax(0,1fr); gap: 32px; }
  .connect-layout > aside, .study-layout > aside, .play-layout > aside { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 28px; }
  .study-shortcuts { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 20px; }
  .study-shortcuts > button { flex-direction: column; text-align: center; gap: 10px; }
  .study-shortcuts > button > .ui-icon { display: none; }
  .study-shortcuts > button > span:nth-child(2) { flex: none; }
  .pomodoro { grid-template-columns: 160px minmax(0,1fr); padding: 28px; text-align: left; gap: 28px; }
  .timer-controls { justify-content: flex-start; flex-wrap: wrap; }
  .study-stats { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 20px; }
  .study-stat { display: block; padding: 20px 4px; text-align: center; background: transparent; border: 0; border-right: 1px solid var(--line); border-radius: 0; }
  .study-stat:last-child { border-right: 0; }
  .study-stat span { display: block; margin: 10px 0 0; }
  .my-page { max-width: 880px; margin: 0 auto; }
  body[data-page="my"] .app-shell { background: #f3f4f6; }
  body[data-page="my"] .topbar { margin-bottom: 0; border-bottom: 0; }
  .my-identity { background: #fff; padding: 32px 24px; }
  .my-section { background: #fff; border: 0; margin: 12px 0 0; padding: 0 24px; }
  .my-row:last-child { border-bottom: 0; }
  .my-logout { margin-top: 20px; background: #fff; border-radius: 0; }
  .book-list, .game-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 24px; }
  .library-tools { grid-template-columns: minmax(0,1fr) 180px; }
  .ratio-filters, .intention-controls { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 28px; }
  .admission-options { scroll-padding-bottom: 20px; }
  .modal-card { width: min(760px,calc(100vw - 32px)); }
  .toast { bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom)); }
  .page-heading, .game-card, button { scroll-margin-top: 88px; scroll-margin-bottom: 88px; }
  .keyboard-open .sidebar { visibility: hidden; }
}

@media (max-width:600px) {
  :root { --compact-gutter: max(20px,env(safe-area-inset-left),env(safe-area-inset-right)); --nav-height: 64px; }
  .sidebar { padding-left: max(8px,env(safe-area-inset-left)); padding-right: max(8px,env(safe-area-inset-right)); }
  .topbar { min-height: 64px; margin-bottom: 24px; padding-top: calc(10px + env(safe-area-inset-top)); padding-bottom: 10px; }
  .topbar-title h1 { font-size: 18px; }
  .topbar-actions .icon-btn { min-width: 40px; width: 40px; }
  .page-heading { align-items: flex-start; gap: 14px; padding-bottom: 24px; }
  .page-heading > div { flex-basis: 140px; }
  [data-panel="admissions"] .page-heading > div, [data-panel="resources"] .page-heading > div,
  .points-page .page-heading > div { flex-basis: 100%; }
  .page-heading > button { min-height: 44px; }
  .page-heading > .heading-actions { flex-basis: auto; gap: 12px; }
  .study-shortcuts { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px 20px; margin-bottom: 24px; padding-bottom: 24px; }
  .study-shortcuts > button { flex-direction: row; gap: 10px; text-align: left; font-size: 14px; }
  .shortcut-icon { width: 34px; height: 34px; flex-basis: 34px; }
  .my-page { margin-inline: calc(-1 * var(--compact-gutter)); }
  .my-identity { padding: 24px var(--compact-gutter) 28px; gap: 16px; }
  .my-avatar { width: 62px; height: 62px; flex-basis: 62px; }
  .my-identity-copy { gap: 6px; }
  .my-identity-copy strong { font-size: 21px; }
  .my-identity-copy small { font-size: 12px; }
  .my-section { padding-inline: var(--compact-gutter); }
  .my-row { min-height: 66px; padding: 15px 0; gap: 12px; }
  .my-row-label { font-size: 15px; }
  .my-row-value { font-size: 12px; }
  .my-circles { padding-left: 46px; }
  .chat-layout { grid-template-columns: minmax(0,1fr); min-height: 0; border: 0; overflow: visible; }
  .chat-list { border: 0; background: #fff; }
  .chat-list-head { padding: 0 0 16px; color: #7a858f; font-size: 13px; }
  #friend-list { display: block; overflow: visible; }
  #friend-list > .empty-state { min-height: 150px; display: grid; place-items: center; }
  .chat-contact { flex: none; min-height: 76px; padding: 16px 0; border-bottom: 1px solid var(--line); }
  .chat-contact .avatar { width: 44px; height: 44px; }
  .chat-window { display: none; max-height: none; }
  .chat-layout.conversation-open .chat-list { display: none; }
  .chat-layout.conversation-open .chat-window { display: flex; min-height: 320px; height: calc(var(--visible-height,100dvh) - 172px - env(safe-area-inset-bottom)); }
  body[data-page="connect"]:has(.conversation-open) .page-panel.active > .page-heading,
  body[data-page="connect"]:has(.conversation-open) .connect-layout > aside { display: none; }
  .chat-header { padding: 0 0 12px; gap: 8px; }
  .chat-back { display: inline-flex; }
  .messages { padding: 20px 12px; background: #f3f5f6; }
  .message { max-width: 88%; }
  .bubble { font-size: 14px; border-radius: 6px; }
  .chat-compose { padding: 12px 0 0; }
  .connect-layout > aside, .study-layout > aside, .play-layout > aside { grid-template-columns: minmax(0,1fr); gap: 28px; }
  .connect-layout > aside .bottle-card { padding: 20px 0; text-align: left; }
  .bottle-icon { display: none; }
  .bottle-card p { max-width: none; }
  .pomodoro { grid-template-columns: minmax(0,1fr); justify-items: center; padding: 24px 16px; text-align: center; gap: 22px; border-radius: 8px; }
  .timer-ring { width: 144px; height: 144px; }
  .timer-ring strong { font-size: 32px; }
  .pomodoro-copy { min-width: 0; width: 100%; }
  .pomodoro-copy h3 { font-size: 18px; }
  .pomodoro-copy p { font-size: 13px; }
  .timer-controls { justify-content: center; gap: 10px; }
  .timer-controls > button { padding-inline: 14px; }
  .study-stats { gap: 8px; }
  .study-stat { text-align: center; padding: 16px 0; min-width: 0; }
  .study-stat strong { font-size: 18px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
  .study-stat span { font-size: 11px; line-height: 1.7; }
  .section-head { margin: 28px 0 18px; }
  .rail-title { gap: 16px; }
  .library-tools { grid-template-columns: minmax(0,1fr); gap: 16px; }
  .book-list { grid-template-columns: minmax(0,1fr); gap: 20px; }
  .book-card { padding: 20px 16px; gap: 16px; min-height: 160px; }
  .game-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
  .game-card { padding: 18px 14px; min-height: 230px; }
  .game-card h3 { font-size: 16px; line-height: 1.5; }
  .game-card p { font-size: 12px; line-height: 1.8; }
  .game-card button { font-size: 12px; min-height: 44px; padding: 8px 0; }
  .game-visual { font-size: 25px; width: 42px; height: 42px; }
  .life-tabs { gap: 8px; padding-bottom: 12px; }
  .topic-list { gap: 12px; }
  .topic-chip { padding: 10px 14px; }
  .ratio-filters, .intention-controls { grid-template-columns: minmax(0,1fr); gap: 24px; }
  .admission-section h3 { font-size: 17px; }
  .admission-summary, .intention-trend { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 20px; }
  .admission-coverage { grid-template-columns: minmax(0,1fr); }
  .modal-backdrop { align-items: center; padding: max(12px,env(safe-area-inset-top)) 12px max(12px,env(safe-area-inset-bottom)); }
  .modal-card, .modal-card:has(.board-grid) { width: 100%; padding: 24px 18px; max-height: calc(var(--visible-height,100dvh) - 32px); border-radius: 8px; }
  .modal-head { gap: 12px; margin-bottom: 24px; }
  .modal-head h3 { font-size: 21px; line-height: 1.5; overflow-wrap: anywhere; }
  .modal-form, .modal-row, .verification-fields { gap: 20px; }
  .modal-row, .verification-fields { grid-template-columns: minmax(0,1fr); }
  .modal-input, .modal-textarea, .library-search, .library-select { font-size: 16px; }
  .modal-label input[type="file"] { width: 100%; min-width: 0; font-size: 13px; }
  .board-wrap { grid-template-columns: minmax(0,1fr); }
  .game-side { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .difficulty-options { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .hero { border-radius: 0; }
  .hero-copy { padding: 24px 20px; }
  .hero h2 { font-size: 27px; line-height: 1.4; }
}

@media (prefers-reduced-motion:reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0s !important; animation-duration: 0s !important; }
}
