:root {
  --bg: #f4f6ea;
  --card: #ffffffd9;
  --line: #192019;
  --muted: #5f6b60;
  --ink: #0f150f;
  --accent: #6f7d45;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Serif KR", "Apple SD Gothic Neo", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, #dde8c7 0%, transparent 32%),
    radial-gradient(circle at 85% 80%, #e7dcc2 0%, transparent 28%),
    var(--bg);
}

.app {
  width: min(1200px, 96vw);
  margin: 2rem auto;
  padding: 1rem;
  border: 1px solid #c0c8b0;
  background: var(--card);
  backdrop-filter: blur(4px);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.paging,
.modes {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.selection-shape-control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.selection-shape-label {
  font-size: 0.8rem;
  color: #4f5c4b;
  white-space: nowrap;
}

.mode-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid #bcc3ad;
  background: #f5f8ee;
}

.mode-title {
  font-size: 0.78rem;
  color: #4f5c4b;
  padding-right: 0.25rem;
}

button {
  border: 1px solid #8d9679;
  background: #fff;
  color: #1d2419;
  padding: 0.45rem 0.7rem;
  font-size: 0.9rem;
  cursor: pointer;
}

button:hover {
  background: #eef2e5;
}

button.is-active {
  background: #dce8c3;
  border-color: #6f7d45;
}

.selection-shape-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.18rem;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border-radius: 999px;
  border-color: #5f8446;
  background: linear-gradient(180deg, #86c85b 0%, #5ea93b 100%);
  box-shadow:
    inset 0 1px 0 #c6ecab59,
    0 1px 2px #2433141f;
  transition:
    border-color 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.selection-shape-toggle:hover {
  background: linear-gradient(180deg, #93d467 0%, #65b740 100%);
  border-color: #557b3d;
}

.selection-shape-toggle.is-active {
  background: linear-gradient(180deg, #7ecb4f 0%, #529d34 100%);
  border-color: #4b7734;
  box-shadow:
    inset 0 1px 0 #d3f5bb40,
    0 1px 2px #1f2f151f;
}

.selection-shape-toggle::before {
  content: "";
  position: absolute;
  top: 0.18rem;
  bottom: 0.18rem;
  left: 0.18rem;
  width: calc((100% - 0.51rem) / 2);
  border-radius: 999px;
  background: #ffffff;
  box-shadow:
    0 1px 3px #1a23151c,
    inset 0 1px 0 #ffffff;
  transform: translateX(0);
  transition:
    transform 0.22s cubic-bezier(0.2, 0.9, 0.2, 1),
    background-color 0.18s ease,
    box-shadow 0.18s ease;
  z-index: 2;
}

.selection-shape-toggle[data-shape-mode="rect"]::before {
  transform: translateX(calc(100% + 0.15rem));
}

.selection-shape-toggle.is-active::before {
  background: #fefefe;
}

.selection-shape-toggle__option {
  position: relative;
  z-index: 1;
  min-width: 3.05rem;
  padding: 0.28rem 0.48rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1;
  color: #ffffff00;
  text-align: center;
  text-shadow: none;
  transition:
    color 0.15s ease,
    transform 0.22s cubic-bezier(0.2, 0.9, 0.2, 1),
    letter-spacing 0.18s ease,
    text-shadow 0.18s ease;
}

.selection-shape-toggle[data-shape-mode="path"] [data-shape-option="path"],
.selection-shape-toggle[data-shape-mode="rect"] [data-shape-option="rect"] {
  z-index: 3;
  color: #f8fff1;
  text-shadow: 0 1px 1px #2d4d1e66;
  transform: translateY(-1px);
  letter-spacing: 0.07em;
}

.selection-shape-toggle[data-shape-mode="path"] [data-shape-option="rect"],
.selection-shape-toggle[data-shape-mode="rect"] [data-shape-option="path"] {
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .selection-shape-toggle,
  .selection-shape-toggle::before,
  .selection-shape-toggle__option {
    transition: none;
  }
}

.grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--line);
  user-select: none;
}

.cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  aspect-ratio: 1 / 1;
  position: relative;
  display: grid;
  place-items: center;
  text-align: center;
  overflow: hidden;
  transition: background-color 0.15s ease;
}

.cell[data-kanji] {
  cursor: pointer;
  background: #fff;
}

.cell.is-unmemorized {
  background: #fff;
}

.cell.is-memorized {
  background: #dfe8c9;
}

.cell.is-temp-selected {
  box-shadow:
    inset 0 0 0 2px #ffffff,
    inset 0 0 0 5px #58763c;
  z-index: 1;
}

.cell[data-kanji]:focus-visible {
  outline: 2px solid #6f7d45;
  outline-offset: -2px;
}

.cell.is-memorized::after {
  content: "✓";
  position: absolute;
  top: 0.18rem;
  right: 0.22rem;
  width: 1.05rem;
  height: 1.05rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #5f7d42;
  color: #fff;
  border: 1px solid #4a6333;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

.cell:nth-child(10n) {
  border-right: none;
}

.hanja {
  font-size: clamp(1.2rem, 2.2vw, 1.95rem);
  line-height: 1;
}

.ko-info {
  position: absolute;
  inset: auto 0 0;
  border-top: 1px solid #b6bda7;
  background: #f8fbf2;
  color: #22311d;
  font-size: clamp(0.58rem, 1.1vw, 0.72rem);
  line-height: 1.2;
  padding: 0.16rem 0.2rem;
  transform: translateY(110%);
  transition: transform 0.2s ease;
}

.jp-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 0.22rem;
  font-size: clamp(0.55rem, 1vw, 0.7rem);
  color: #222;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  background: transparent;
  text-shadow: 0 1px 0 #ffffffc4;
}

.jp-example {
  position: absolute;
  inset: auto 0 0;
  border-top: 1px solid #d5dbca;
  background: #ffffffd6;
  color: #1f2a1d;
  font-size: clamp(0.56rem, 1vw, 0.7rem);
  line-height: 1.15;
  padding: 0.16rem 0.2rem;
  opacity: 0;
  transform: translateY(110%);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.mode-ko .ko-info {
  transform: translateY(0);
}

.mode-jp .jp-overlay {
  opacity: 1;
}

.mode-c .jp-example {
  opacity: 1;
  transform: translateY(0);
}

.selection-action-popover {
  position: fixed;
  z-index: 50;
  min-width: 178px;
  max-width: min(240px, calc(100vw - 16px));
  padding: 0.55rem;
  border: 1px solid #b8c4a6;
  background: #fbfdf7f0;
  backdrop-filter: blur(4px);
  box-shadow: 0 10px 26px #1d241926;
}

.selection-action-popover[hidden] {
  display: none;
}

.selection-action-popover__count {
  font-size: 0.78rem;
  color: #42543a;
  margin-bottom: 0.45rem;
}

.selection-action-popover__buttons {
  display: grid;
  gap: 0.35rem;
}

.selection-action-popover__buttons button {
  width: 100%;
  text-align: left;
  padding: 0.42rem 0.55rem;
  font-size: 0.84rem;
}

.selection-marquee {
  position: fixed;
  z-index: 45;
  border: 1px dashed #58763c;
  background: #8fb36b22;
  pointer-events: none;
}

.selection-marquee[hidden] {
  display: none;
}

@media (max-width: 980px) {
  .grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .cell:nth-child(10n) {
    border-right: 1px solid var(--line);
  }

  .cell:nth-child(8n) {
    border-right: none;
  }
}

@media (max-width: 760px) {
  .grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .cell:nth-child(8n) {
    border-right: 1px solid var(--line);
  }

  .cell:nth-child(6n) {
    border-right: none;
  }
}

@media (max-width: 520px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .cell:nth-child(6n) {
    border-right: 1px solid var(--line);
  }

  .cell:nth-child(4n) {
    border-right: none;
  }
}
