:root {
  --bg: #f7f7f2;
  --panel: #ffffff;
  --panel-soft: #fbfcfd;
  --panel-warm: #fffaf0;
  --panel-tint: #e0f2f1;
  --control-bg: rgba(255, 255, 255, 0.72);
  --stat-bg: #fbfcfd;
  --skill-bg: #f4f8fb;
  --tag-bg: #eef8f7;
  --text: #1f2933;
  --muted: #5e6b78;
  --line: #dde3ea;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #f59e0b;
  --on-primary: #ffffff;
  --hover-line: #c7d2da;
  --strong-hover-line: #b7c6d4;
  --featured-bg: #fffaf0;
  --featured-line: #f3d28a;
  --profile-mark-bg: #e0f2f1;
  --user-message-bg: #e0f2f1;
  --user-message-line: #b7d9d5;
  --error-text: #8a2f2f;
  --error-bg: #fff1f1;
  --error-line: #f2c5c5;
  --thinking-text: #7a4b00;
  --thinking-bg: #fffaf0;
  --thinking-line: #f3d28a;
  --focus-ring: rgba(15, 118, 110, 0.16);
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.08);
}

html {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --panel: #182231;
  --panel-soft: #141e2b;
  --panel-warm: #2a2115;
  --panel-tint: #13312f;
  --control-bg: rgba(24, 34, 49, 0.78);
  --stat-bg: #141e2b;
  --skill-bg: #1d2a3a;
  --tag-bg: #123a37;
  --text: #edf2f7;
  --muted: #a9b5c2;
  --line: #2c3a4d;
  --primary: #2dd4bf;
  --primary-dark: #5eead4;
  --accent: #fbbf24;
  --on-primary: #082f2b;
  --hover-line: #42526a;
  --strong-hover-line: #53657d;
  --featured-bg: #241f17;
  --featured-line: #5f4520;
  --profile-mark-bg: #123a37;
  --user-message-bg: #123a37;
  --user-message-line: #25635d;
  --error-text: #fecaca;
  --error-bg: #3a1b1f;
  --error-line: #7f2b35;
  --thinking-text: #fde68a;
  --thinking-bg: #302411;
  --thinking-line: #7a551b;
  --focus-ring: rgba(45, 212, 191, 0.2);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  transition: background-color 180ms ease, color 180ms ease;
}

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

.site {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
}

.brand {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  color: var(--muted);
  font-size: 15px;
}

.nav-links a:hover {
  color: var(--primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 18px;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  box-shadow: 0 8px 20px rgba(31, 41, 51, 0.04);
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--text);
  box-shadow: 0 8px 20px rgba(31, 41, 51, 0.04);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background-color 180ms ease, color 180ms ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--hover-line);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.theme-icon {
  grid-area: 1 / 1;
  font-size: 18px;
  line-height: 1;
  transition: opacity 160ms ease, transform 160ms ease;
}

.theme-icon-moon,
html[data-theme="dark"] .theme-icon-sun {
  opacity: 0;
  transform: scale(0.7) rotate(-45deg);
}

html[data-theme="dark"] .theme-icon-moon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.lang-button {
  min-height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.lang-button.active {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.18);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 32px;
  align-items: stretch;
  padding: 56px 0 44px;
}

.hero-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 420px;
}

.eyebrow {
  color: var(--primary);
  font-weight: 800;
  margin: 0 0 14px;
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(44px, 8vw, 82px);
  line-height: 1;
  letter-spacing: 0;
}

.intro {
  max-width: 680px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 19px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 750;
  box-shadow: 0 8px 22px rgba(31, 41, 51, 0.05);
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background-color 180ms ease, color 180ms ease;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.profile-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 420px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.profile-mark {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border-radius: 8px;
  background: var(--profile-mark-bg);
  color: var(--primary-dark);
  font-size: 30px;
  font-weight: 900;
}

.profile-card h2 {
  margin: 24px 0 10px;
  font-size: 26px;
  line-height: 1.2;
}

.profile-card p {
  margin: 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 26px;
}

.stat {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--stat-bg);
  transition: background-color 180ms ease, border-color 180ms ease;
}

