:root {
  color-scheme: light;
  --teal: #0c9b95;
  --teal-dark: #08736f;
  --yellow: #ffd84d;
  --blue: #3b82f6;
  --coral: #ff7a59;
  --purple: #8b5cf6;
  --green: #22c55e;
  --ink: #172b33;
  --muted: #63777c;
  --line: #dce8e7;
  --soft: #eef8f7;
  --paper: #ffffff;
  --shadow: 0 18px 48px rgba(17, 43, 51, 0.1);
  font-family: "UD Digi Kyokasho N-R", "Yu Gothic", "Hiragino Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #f8fcfc 0%, #f2f8f7 100%);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.shell {
  min-height: 100vh;
}

.state {
  width: min(860px, calc(100% - 32px));
  margin: 42px auto;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.state-loading {
  display: flex;
  align-items: center;
  gap: 16px;
}

.state-locked {
  border-top: 8px solid var(--coral);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 4px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

@keyframes sheen {
  from { transform: translateX(-120%); }
  to { transform: translateX(160%); }
}

.portal {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
}

.brand {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 4px 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  line-height: 1.25;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff;
  box-shadow: 0 10px 22px rgba(12, 155, 149, 0.25);
}

.side-nav {
  display: grid;
  gap: 6px;
  margin-top: 24px;
}

.nav-button {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 900;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-button:hover,
.nav-button.active {
  background: var(--soft);
  color: var(--teal-dark);
}

.nav-button.active {
  box-shadow: inset 4px 0 0 var(--teal);
}

.main-stage {
  min-width: 0;
}

.search-top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(280px, 720px) auto;
  justify-content: center;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 252, 252, 0.9);
  backdrop-filter: blur(14px);
}

.search-box {
  display: grid;
  grid-template-columns: 1fr auto;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(23, 59, 67, 0.07);
  overflow: hidden;
}

.search-box input {
  min-width: 0;
  border: 0;
  padding: 0 18px;
  background: transparent;
  color: var(--ink);
  outline: none;
}

.search-box:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(12, 155, 149, 0.13);
}

.search-box button {
  width: 86px;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--soft);
  color: var(--teal-dark);
  font-weight: 900;
  cursor: pointer;
}

.account-badge {
  min-width: 120px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--yellow);
  color: var(--ink);
  text-align: center;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(255, 216, 77, 0.28);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.settings-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(23, 59, 67, 0.08);
}

.settings-icon:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.empty-stage {
  min-height: 0;
}

.content-stage {
  width: min(1160px, calc(100% - 48px));
  margin: 12px auto 48px;
  display: grid;
  gap: 18px;
  animation: riseIn 0.32s ease both;
}

.view-panel,
.preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.view-panel {
  padding: 18px;
}

.panel-head,
.preview-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.panel-head {
  margin-bottom: 16px;
}

.preview-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 16px;
}

