/* ============================================================
   writing.css — 英作文添削ページのスタイル
   2カラムレイアウト（モバイルでは1カラム）
   カテゴリ色分け: GRAMMAR=赤, TYPOS=オレンジ, STYLE=青
   ============================================================ */

/* ---- ページ全体レイアウト ---- */
.writing-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.writing-header {
  margin-bottom: 1.5rem;
}

.writing-header .page-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--color-heading, #1a1a2e);
}

.writing-header .page-description {
  color: var(--color-text-muted, #555);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ---- 2カラムレイアウト ---- */
.writing-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 768px) {
  .writing-layout {
    grid-template-columns: 1fr;
  }
}

/* ---- 入力カラム ---- */
.writing-input-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---- CEFRレベル選択 ---- */
.level-selector-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.label-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text, #333);
  white-space: nowrap;
}

.cefr-select {
  padding: 0.4rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.9rem;
  background-color: #fff;
  cursor: pointer;
}

.cefr-select:focus {
  outline: 2px solid #10b981;
  outline-offset: 1px;
}

/* ---- トピック例 ---- */
.topic-prompts {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.topic-label {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.topic-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.topic-list li button {
  background: none;
  border: none;
  color: #10b981;
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
  padding: 0.2rem 0;
  line-height: 1.4;
  text-decoration: underline;
}

.topic-list li button:hover {
  color: #059669;
}

/* ---- テキストエリア ---- */
.textarea-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.writing-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.writing-textarea:focus {
  outline: none;
  border-color: #10b981;
}

.char-counter {
  text-align: right;
  font-size: 0.8rem;
  color: #888;
}

.char-counter.near-limit {
  color: #e67e22;
}

.char-counter.at-limit {
  color: #e74c3c;
  font-weight: 700;
}

/* ---- ボタン群 ---- */
.button-row {
  display: flex;
  gap: 0.75rem;
}

.btn-correct {
  flex: 1;
  padding: 0.65rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background-color: #10b981;
  color: #fff;
  transition: background-color 0.2s;
}

.btn-correct:hover:not(:disabled) {
  background-color: #059669;
}

.btn-correct:disabled {
  background-color: #a0b8d4;
  cursor: not-allowed;
}

.btn-reset {
  padding: 0.65rem 1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: #555;
  cursor: pointer;
  transition:
    border-color 0.2s,
    color 0.2s;
}

.btn-reset:hover {
  border-color: #aaa;
  color: #333;
}

/* ---- ローディング ---- */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #555;
  font-size: 0.9rem;
}

.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #ccc;
  border-top-color: #10b981;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- エラーバナー ---- */
.error-banner {
  background: #fff0f0;
  border: 1px solid #e74c3c;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: #c0392b;
  font-size: 0.9rem;
}

/* ---- 結果カラム ---- */
.writing-result-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.result-area {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---- 統計バー ---- */
.stats-bar {
  display: flex;
  gap: 1.5rem;
  background: #f0f4ff;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.stat-label {
  font-size: 0.75rem;
  color: #888;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #2c3e50;
}

/* ---- Before / After 比較 ---- */
.before-after-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 480px) {
  .before-after-section {
    grid-template-columns: 1fr;
  }
}

.before-box,
.after-box {
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.before-box {
  background: #fff5f5;
  border: 1px solid #f5c6c6;
}

.after-box {
  background: #f0fff4;
  border: 1px solid #a8d5b5;
}

.before-after-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
  color: #555;
}

.before-text,
.after-text {
  font-size: 0.95rem;
  line-height: 1.6;
  margin: 0;
  word-break: break-word;
}

/* ---- 指摘リスト ---- */
.issues-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.issues-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.issues-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: #e74c3c;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.issues-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---- 指摘カード ---- */
.issue-card {
  border-radius: 8px;
  padding: 0.85rem 1rem;
  border-left: 4px solid #ccc;
  background: #fafafa;
}

/* カテゴリ別色分け */
.issue-card.category-grammar {
  border-left-color: #e74c3c;
  background: #fff8f8;
}

.issue-card.category-typos {
  border-left-color: #e67e22;
  background: #fffbf5;
}

.issue-card.category-style {
  border-left-color: #10b981;
  background: #f5faff;
}

.issue-card.category-other {
  border-left-color: #95a5a6;
  background: #fafafa;
}

.issue-category-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.4rem;
}

.category-grammar .issue-category-badge {
  background: #fde8e8;
  color: #c0392b;
}

.category-typos .issue-category-badge {
  background: #fdebd0;
  color: #a04000;
}

.category-style .issue-category-badge {
  background: #d6eaf8;
  color: #047857;
}

.category-other .issue-category-badge {
  background: #eaeded;
  color: #555;
}

.issue-message {
  font-size: 0.9rem;
  color: #333;
  margin-bottom: 0.35rem;
}

.issue-correction {
  font-size: 0.85rem;
  color: #555;
}

.issue-original {
  text-decoration: line-through;
  color: #e74c3c;
}

.issue-arrow {
  margin: 0 0.25rem;
}

.issue-suggestion {
  font-weight: 600;
  color: #27ae60;
}

.issue-context {
  font-size: 0.8rem;
  color: #888;
  font-style: italic;
  margin-top: 0.3rem;
}

.no-issues-message {
  color: #27ae60;
  font-weight: 600;
  padding: 0.75rem;
  background: #f0fff4;
  border-radius: 8px;
  text-align: center;
}

/* ---- 履歴セクション ---- */
.history-section {
  border-top: 1px solid #eee;
  padding-top: 1rem;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.button-text {
  background: none;
  border: none;
  color: #999;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

.button-text:hover {
  color: #e74c3c;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.history-item:hover {
  background: #eef0f2;
}

.history-item-text {
  font-size: 0.85rem;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.history-item-meta {
  font-size: 0.75rem;
  color: #aaa;
  white-space: nowrap;
}

.no-history-message {
  font-size: 0.85rem;
  color: #aaa;
  text-align: center;
  padding: 0.5rem;
}