.stat strong {
  display: block;
  font-size: 22px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

section {
  padding: 36px 0;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.section-head h2 {
  margin: 0;
  font-size: 30px;
}

.section-head p {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
}

.project-search {
  max-width: 760px;
  margin: 2px 0 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 86%, var(--bg));
  box-shadow: 0 16px 42px rgba(31, 41, 51, 0.08);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.project-search-label {
  display: block;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.project-search-box {
  display: flex;
  align-items: center;
  min-height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 32px rgba(31, 41, 51, 0.1);
  transition: border-color 150ms ease, background-color 180ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.project-search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus-ring), 0 18px 38px rgba(31, 41, 51, 0.12);
  transform: translateY(-1px);
}

.project-search-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-left: 8px;
  border-radius: 8px;
  border: 0;
  background: var(--tag-bg);
  color: var(--primary-dark);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.project-search-icon:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.project-search-input {
  flex: 1;
  min-width: 0;
  min-height: 54px;
  border: 0;
  padding: 0 14px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 650;
}

.project-search-input::placeholder {
  color: var(--muted);
  opacity: 0.86;
  transition: opacity 160ms ease, color 160ms ease;
}

.project-search-box:focus-within .project-search-input::placeholder {
  color: var(--primary-dark);
  opacity: 0.48;
}

.project-search-input::-webkit-search-cancel-button {
  appearance: none;
}

.project-search-input:focus {
  outline: 0;
}

.project-search-clear {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  margin-right: 9px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, background-color 150ms ease, color 150ms ease;
}

.project-search.has-query .project-search-clear {
  opacity: 1;
  pointer-events: auto;
}

.project-search-clear:hover,
.project-search-clear:focus-visible {
  background: var(--skill-bg);
  color: var(--text);
  outline: 0;
}

.project-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.project-filter {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.project-filter:hover {
  transform: translateY(-1px);
  border-color: var(--hover-line);
}

.project-filter:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.project-filter.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

.project-search-empty {
  margin: 10px 2px 0;
  color: var(--muted);
  font-weight: 750;
}

.project-search-count {
  min-height: 20px;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

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

.project-card {
  display: flex;
  flex-direction: column;
  min-height: 230px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.05);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background-color 180ms ease, color 180ms ease;
}

.project-card:hover {
  transform: translateY(-2px);
  border-color: var(--hover-line);
  box-shadow: var(--shadow);
}

.project-card.featured {
  grid-column: span 2;
  background: var(--featured-bg);
  border-color: var(--featured-line);
}

.tag {
  align-self: flex-start;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.project-card h3 {
  margin: 18px 0 8px;
  font-size: 22px;
}

.project-card p {
  margin: 0;
  color: var(--muted);
  flex: 1;
}

.project-card a {
  margin-top: 20px;
  color: var(--primary-dark);
  font-weight: 800;
}

.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.project-actions .button {
  margin-top: 0;
}

.project-meta {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.about-card,
.skills-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.05);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.skills-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.skill-pill {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--skill-bg);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

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

.academic-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.05);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background-color 180ms ease, color 180ms ease;
}

.academic-card:hover {
  transform: translateY(-2px);
  border-color: var(--strong-hover-line);
  box-shadow: var(--shadow);
}

.academic-media {
  display: block;
  border-radius: 8px;
  line-height: 0;
  margin: 18px 18px 0;
}

.academic-image {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(31, 41, 51, 0.08);
}

.academic-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 22px;
}

.academic-body h3 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.academic-subtitle {
  margin: 8px 0 0;
  color: var(--primary-dark);
  font-weight: 800;
}

.academic-description {
  margin: 14px 0 0;
  color: var(--muted);
  flex: 1;
}

.academic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.timeline-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.05);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

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

