/* TOEIC Speaking Study App */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.05);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header h1 { font-size: 1.25rem; font-weight: 700; }
.header h1 a { color: var(--text); }
.header nav { display: flex; gap: 1.5rem; align-items: center; }
.header nav a { color: var(--text-muted); font-weight: 500; }
.header nav a.active, .header nav a:hover { color: var(--primary); text-decoration: none; }

/* Container */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}

/* Home grid */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card h2 { font-size: 1.25rem; margin-bottom: 0.5rem; }
.card .badge { display:inline-block; background: #eff6ff; color: var(--primary); padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; margin-bottom: 0.5rem; }
.card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.card .actions { display: flex; gap: 0.5rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.5rem 1rem; border-radius: 6px; font-weight: 500; font-size: 0.9rem;
  border: 1px solid var(--border); background: white; color: var(--text);
  cursor: pointer; transition: all 0.15s; text-decoration: none;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { filter: brightness(0.9); color: white; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-large { padding: 0.75rem 2rem; font-size: 1rem; }

/* Practice page */
.practice-page { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
.practice-toolbar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  background: var(--card); padding: 1rem; border-radius: 8px; border: 1px solid var(--border);
}
.practice-toolbar select {
  padding: 0.4rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; background: white; font-size: 0.95rem;
}
.practice-toolbar .item-counter {
  margin-left: auto; color: var(--text-muted); font-size: 0.9rem;
}

.timer-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 1rem 1.5rem; display: flex; align-items: center; gap: 1rem;
}
.timer-box.prep { background: #fef3c7; border-color: #fde68a; }
.timer-box.response { background: #dbeafe; border-color: #93c5fd; }
.timer-box.idle { background: #f1f5f9; }
.timer-label { font-weight: 600; }
.timer-value {
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 1.5rem; font-weight: 700; min-width: 70px;
}
.timer-bar {
  flex: 1; height: 8px; background: rgba(0,0,0,0.08); border-radius: 4px; overflow: hidden;
}
.timer-bar-fill {
  height: 100%; background: var(--primary); width: 0%; transition: width 0.3s linear;
}
.timer-box.prep .timer-bar-fill { background: var(--accent); }
.timer-box.response .timer-bar-fill { background: var(--primary); }

.problem-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.5rem; box-shadow: var(--shadow);
}
.problem-image {
  width: 100%; max-width: 800px; margin: 1rem auto; display: block;
  border-radius: 8px; border: 1px solid var(--border);
}
.problem-image-large {
  width: 100%; max-height: 70vh; object-fit: contain; margin: 1rem auto; display: block;
  border-radius: 8px;
}
.problem-narration, .problem-question, .problem-intro {
  background: #f8fafc; padding: 1rem; border-left: 4px solid var(--primary);
  border-radius: 4px; margin: 0.75rem 0; font-size: 0.95rem;
}
.problem-question { border-left-color: var(--accent); font-weight: 500; }
.problem-keywords {
  background: #f0fdf4; padding: 1rem; border-left: 4px solid var(--success);
  border-radius: 4px; margin: 0.75rem 0; white-space: pre-wrap; font-size: 0.95rem;
}

.answer-area {
  margin-top: 1rem;
}
.answer-area textarea {
  width: 100%; min-height: 200px; padding: 1rem;
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 0.95rem; line-height: 1.6;
  resize: vertical;
}
.answer-area textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.sample-toggle {
  margin-top: 1rem; display: flex; gap: 0.5rem; align-items: center;
}
.sample-display {
  margin-top: 1rem; background: #f0f9ff; border: 1px solid #bae6fd;
  border-radius: 8px; padding: 1rem; white-space: pre-wrap;
  font-size: 0.95rem;
}
.sample-display.hidden { display: none; }
.sample-display .label {
  display: inline-block; background: var(--primary); color: white;
  padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; margin-right: 0.5rem;
}
.sample-display .structured-row {
  display: grid; grid-template-columns: 100px 1fr; gap: 1rem; padding: 0.5rem 0; border-bottom: 1px dashed #cbd5e1;
}
.sample-display .structured-row:last-child { border-bottom: none; }
.sample-display .structured-row .label { display: inline-block; font-weight: 600; color: var(--primary); align-self: start; background: #eff6ff; }

/* Sub-question (Part 4) */
.subq {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 1rem; margin-bottom: 0.75rem;
}
.subq-label {
  display: inline-block; background: var(--accent); color: white;
  padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; margin-bottom: 0.5rem;
}
.subq.active { border-color: var(--primary); border-width: 2px; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

/* Expressions (templates) */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.template-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; cursor: pointer; transition: all 0.15s;
}
.template-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.template-item img { width: 100%; height: auto; display: block; }
.template-item .label { padding: 0.5rem; background: #f8fafc; font-size: 0.8rem; text-align: center; color: var(--text-muted); }

.template-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 2rem;
}
.template-modal.open { display: flex; }
.template-modal img {
  max-width: 95%; max-height: 95%; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}
.template-modal .modal-close {
  position: absolute; top: 1rem; right: 1rem;
  background: white; border: none; width: 40px; height: 40px;
  border-radius: 50%; font-size: 1.5rem; cursor: pointer;
}

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-2 { gap: 0.5rem; }
.between { justify-content: space-between; }
.center { align-items: center; }

@media (max-width: 768px) {
  .header { padding: 1rem; flex-direction: column; gap: 0.75rem; }
  .container { padding: 1rem; }
}
