* {
  box-sizing: border-box;
}

:root {
  --bg: #fffbf7;
  --surface: #ffffff;
  --surface-soft: #fafaf9;
  --red: #dc2626;
  --red-dark: #b91c1c;
  --red-soft: #fef2f2;
  --red-border: #fee2e2;
  --stone-900: #1c1917;
  --stone-800: #292524;
  --stone-700: #44403c;
  --stone-600: #57534e;
  --stone-500: #78716c;
  --stone-400: #a8a29e;
  --stone-300: #d6d3d1;
  --stone-200: #e7e5e4;
  --stone-100: #f5f5f4;
  --amber: #fcd34d;
  --shadow-sm: 0 2px 10px rgba(41, 37, 36, 0.04);
  --shadow-md: 0 14px 35px rgba(41, 37, 36, 0.08);
  --radius-xl: 24px;
  --radius-lg: 16px;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--stone-800);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(220, 38, 38, 0.28);
  outline-offset: 2px;
}

svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--red-border);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--red);
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--red);
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: -0.08em;
  box-shadow: 0 6px 14px rgba(220, 38, 38, 0.2);
}

.brand-name {
  font-size: clamp(1.25rem, 2.5vw, 1.55rem);
  font-weight: 900;
  letter-spacing: -0.04em;
}

.header-actions,
.user-profile,
.notification-item,
.report-prompt-user {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 16px;
}

.icon-button {
  position: relative;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--stone-600);
  background: transparent;
  transition: background 160ms ease, color 160ms ease;
}

.icon-button:hover {
  background: var(--stone-100);
  color: var(--stone-800);
}

.notification-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--red);
  border: 2px solid white;
}

.notification-area {
  position: relative;
}

.notification-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--stone-100);
  border-radius: 16px;
  background: white;
  box-shadow: var(--shadow-md);
  animation: slideDown 180ms ease both;
}

.notification-panel h2 {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: var(--stone-500);
}

.notification-item {
  align-items: flex-start;
  gap: 12px;
  padding-block: 8px;
}

.notification-status {
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 999px;
  background: var(--stone-300);
}

.notification-item.unread .notification-status {
  background: var(--red);
}

.notification-item h3 {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.notification-item p {
  margin: 3px 0 0;
  color: var(--stone-400);
  font-size: 0.75rem;
}

.user-profile {
  gap: 8px;
  padding-left: 16px;
  border-left: 1px solid var(--stone-200);
}

.avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #92400e;
  background: #fde68a;
  font-weight: 800;
  font-size: 0.86rem;
}

.avatar.large {
  width: 48px;
  height: 48px;
  font-size: 1rem;
}

.teacher-name {
  font-size: 0.88rem;
  font-weight: 700;
}

.workspace {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 64px);
  overflow: hidden;
}

.sidebar {
  width: 256px;
  flex: 0 0 256px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px 12px;
  background: var(--surface);
  border-right: 1px solid #fff1f2;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.02);
}

.primary-nav,
.secondary-nav {
  display: grid;
  gap: 8px;
}

.secondary-nav {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--stone-100);
}