.timeline-list li {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.timeline-year {
  font-weight: 800;
  color: var(--primary-dark);
}

.detail-header {
  padding: 24px 0 10px;
}

.detail-header .nav-right {
  gap: 12px;
}

.detail-hero {
  padding: 28px 0 10px;
}

.detail-hero h1 {
  max-width: 820px;
  font-size: clamp(34px, 6vw, 58px);
}

.detail-hero p {
  max-width: 720px;
  margin: 16px 0 0;
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.detail-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.05);
}

.detail-card h3 {
  margin: 0 0 12px;
  font-size: 20px;
}

.detail-card p {
  margin: 0;
  color: var(--muted);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(31, 41, 51, 0.12);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease, background-color 180ms ease, border-color 180ms ease;
  z-index: 10;
}

.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover {
  border-color: var(--hover-line);
  transform: translateY(-2px);
}

.back-to-top:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.ai-section {
  display: block;
  position: static;
  visibility: visible;
  opacity: 1;
  clear: both;
}

.ai-card {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.05);
  overflow: hidden;
}

.ai-chat {
  min-height: 180px;
  max-height: 360px;
  overflow-y: auto;
  padding: 20px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}

.ai-message {
  width: fit-content;
  max-width: min(760px, 100%);
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  white-space: pre-wrap;
}

.ai-message.user {
  margin-left: auto;
  background: var(--user-message-bg);
  border-color: var(--user-message-line);
}

.ai-message.error {
  color: var(--error-text);
  background: var(--error-bg);
  border-color: var(--error-line);
}

.ai-message.thinking {
  background: var(--thinking-bg);
  border-color: var(--thinking-line);
  color: var(--thinking-text);
}

.ai-form {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--panel);
}

.ai-input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.ai-input:focus {
  outline: 2px solid var(--focus-ring);
  border-color: var(--primary);
}

.ai-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ai-file-status {
  padding: 16px 16px 0;
  color: var(--muted);
  font-size: 13px;
}

.contact {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  padding-bottom: 64px;
}

.contact-item {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background-color 180ms ease, color 180ms ease;
}

.contact-item:hover {
  transform: translateY(-2px);
  border-color: var(--hover-line);
  box-shadow: var(--shadow);
}

.contact-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.contact-item a,
.contact-item strong {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.guestbook-section {
  padding-top: 0;
}

.guestbook-card {
  min-height: 180px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.05);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.guestbook-card .giscus,
.guestbook-card .giscus-frame {
  width: 100%;
}

footer {
  border-top: 1px solid var(--line);
  padding: 24px 0 34px;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 860px) {
  .nav {
    flex-wrap: wrap;
    gap: 12px 18px;
  }

  .nav-right {
    width: 100%;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px 12px;
  }

  .nav-links {
    flex: 1 1 460px;
    gap: 10px 14px;
  }

  .hero,
  .contact {
    grid-template-columns: 1fr;
  }

  .hero {
    padding-top: 28px;
  }

  .hero-main,
  .profile-card {
    min-height: auto;
  }

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

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

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

@media (max-width: 560px) {
  .site {
    width: min(100% - 28px, 1120px);
  }

  .nav {
    align-items: flex-start;
    gap: 14px;
    flex-direction: column;
  }

  .nav-links {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
  }

  .nav-right {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .intro {
    font-size: 17px;
  }

  .section-head {
    display: block;
  }

  .section-head p {
    margin-top: 8px;
  }

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

  .project-card.featured {
    grid-column: auto;
  }

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

  .academic-body h3 {
    font-size: 21px;
  }

  .academic-description {
    font-size: 16px;
  }

  .ai-form {
    flex-direction: column;
  }

  .ai-form .button {
    width: 100%;
  }

  .timeline-list li {
    grid-template-columns: 1fr;
  }

  .back-to-top {
    right: 16px;
    bottom: 16px;
  }
}
