@charset "UTF-8";

:root {
  --bg: #f7f4ee;
  --paper: #fffdf8;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #ded7cb;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --shadow: 0 18px 42px rgba(43, 34, 23, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "YuGothic", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 330px) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfaf6;
}

.brand h1 {
  margin: 0 0 8px;
  font-size: 25px;
  line-height: 1.25;
}

.brand p,
.meta {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.search-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 0 12px;
  color: var(--ink);
}

.music-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.music-label,
.music-status {
  margin: 0;
}

.music-label {
  color: var(--muted);
  font-size: 12px;
}

.music-status {
  margin-top: 3px;
  font-size: 14px;
  line-height: 1.4;
}

.music-panel button {
  width: 100%;
}

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

.tab.is-active,
.icon-text.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #1d4ed8;
}

.character-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 8px;
  align-content: start;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: 16px;
}

.app-credit {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.app-credit p {
  margin: 0;
}

.app-credit a {
  color: #1d4ed8;
  text-decoration: none;
}

.character-button {
  aspect-ratio: 1;
  min-height: 48px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

.character-button.is-word {
  aspect-ratio: auto;
  grid-column: span 2;
  font-size: 22px;
}

.character-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.empty-list {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.practice {
  display: grid;
  grid-template-rows: auto auto;
  gap: 18px;
  padding: 24px;
}

.viewer,
.writing-area {
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.viewer {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 16px;
  padding: 20px;
}

.viewer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.viewer h2 {
  margin: 2px 0 0;
  font-size: 48px;
  line-height: 1;
}

.mark-buttons,
.controls,
.clear-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.model-grid,
.copy-grid {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 1;
  justify-self: center;
  align-self: center;
  border: 2px solid #b8aa98;
}

.copy-grid {
  background:
    linear-gradient(to right, transparent calc(50% - 1px), #c9bdaf calc(50% - 1px), #c9bdaf calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - 1px), #c9bdaf calc(50% - 1px), #c9bdaf calc(50% + 1px), transparent calc(50% + 1px)),
    #fffefb;
}

.model-grid {
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(to right, transparent calc(50% - 1px), rgba(255, 255, 255, 0.32) calc(50% - 1px), rgba(255, 255, 255, 0.32) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - 1px), rgba(255, 255, 255, 0.32) calc(50% - 1px), rgba(255, 255, 255, 0.32) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to right, rgba(251, 207, 214, 0.72) 0 50%, rgba(255, 247, 186, 0.72) 50% 100%) top / 100% 50% no-repeat,
    linear-gradient(to right, rgba(175, 232, 238, 0.72) 0 50%, rgba(207, 239, 178, 0.72) 50% 100%) bottom / 100% 50% no-repeat;
}

.reference-glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(31, 41, 55, 0.16);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "YuGothic", sans-serif;
  font-size: clamp(232px, 56vw, 500px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
}

.reference-glyph.is-word {
  font-size: clamp(140px, 30vw, 300px);
}

.stroke-svg {
  width: min(92%, 620px);
  height: min(92%, 620px);
  max-height: 100%;
  overflow: visible;
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.stroke-svg.is-word {
  display: none;
}

.guide-path {
  display: none;
}

.stroke-path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stroke-number {
  fill: var(--danger);
  font-size: 8px;
  font-weight: 700;
}

.controls {
  justify-content: center;
}

.clear-controls {
  justify-content: center;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.writing-area {
  display: grid;
  grid-template-rows: 1fr;
  padding: 16px;
  place-items: center;
}

.copy-grid {
  touch-action: none;
}

.writing-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  z-index: 3;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .practice {
    grid-template-rows: auto auto;
    padding: 16px;
  }

  .viewer-top {
    align-items: stretch;
    flex-direction: column;
  }

  .model-grid,
  .copy-grid {
    width: min(100%, 460px);
  }
}

/* LiNest v3: 機能と書字面を保ったまま、外枠だけをブランドにそろえる。 */
body.linest-themed {
  --bg: var(--linest-bg);
  --paper: var(--linest-surface);
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --accent: var(--linest-green);
  --accent-soft: var(--linest-green-soft);
  --shadow: var(--linest-shadow);
}

body.linest-themed .sidebar {
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 8px 0 26px rgba(74, 55, 40, 0.06);
}

body.linest-themed :where(.music-panel, .viewer, .writing-area) {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed :where(button, .search-box input) {
  border-color: var(--linest-border);
  background-color: #ffffff;
  color: var(--linest-text);
}

body.linest-themed :where(.tab.is-active, .icon-text.is-active) {
  border-color: var(--linest-green);
  background: var(--linest-green-soft);
  color: var(--linest-green-dark);
}

body.linest-themed .character-button.is-active {
  border-color: var(--linest-green);
  background: var(--linest-green);
  color: #ffffff;
}

body.linest-themed .app-credit a {
  color: var(--linest-green-dark);
}

@media (max-width: 860px) {
  body.linest-themed .sidebar {
    box-shadow: 0 8px 24px rgba(74, 55, 40, 0.06);
  }
}

@media (max-width: 430px) {
  body.linest-themed .sidebar,
  body.linest-themed .practice {
    padding-inline: 10px;
  }

  body.linest-themed :where(.mark-buttons, .controls, .clear-controls) > button {
    flex: 1 1 118px;
    min-width: 0;
    padding-inline: 8px;
    white-space: normal;
    word-break: keep-all;
  }
}