.nav-item {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  color: var(--stone-500);
  background: transparent;
  font-weight: 700;
  text-align: left;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-item:hover {
  color: var(--stone-800);
  background: var(--stone-50, #fafaf9);
}

.nav-item.active {
  color: var(--red);
  background: var(--red-soft);
}

.nav-item span {
  white-space: nowrap;
  font-size: 0.9rem;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: clamp(16px, 3vw, 32px);
}

.tab-panel {
  animation: fadeIn 240ms ease both;
}

.content-container {
  width: 100%;
  margin: 0 auto;
}

.content-container.narrow { max-width: 768px; }
.content-container.medium { max-width: 896px; }
.content-container.wide { max-width: 1024px; }
.content-container.widest { max-width: 1180px; }

.ai-search-card {
  position: relative;
  overflow: hidden;
  margin-bottom: 32px;
  padding: clamp(24px, 5vw, 32px);
  border-radius: 30px;
  color: white;
  background: linear-gradient(135deg, #dc2626, #ef4444);
  box-shadow: 0 18px 44px rgba(220, 38, 38, 0.22);
}

.decorative-circle {
  position: absolute;
  top: -100px;
  right: -70px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.ai-search-content {
  position: relative;
  z-index: 1;
}

.ai-search-card h1,
.page-header h1,
.report-prompt h1,
.dashboard-header h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.65rem);
  letter-spacing: -0.02em;
}

.ai-search-card h1,
.section-heading-row h2,
.subsection-title,
.analytics-panel h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-search-card h1 svg {
  color: var(--amber);
}

.ai-search-card p {
  max-width: 780px;
  margin: 8px 0 24px;
  color: #fee2e2;
  line-height: 1.7;
  font-size: 0.93rem;
}

.ai-search-form {
  display: flex;
  gap: 8px;
}

.ai-search-form input {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  color: white;
  background: rgba(255, 255, 255, 0.1);
  transition: background 160ms ease;
}

.ai-search-form input::placeholder {
  color: #fecaca;
}

.ai-search-form input:focus {
  background: rgba(255, 255, 255, 0.2);
}

.ai-search-form button,
.primary-button {
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.ai-search-form button {
  padding: 12px 24px;
  color: var(--red);
  background: white;
  box-shadow: 0 6px 16px rgba(41, 37, 36, 0.08);
}

.ai-search-form button:hover,
.primary-button:hover,
.dashed-button:hover {
  transform: translateY(-1px);
}

.ai-search-form button:disabled {
  cursor: wait;
  opacity: 0.8;
}

.ai-response {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  line-height: 1.75;
  white-space: pre-line;
  font-size: 0.9rem;
  animation: slideDown 240ms ease both;
}

.ai-response .response-body {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.ai-response svg {
  margin-top: 4px;
  color: var(--amber);
}

.ai-response button {
  margin-top: 12px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  color: white;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.78rem;
  font-weight: 800;
}

.section-heading-row,
.page-header,
.report-prompt,
.dashboard-card > div,
.dashboard-card p {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-heading-row {
  gap: 16px;
  margin-bottom: 24px;
}

.section-heading-row h2,
.analytics-panel h2,
.subsection-title {
  margin: 0;
  font-size: 1.2rem;
}

.section-heading-row h2 svg,
.analytics-panel h2 svg,
.subsection-title svg {
  color: var(--red);
}

.filter-group {
  display: flex;
  gap: 8px;
}

select {
  min-height: 38px;
  padding: 6px 34px 6px 12px;
  border: 1px solid var(--stone-200);
  border-radius: 10px;
  color: var(--stone-600);
  background: white;
}

.materials-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

.material-card,
.report-card,
.dashboard-card,
.analytics-panel,
.report-prompt,
.upload-card {
  border: 1px solid var(--stone-100);
  background: white;
  box-shadow: var(--shadow-sm);
}

.material-card {
  overflow: hidden;
  border-radius: var(--radius-xl);
  transition: box-shadow 180ms ease, transform 180ms ease;
}

.material-card:hover,
.report-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.material-thumbnail {
  position: relative;
  height: 160px;
  display: grid;
  place-items: center;
  color: var(--stone-400);
  background: linear-gradient(135deg, #f5f5f4, #fef2f2);
}

.material-thumbnail svg {
  width: 48px;
  height: 48px;
  opacity: 0.22;
}

.recommend-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 7px;
  color: white;
  background: var(--red);
  font-size: 0.72rem;
  font-weight: 900;
  box-shadow: 0 6px 14px rgba(220, 38, 38, 0.18);
}

.recommend-badge svg {
  width: 12px;
  height: 12px;
  opacity: 1;
}

.material-body {
  padding: 20px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.tag {
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--stone-100);
  color: var(--stone-600);
  font-size: 0.75rem;
  font-weight: 800;
}

.tag.subject {
  background: var(--red-soft);
  color: var(--red);
}

.material-card h3 {
  min-height: 3.1em;
  margin: 0 0 12px;
  font-size: 1rem;
  line-height: 1.55;
}

.material-stats {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
  color: var(--stone-500);
  font-size: 0.78rem;
}

.material-stats span,
.material-actions button,
.primary-button,
.dashed-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.material-stats svg {
  width: 14px;
  height: 14px;
}

.material-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.material-actions button {
  min-height: 40px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 800;
  transition: background 160ms ease, transform 160ms ease;
}

.secondary-button {
  border: 1px solid var(--stone-200);
  color: var(--stone-700);
  background: white;
}

.secondary-button:hover {
  background: var(--stone-100);
}

.classroom-button {
  border: 0;
  color: white;
  background: #00897b;
}

.classroom-button:hover {
  background: #00796b;
}

.page-header {
  gap: 20px;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--stone-200);
}

.page-header p,
.report-prompt p {
  margin: 6px 0 0;
  color: var(--stone-500);
}

.primary-button {
  min-height: 42px;
  padding: 10px 18px;
  color: white;
  background: var(--red);
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.16);
}

.primary-button:hover {
  background: var(--red-dark);
}

.upload-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
  padding: clamp(30px, 6vw, 42px);
  border-color: var(--red-border);
  border-radius: var(--radius-xl);
  text-align: center;
}

.feature-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 999px;
  color: var(--red);
  background: var(--red-soft);
}

.feature-icon svg {
  width: 32px;
  height: 32px;
}

.upload-card h2 {
  margin: 0 0 10px;
  font-size: 1.15rem;
}

.upload-card p {
  max-width: 520px;
  margin: 0 0 24px;
  color: var(--stone-500);
  line-height: 1.75;
  font-size: 0.9rem;
}

.dashed-button {
  padding: 16px 28px;
  border: 2px dashed #fecaca;
  border-radius: 14px;
  color: var(--red);
  background: rgba(254, 242, 242, 0.55);
  font-weight: 800;
  transition: background 160ms ease, transform 160ms ease;
}

.dashed-button:hover {
  background: var(--red-soft);
}

.upload-card small {
  margin-top: 12px;
  color: var(--stone-400);
}

.subsection-title {
  margin-bottom: 16px;
}

.subsection-title svg {
  color: var(--stone-500);
}

.empty-state {
  padding: 38px;
  border: 1px dashed var(--stone-200);
  border-radius: var(--radius-xl);
  text-align: center;
  background: var(--surface-soft);
}

.empty-state svg {
  width: 42px;
  height: 42px;
  color: var(--stone-300);
}

.empty-state p {
  margin: 10px 0 0;
  color: var(--stone-500);
}

.report-prompt {
  gap: 20px;
  margin-bottom: 24px;
  padding: 24px;
  border-radius: var(--radius-xl);
}

.report-prompt-user {
  gap: 16px;
}

.report-prompt h1 {
  font-size: 1rem;
}

.report-prompt p {
  font-size: 0.88rem;
}

.reports-list {
  display: grid;
  gap: 16px;
}

.report-card {
  padding: 24px;
  border-radius: var(--radius-xl);
  transition: box-shadow 180ms ease, transform 180ms ease;
}

.report-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.report-author {
  display: flex;
  align-items: center;
  gap: 12px;
}

.report-author-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--stone-600);
  background: var(--stone-100);
  font-weight: 800;
}