.section-title {
  margin: 18px 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.compact-list,
.recommend-list,
.today-list,
.pack-list,
.print-list {
  display: grid;
  gap: 10px;
}

.pack-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.print-list {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.history-item,
.recommend-item,
.today-card,
.pack-button,
.print-card {
  width: 100%;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.print-card {
  --grade-color: var(--teal);
  --grade-bg: #ffffff;
  border-left: 6px solid var(--grade-color);
  background: linear-gradient(90deg, var(--grade-bg) 0, #ffffff 46%);
}

.print-card.grade-preschool { --grade-color: #ff7a59; --grade-bg: #fff2ed; }
.print-card.grade-g1 { --grade-color: #0c9b95; --grade-bg: #e7f8f6; }
.print-card.grade-g2 { --grade-color: #f5b700; --grade-bg: #fff8d9; }
.print-card.grade-g3 { --grade-color: #3b82f6; --grade-bg: #eaf2ff; }
.print-card.grade-g4 { --grade-color: #20a66a; --grade-bg: #eaf8ef; }
.print-card.grade-g5 { --grade-color: #8b5cf6; --grade-bg: #f2ecff; }
.print-card.grade-g6 { --grade-color: #ef476f; --grade-bg: #fff0f4; }
.print-card.grade-j1 { --grade-color: #0f766e; --grade-bg: #e3fbf6; }
.print-card.grade-j2 { --grade-color: #7c3aed; --grade-bg: #f3edff; }
.print-card.grade-j3 { --grade-color: #dc2626; --grade-bg: #fff0f0; }

.history-item:hover,
.recommend-item:hover,
.today-card:hover,
.pack-button:hover,
.print-card:hover {
  transform: translateY(-2px);
  border-color: rgba(12, 155, 149, 0.42);
  box-shadow: 0 14px 28px rgba(23, 59, 67, 0.1);
}

.history-item:nth-child(6n + 1) { border-left: 5px solid var(--teal); }
.history-item:nth-child(6n + 2) { border-left: 5px solid var(--yellow); }
.history-item:nth-child(6n + 3) { border-left: 5px solid var(--blue); }
.history-item:nth-child(6n + 4) { border-left: 5px solid var(--coral); }
.history-item:nth-child(6n + 5) { border-left: 5px solid var(--purple); }
.history-item:nth-child(6n) { border-left: 5px solid var(--green); }

.print-card[aria-selected="true"] {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(12, 155, 149, 0.14);
}

.card-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.print-card h3 {
  font-size: 15px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
}

.chip.accent {
  background: #fff4bf;
  color: #7a5b00;
}

.history-title,
.recommend-title {
  display: block;
  font-size: 14px;
  font-weight: 900;
}

.history-meta,
.recommend-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.today-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.today-number {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 900;
}

.today-card:nth-child(2) .today-number { background: var(--blue); color: #fff; }
.today-card:nth-child(3) .today-number { background: var(--coral); color: #fff; }
.today-card:nth-child(4) .today-number { background: var(--green); color: #fff; }

.today-card small,
.pack-button small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pack-button {
  display: grid;
  gap: 4px;
}

.pack-button:nth-child(3n + 1) { background: linear-gradient(90deg, rgba(12, 155, 149, 0.1), #fff 42%); }
.pack-button:nth-child(3n + 2) { background: linear-gradient(90deg, rgba(139, 92, 246, 0.1), #fff 42%); }
.pack-button:nth-child(3n) { background: linear-gradient(90deg, rgba(255, 216, 77, 0.2), #fff 42%); }

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(23, 43, 51, 0.28);
  backdrop-filter: blur(4px);
}

.settings-modal {
  position: fixed;
  z-index: 1001;
  top: 86px;
  right: 28px;
  width: min(720px, calc(100vw - 40px));
  max-height: calc(100vh - 112px);
  overflow: auto;
}

.settings-block {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.settings-block h3 {
  margin-bottom: 12px;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

select,
.settings-block input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select:focus,
.settings-block input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(12, 155, 149, 0.13);
}

.filter-row {
  margin-bottom: 12px;
}

.result-count,
.history-empty,
.recommend-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.segmented,
.quick-times,
.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.segment,
.time-chip,
.status-button,
.ghost-button,
.web-button,
.answer-button,
.download-button,
.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  cursor: pointer;
}

.segment.active,
.time-chip.active,
.status-button.active,
.ghost-button {
  background: var(--soft);
  color: var(--teal-dark);
}

.download-button,
.web-button,
.answer-button,
.primary-link {
  position: relative;
  overflow: hidden;
  min-height: 42px;
  border: 0;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 12px 24px rgba(12, 155, 149, 0.22);
}

.answer-button {
  background: var(--yellow);
  color: #173b43;
  box-shadow: 0 12px 24px rgba(245, 183, 0, 0.2);
}

.web-button {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 12px 24px rgba(59, 130, 246, 0.2);
}

.download-button::after,
.web-button::after,
.answer-button::after,
.primary-link::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 35%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  animation: sheen 3.4s ease-in-out infinite;
}

.wide-action {
  width: 100%;
  margin-top: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.report-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.report-grid strong {
  display: block;
  color: var(--teal-dark);
  font-size: 20px;
}

.report-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.calendar-dots {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 10px;
}

.calendar-dot {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 999px;
  background: #eef4f4;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.calendar-dot.active {
  background: linear-gradient(135deg, var(--teal), var(--green));
  color: #fff;
}

.mini-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.mini-metrics span {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--soft);
}

.mini-metrics strong {
  margin-right: 4px;
  color: var(--teal-dark);
}

.preview {
  display: grid;
  grid-template-rows: auto auto minmax(520px, 70vh);
}

.preview-modal {
  position: fixed;
  z-index: 1002;
  top: 28px;
  left: 50%;
  right: auto;
  bottom: 28px;
  width: min(1280px, calc(100vw - 56px));
  transform: translateX(-50%);
  max-height: calc(100vh - 56px);
  background: #fff;
  grid-template-rows: auto auto minmax(420px, 1fr);
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #7a5b00;
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
}

.progress-panel {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.1), #fff 34%);
}

.progress-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.5fr) 1fr;
  gap: 10px;
  margin-top: 10px;
}

.progress-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.progress-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.progress-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}

iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #eef6f5;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  .portal {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .brand {
    grid-template-columns: 1fr;
  }

  .brand span:last-child,
  .nav-button {
    font-size: 12px;
  }

  .nav-button {
    padding: 0 6px;
    text-align: center;
  }

  .search-top {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .account-badge {
    justify-self: end;
  }

  .settings-grid,
  .pack-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .portal {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    z-index: 6;
    height: auto;
    top: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    grid-template-columns: repeat(3, 1fr);
    margin-top: 0;
  }

  .search-top {
    top: 81px;
    padding: 10px 12px;
  }

  .content-stage {
    width: calc(100% - 24px);
    margin-top: 16px;
  }

  .panel-head,
  .preview-head,
  .progress-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .preview-modal {
    top: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }
}
