/* Reset & Base */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.6;
  color: #222;
  background-color: #f5f7fa;
  padding: 1rem;
  transition: background-color 0.3s, color 0.3s;
}

.light-theme {
  --bg: #f5f7fa;
  --fg: #222;
  --card-bg: #fff;
  --shadow: rgba(0, 0, 0, 0.1);
  --accent: #0077cc;
  --hover: #e6f2ff;
}

.dark-theme {
  --bg: #121212;
  --fg: #eee;
  --card-bg: #1e1e1e;
  --shadow: rgba(255, 255, 255, 0.05);
  --accent: #40a9ff;
  --hover: #2a2a2a;
  color: #eee;
  background-color: #121212;
}

body {
  background-color: var(--bg);
  color: var(--fg);
}

/* Layout */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

/* Typography */
h1 {
  font-size: 1.8rem;
  margin: 0 0 0.5rem;
  text-align: center;
}

.subtitle {
  text-align: center;
  font-style: italic;
  margin-bottom: 1.5rem;
  color: #555;
}

.dark-theme .subtitle {
  color: #aaa;
}

h2, dt {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

dd {
  margin: 0 0 1rem;
  padding-left: 1rem;
}

/* Card */
.container > * {
  background: var(--card-bg);
  padding: 1.2rem;
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--shadow);
  margin-bottom: 1rem;
}

/* Form */
label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
}

textarea {
  width: 100%;
  padding: 0.8rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
  resize: vertical;
  background: var(--card-bg);
  color: var(--fg);
  transition: border 0.2s;
}

.dark-theme textarea {
  border-color: #444;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.25);
}

#char-count, #counter {
  font-size: 0.9rem;
  color: #666;
  margin-top: 0.5rem;
}

.dark-theme #char-count, .dark-theme #counter {
  color: #aaa;
}

/* Fieldset */
fieldset {
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0;
}

.dark-theme fieldset {
  border-color: #444;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

label[for] {
  cursor: pointer;
}

input[type="radio"] {
  margin-right: 0.3rem;
}

/* Buttons */
.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1rem;
  justify-content: center;
}

button {
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

button:hover {
  background: #005fa3;
}

button:active {
  transform: scale(0.98);
}

button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background: #aaa;
}

/* Preview */
.preview {
  min-height: 60px;
  border: 1px dashed #ccc;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  font-size: 1rem;
  word-wrap: break-word;
  background: var(--card-bg);
  color: var(--fg);
}

.blank {
  color: transparent;
  user-select: none;
}

.revealed {
  color: var(--fg);
  background: #eef;
}

.dark-theme .revealed {
  background: #2a2a40;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Theme Toggle */
footer {
  text-align: center;
  font-size: 0.9rem;
  color: #777;
}

.dark-theme footer {
  color: #aaa;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 0.5rem;
  }

  .button-group {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    text-align: center;
  }
}