:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --border: #e3e6eb;
  --accent: #3b6ef5;
  --accent-hover: #2f5be0;
  --error: #d64545;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

:root[data-theme="dark"] {
  --bg: #0e1117;
  --card-bg: #171b22;
  --text: #e6e9ef;
  --text-muted: #9aa4b2;
  --border: #262c36;
  --accent: #5b82f7;
  --accent-hover: #6f92f8;
  --error: #f27878;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

.app__header {
  position: relative;
  text-align: center;
  margin-bottom: 1.75rem;
}

.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s, border-color 0.15s;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.app__title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  letter-spacing: -0.02em;
}

.app__subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card__title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

/* Clock */
.clock {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border: none;
  color: #fff;
}

.clock__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.clock__row--sub {
  margin-top: 0.35rem;
}

.clock__label {
  font-size: 0.85rem;
  opacity: 0.85;
}

.clock__value-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.clock__value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.clock__human {
  font-size: 0.85rem;
  opacity: 0.9;
}

/* Fields */
.field {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.field--controls {
  gap: 0.75rem;
  flex-wrap: wrap;
}

.control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control--grow {
  flex: 1;
  min-width: 180px;
}

.control__label {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.select--grow {
  flex: 1;
  min-width: 0;
}

.input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--accent);
}

.select {
  padding: 0.65rem 0.6rem;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

.detected {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  margin: 0 0 0.75rem;
  min-height: 1.1em;
}

.detected:empty {
  margin: 0;
  min-height: 0;
}

/* Buttons */
.btn {
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn--copy {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
  opacity: 0.7;
}

.btn--copy:hover {
  background: rgba(127, 127, 127, 0.15);
  opacity: 1;
}

/* Results */
.results {
  display: grid;
  gap: 0.6rem;
}

.result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
}

.result__label {
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.result__value-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.result__value {
  font-size: 0.95rem;
  text-align: right;
  word-break: break-all;
}

.mono {
  font-family: var(--mono);
}

.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.input--num {
  max-width: 110px;
}

/* Textarea */
.textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  resize: vertical;
  margin-bottom: 0.75rem;
}

.textarea:focus {
  border-color: var(--accent);
}

/* Batch actions + table */
.batch-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0.25rem 0 0.75rem;
}

.batch-actions__btns {
  display: flex;
  gap: 0.5rem;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.table th,
.table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  color: var(--text-muted);
  font-weight: 600;
}

.table__row--bad td {
  color: var(--error);
}

/* Code snippet */
.snippet {
  position: relative;
}

.snippet__copy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
}

.snippet__code {
  margin: 0;
  padding: 0.9rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre;
}

/* Diff tags */
.diff-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Custom pattern result */
.result--custom {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.result__custom-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.input--pattern {
  flex: 1;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.result--custom .result__value-wrap {
  justify-content: space-between;
  width: 100%;
}

/* Card head with action */
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card__head .card__title {
  margin: 0;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn--ghost:hover {
  background: var(--bg);
  color: var(--text);
}

/* History */
.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.history__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
}

.history__load {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  text-align: left;
  word-break: break-all;
}

.history__load:hover {
  text-decoration: underline;
}

.history__iso {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Error */
.error {
  color: var(--error);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
  min-height: 1.2em;
}

.error:empty {
  margin: 0;
  min-height: 0;
}

/* Footer */
.app__footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 1.5rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

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

@media (max-width: 480px) {
  .result {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  .result__value-wrap {
    width: 100%;
    justify-content: space-between;
  }
  .result__value {
    text-align: left;
  }
}
