﻿:root {
  --bg: #f4f8ff;
  --card: #ffffff;
  --text: #18314f;
  --muted: #5f738b;
  --primary: #2e87ff;
  --primary-strong: #1562d6;
  --ok: #14804a;
  --ng: #c53338;
  --line: #dce7f5;
  --shadow: 0 8px 24px rgba(24, 49, 79, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: var(--text);
  background: linear-gradient(165deg, #f4f8ff 0%, #edf7ff 50%, #f9fcff 100%);
}

.app {
  width: min(1200px, 96vw);
  margin: 24px auto 40px;
}

.app-header,
.tab-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.app-header {
  padding: 18px;
}

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

.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.header-controls {
  margin-top: 10px;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(260px, 320px);
  gap: 16px;
  align-items: start;
}

.header-controls.collapsed {
  display: none;
}

.header-side {
  justify-self: end;
  width: 100%;
  max-width: 320px;
}

.set-switcher {
  margin-top: 0;
  max-width: 520px;
}

h1 {
  margin: 0;
  font-size: clamp(1.3rem, 2.5vw, 1.9rem);
}

h2 {
  margin: 0;
  font-size: 1.2rem;
}

.sub {
  margin: 8px 0 0;
  color: var(--muted);
}

.progress-wrap {
  margin-top: 14px;
}

.progress-text {
  font-weight: 700;
}

.progress-bar-bg {
  margin-top: 8px;
  height: 14px;
  border-radius: 999px;
  background: #e9f1ff;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #6ac2ff, #2e87ff);
  transition: width 0.25s ease;
}

.top-actions {
  margin-top: 12px;
}

.reset-edge-btn {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.xp-panel {
  margin-top: 12px;
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #eef7ff, #f7fbff);
  border: 1px solid #d7e7fb;
}

.xp-label {
  color: var(--muted);
  font-size: 0.92rem;
}

.xp-value {
  font-weight: 800;
  font-size: 1.25rem;
  color: #0f4ba0;
}

.sync-status {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: #365b86;
}

.sync-status.online {
  color: #1f7b4b;
}

.sync-status.offline {
  color: #b15b1e;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.tabs-toggle-btn {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.tab-btn,
button,
.text-input {
  font: inherit;
}

.tab-btn,
button {
  border: 1px solid #c8d9f1;
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  min-height: 46px;
}

.tab-btn.active,
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.primary-btn:hover,
.tab-btn.active:hover,
.filter-btn.active:hover {
  background: var(--primary-strong);
}

.danger-btn {
  color: #fff;
  background: #d65159;
  border-color: #d65159;
}

.tab-panel {
  margin-top: 10px;
  padding: 16px;
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.study-card {
  margin-top: 14px;
  background: #f7fbff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.range-controls {
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid #d8e7fb;
  border-radius: 12px;
  background: #f1f7ff;
}

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

.range-input {
  width: 88px;
  min-height: 42px;
  border: 1px solid #bdd1eb;
  border-radius: 10px;
  padding: 8px;
}

.label {
  font-size: 0.95rem;
  color: var(--muted);
}

.word-ja,
.flip-word {
  font-weight: 700;
  font-size: clamp(1.3rem, 4.2vw, 2rem);
  margin: 8px 0 14px;
}

.text-input {
  width: 100%;
  border: 1px solid #bdd1eb;
  border-radius: 12px;
  min-height: 46px;
  padding: 10px 12px;
}

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

.hint {
  color: var(--muted);
}

.feedback {
  min-height: 1.4em;
  font-weight: 700;
}

.feedback.ok {
  color: var(--ok);
}

.feedback.ng {
  color: var(--ng);
}

.model-answer {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #d9e6fb;
}

.model-answer-label {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

.model-answer-text {
  display: block;
  margin-top: 4px;
  font-weight: 800;
  font-size: 1.08rem;
  color: #0f4ba0;
}

.flip-card {
  margin-top: 14px;
  min-height: 250px;
  border-radius: 16px;
  border: 1px solid #bfd6f7;
  background: transparent;
  box-shadow: var(--shadow);
  text-align: center;
  perspective: 1200px;
  overflow: hidden;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  min-height: 250px;
  transform-style: preserve-3d;
  transition: transform 320ms ease;
}

.flip-card.is-back .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 20px;
  border-radius: 16px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flip-front {
  background: linear-gradient(180deg, #fafdff 0%, #eef6ff 100%);
}

.flip-back {
  background: linear-gradient(180deg, #eef6ff 0%, #e4f0ff 100%);
  transform: rotateY(180deg);
}

.match-board {
  margin-top: 14px;
  border: 1px solid var(--line);
  background: #f7fbff;
  border-radius: 14px;
  padding: 14px;
  --match-board-height: 68vh;
}

.match-board.fullscreen {
  margin-top: 0;
  border-radius: 0;
  border: none;
  padding: 16px;
}

.match-status {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  color: #355a83;
}

.match-columns {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-height: var(--match-board-height);
}

.match-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(var(--match-cols, 3), minmax(0, 1fr));
  grid-template-rows: repeat(var(--match-rows, 3), minmax(0, 1fr));
  min-height: calc(var(--match-board-height) - 50px);
}

.match-item {
  width: 100%;
  aspect-ratio: 1 / 1;
  text-align: center;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  padding: 10px;
  line-height: 1.3;
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
}

.match-item.selected {
  border-color: var(--primary);
  background: #eaf3ff;
}

.match-item.matched {
  border-color: #79c5a0;
  background: #eaf8f1;
  color: #1f7b4b;
  cursor: default;
  opacity: 0.5;
}

.list-controls {
  margin-top: 14px;
  background: #f7fbff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.filter-btn {
  background: #fff;
}

.table-wrap {
  margin-top: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.word-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  background: #fff;
}

.set-table {
  min-width: 520px;
}

.set-table td:first-child {
  width: 140px;
}

.word-table th,
.word-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #e4edf9;
  text-align: left;
  vertical-align: middle;
}

.word-table th {
  background: #f2f7ff;
  color: #365b86;
  font-size: 0.92rem;
}

.word-table td.en {
  font-weight: 700;
  font-size: 1.04rem;
  color: #0f4ba0;
}

#import-preview-wrap .word-table {
  min-width: 520px;
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.status-mastered {
  background: #e6f6ec;
  color: #1f7b4b;
}

.status-unmastered {
  background: #fff2e8;
  color: #ad5a1d;
}

.speak-small {
  min-height: 38px;
  padding: 8px 10px;
}

.result-list {
  margin: 12px 0 0;
  padding-left: 20px;
}

.result-list li {
  margin: 6px 0;
}

.result-ok {
  color: var(--ok);
}

.result-ng {
  color: var(--ng);
}

.json-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  background: #f7fbff;
  border-radius: 12px;
  padding: 14px;
  overflow-x: auto;
}

.hidden {
  display: none;
}

button:focus-visible,
.text-input:focus-visible,
.flip-card:focus-visible,
.range-input:focus-visible {
  outline: 3px solid #9cc4ff;
  outline-offset: 2px;
}

@media (max-width: 680px) {
  .app {
    width: min(98vw, 700px);
    margin-top: 12px;
  }

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

  .header-actions {
    align-items: stretch;
  }

  .header-controls {
    grid-template-columns: 1fr;
  }

  .header-side {
    max-width: none;
  }

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

  .tabs-toggle-btn {
    width: 100%;
  }

  .tab-btn,
  button {
    min-height: 48px;
  }

  .word-table {
    min-width: 560px;
  }

  .range-input {
    width: 78px;
  }

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

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

.match-board.fullscreen .match-columns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: var(--match-board-height);
}

.match-board.fullscreen .match-list {
  min-height: calc(var(--match-board-height) - 40px);
}