.report-author strong {
  display: block;
  font-size: 0.88rem;
}

.report-author small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--stone-500);
}

.report-author small svg {
  width: 12px;
  height: 12px;
}

.report-card > p {
  margin: 0 0 18px;
  color: var(--stone-700);
  line-height: 1.75;
  font-size: 0.9rem;
}

.report-actions {
  display: flex;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--stone-100);
}

.report-actions button,
.chevron-button {
  border: 0;
  color: var(--stone-500);
  background: transparent;
  font-size: 0.86rem;
  transition: color 160ms ease;
}

.report-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.report-actions button:hover {
  color: var(--red);
}

.chevron-button:hover {
  color: var(--stone-800);
}

.dashboard-header select {
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.dashboard-card {
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px;
  border-radius: var(--radius-xl);
}

.dashboard-card h2 {
  margin: 0;
  color: var(--stone-500);
  font-size: 0.86rem;
  font-weight: 700;
}

.dashboard-card p {
  margin: 20px 0 0;
}

.dashboard-card strong {
  font-size: 2rem;
  line-height: 1;
}

.dashboard-card span {
  color: #16a34a;
  font-size: 0.88rem;
  font-weight: 800;
}

.metric-blue { color: #3b82f6; }
.metric-green { color: #22c55e; }
.metric-amber { color: #f59e0b; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.analytics-panel {
  padding: 24px;
  border-radius: var(--radius-xl);
}

.analytics-panel h2 {
  margin-bottom: 26px;
  font-size: 1rem;
}

.graph-list {
  display: grid;
  gap: 18px;
}

.graph-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
  color: var(--stone-600);
  font-size: 0.8rem;
}

.graph-bar span {
  font-weight: 800;
}

.graph-bar strong {
  color: var(--stone-500);
}

.graph-bar i {
  grid-column: 1 / -1;
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--stone-100);
}

.graph-bar i::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar-width);
  border-radius: inherit;
  background: var(--bar-color);
}

