@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@400;600;700&display=swap');

:root {
  --dark: #141413;
  --light: #faf9f5;
  --mid-gray: #b0aea5;
  --light-gray: #e8e6dc;
  --accent-orange: #d97757;
  --accent-blue: #6a9bcc;
  --accent-green: #788c5d;
  --min-onkun-lines: 5;
  --min-old-form-lines: 1;
  --min-detail-rows: 5;
  --font-ui: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", "MS PMincho", serif;
  --font-jp: "Hiragino Mincho ProN", "Yu Mincho", "MS PMincho", "Noto Serif JP", serif;
}

html[data-theme="dark"] {
  --dark: #faf9f5;
  --light: #141413;
  --mid-gray: #6f6d64;
  --light-gray: #232320;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--light);
  color: var(--dark);
  font-family: var(--font-ui);
}

.app {
  min-height: 100svh;
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 16px 12px;
  position: relative;
}

.theme-switch {
  display: flex;
  gap: 2px;
  align-items: center;
  position: absolute;
  top: 9px;
  right: 16px;
}

.theme-user {
  margin-left: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-user.is-hidden {
  display: none;
}

.theme-username {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}

.theme-logout {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.76rem;
}

.theme-btn {
  border: none;
  background: transparent;
  color: var(--mid-gray);
  border-radius: 8px;
  padding: 3px;
  cursor: pointer;
  line-height: 0;
}

.theme-btn:hover {
  background: var(--light-gray);
}

.theme-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  display: block;
}

.theme-btn.is-active {
  color: #000;
}

html[data-theme="dark"] .theme-btn.is-active {
  color: #fff;
}

.header {
  text-align: center;
}

.header h1 {
  margin: 6px 0 0;
  padding: 10px 0 12px;
  font-size: 1.45rem;
}

.study-app .header {
  padding-top: 18px;
}

.muted {
  color: #5b5a54;
}

.progress-row {
  margin: 8px 0 0;
  display: flex;
  justify-content: space-between;
  color: #5b5a54;
  font-size: 0.9rem;
}

.card-wrap {
  margin-top: 20px;
}

.onkun-top {
  margin: 0 0 8px;
  font-size: 0.94rem;
  height: calc(var(--min-onkun-lines) * 1.2em);
  color: var(--dark);
  font-family: var(--font-jp);
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(var(--onkun-rows, 1), 1.2em);
  grid-template-columns: repeat(var(--onkun-cols, 1), max-content);
  align-content: end;
  justify-content: center;
  justify-items: center;
  align-items: end;
  column-gap: 14px;
  row-gap: 0;
  overflow: hidden;
}

.onkun-item {
  line-height: 1.2;
  white-space: nowrap;
}

.kanji-card {
  height: 1.12em;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: clamp(3.6rem, 15vw, 6.8rem);
  line-height: 1;
  letter-spacing: 0.04em;
  font-family: var(--font-jp);
}

.card-meta {
  text-align: center;
  margin: 8px 0 0;
}

.old-form {
  margin: 2px 0 0;
  height: calc(var(--old-form-lines, var(--min-old-form-lines)) * 1.2em);
  text-align: center;
  font-size: 1.04rem;
  line-height: 1.2;
  color: var(--dark);
  font-family: var(--font-jp);
  white-space: pre-line;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.kanji-details {
  margin: 32px 0 24px;
  height: calc((var(--min-detail-rows) + 1) * 2.12rem);
  position: relative;
  overflow: hidden;
}

.kanji-scroll {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.kanji-details::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.16s ease-out;
  background: linear-gradient(to bottom, rgba(250, 249, 245, 0), var(--light) 78%);
}

.kanji-details.has-more::after {
  opacity: 1;
}

.kanji-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.94rem;
  font-family: var(--font-jp);
}

.kanji-table th,
.kanji-table td {
  border-bottom: 1px solid var(--light-gray);
  text-align: left;
  vertical-align: top;
  padding: 6px 8px;
  line-height: 1.45;
  word-break: break-word;
}

.kanji-table th {
  color: #5b5a54;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--light);
}

.kanji-table th:nth-child(1),
.kanji-table td:nth-child(1) {
  width: 24%;
}

.kanji-table th:nth-child(2),
.kanji-table td:nth-child(2) {
  width: 46%;
}

.kanji-table th:nth-child(3),
.kanji-table td:nth-child(3) {
  width: 30%;
}

.actions {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 12px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-green);
  color: var(--light);
}

.btn-secondary {
  background: var(--accent-orange);
  color: var(--light);
}

.btn-ghost {
  background: transparent;
  color: #5b5a54;
  border: 1px solid var(--light-gray);
}

.btn-small {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
}

.review-forgot {
  margin-top: 22px;
  width: 100%;
}

.status {
  margin-top: 8px;
  min-height: 1.2em;
  color: #5b5a54;
  text-align: left;
  font-size: 0.9rem;
}
