* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f4f5f7;
  color: #222;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

h1 {
  margin: 0 0 6px;
  font-size: 30px;
}

.subtitle {
  margin: 0 0 24px;
  color: #666;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.story-hint {
  margin: 0 0 18px;
  color: #666;
  font-size: 15px;
  line-height: 1.5;
}

.story-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}

.story-title {
  font-size: 25px;
  font-weight: 700;
}

.level {
  background: #eee;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  white-space: nowrap;
}

.story-content {
  font-size: 18px;
  line-height: 1.75;
}

.story-paragraph {
  margin: 0 0 18px;
}

.story-word {
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 2px;
  transition: background 0.15s;
}

.story-word:hover {
  background: #eee;
}

.story-word.learning {
  background: #fff1a8;
}

.news-source {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid #eee;
  font-size: 14px;
  color: #666;
  line-height: 1.6;
}

.news-source a {
  color: #1a5fb4;
  word-break: break-all;
}

.story-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 24px;
}

button {
  border: none;
  border-radius: 8px;
  padding: 10px 15px;
  cursor: pointer;
  font-size: 15px;
  background: #222;
  color: white;
}

button:hover {
  opacity: 0.9;
}

button.secondary {
  background: #e8e8e8;
  color: #222;
}

button.danger {
  background: #b42318;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 7px;
  display: none;
  font-size: 14px;
}

.status.error {
  display: block;
  background: #fdecec;
  color: #9c1c1c;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 7px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  background: white;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

select {
  cursor: pointer;
}

.field-help {
  margin-top: 6px;
  color: #777;
  font-size: 13px;
  line-height: 1.4;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.radio-group {
  display: flex;
  gap: 24px;
  align-items: center;
  margin-top: 8px;
}

.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 15px;
  user-select: none;
}

.radio-label input[type="radio"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.vocabulary-list {
  margin-top: 12px;
}

.vocabulary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.vocabulary-item:last-child {
  border-bottom: none;
}

.vocabulary-word {
  font-weight: 600;
}

.vocabulary-meaning {
  color: #666;
  margin-left: 6px;
}

.vocabulary-delete {
  padding: 6px 9px;
  font-size: 13px;
}

.empty {
  color: #777;
  margin: 0;
}

.vocabulary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 15px;
}

.vocabulary-header h2 {
  margin: 0;
}

.vocabulary-header button {
  flex-shrink: 0;
}

.vocabulary-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.word-order {
  width: 150px;
}

.word-order select {
  padding: 8px 10px;
  font-size: 14px;
}

.language-badge {
  display: inline-block;
  margin-bottom: 8px;
  color: #666;
  font-size: 13px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 24px;
}

.page-header .subtitle {
  margin-bottom: 0;
}

.ui-language {
  width: 220px;
  flex-shrink: 0;
}

.ui-language .field-label {
  font-weight: 400;
  color: #666;
  font-size: 13px;
}

/* The word popup: a gloss and one decision, opened over the story by a click on
   a word. The backdrop covers the page, so the story behind the choice cannot
   be clicked while the popup is open. */
.popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
}

/* The attribute has to beat the flex display above, or a closed popup would
   still sit over the page. */
.popup-overlay[hidden] {
  display: none;
}

.popup {
  width: 100%;
  max-width: 360px;
  background: white;
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.popup-word {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.popup-meaning {
  min-height: 26px;
  margin-top: 8px;
  font-size: 17px;
  line-height: 1.5;
  color: #555;
  overflow-wrap: anywhere;
}

.popup-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.popup-actions button {
  flex: 1;
}

@media (max-width: 650px) {
  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .ui-language {
    width: 100%;
  }

  .story-header {
    flex-direction: column;
  }

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