.ranking-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-soft);
}

.ranking-list span {
  width: 18px;
  color: var(--stone-400);
  font-weight: 900;
}

.ranking-list div {
  flex: 1;
}

.ranking-list strong,
.ranking-list small {
  display: block;
}

.ranking-list strong {
  font-size: 0.9rem;
}

.ranking-list small {
  color: var(--stone-500);
  margin-top: 2px;
}

.ranking-list b {
  color: var(--stone-600);
  font-size: 0.86rem;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 40px));
  padding: 14px 16px;
  border-radius: 14px;
  color: white;
  background: rgba(41, 37, 36, 0.94);
  box-shadow: var(--shadow-md);
  animation: toastIn 180ms ease both;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1024px) {
  .sidebar {
    width: 80px;
    flex-basis: 80px;
    padding-inline: 12px;
  }

  .nav-item {
    justify-content: center;
    padding-inline: 12px;
  }

  .nav-item span {
    display: none;
  }

  .materials-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-header {
    padding: 0 14px;
  }

  .brand-name,
  .teacher-name {
    display: none;
  }

  .workspace {
    display: block;
    overflow: visible;
  }

  .sidebar {
    position: sticky;
    top: 64px;
    z-index: 15;
    width: 100%;
    flex-basis: auto;
    flex-direction: row;
    gap: 6px;
    padding: 8px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--red-border);
  }

  .primary-nav,
  .secondary-nav {
    display: flex;
    gap: 6px;
  }

  .secondary-nav {
    margin-top: 0;
    padding-top: 0;
    padding-left: 6px;
    border-top: 0;
    border-left: 1px solid var(--stone-100);
  }

  .nav-item {
    min-width: 48px;
  }

  .main-content {
    overflow: visible;
    padding: 18px 14px 28px;
  }

  .ai-search-form,
  .section-heading-row,
  .page-header,
  .report-prompt,
  .dashboard-header {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-group {
    flex-direction: column;
  }

  .materials-grid,
  .dashboard-cards,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .material-card h3 {
    min-height: auto;
  }

  .report-prompt-user {
    align-items: flex-start;
  }

  .dashboard-card p {
    align-items: flex-end;
  }
}

@media (max-width: 420px) {
  .material-actions {
    grid-template-columns: 1fr;
  }

  .dashed-button,
  .primary-button,
  .ai-search-form button {
    width: 100%;
  }

  .ranking-list li {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}
