:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --fg: #101828;
  --fg-subtle: #475467;
  --panel: #fff;
  --border: #d0d5dd;
  --accent: #166ac3;
  --careful-red: #94150c;
  --char-cards: #fdfffd;
  --char-main-border: #00c317;
  --char-card-shadow: rgba(122, 154, 255, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important; /* Allow hidden attribute to override layout styles */
}

body {
  margin: 0;
  font-family: 'Helvetica Neue', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--fg);
  background: radial-gradient(circle at top, #ffffff, #e4e7f1 60%, #d5d9e8);
  min-height: 100vh;
  padding: 24px clamp(16px, 4vw, 56px) 64px;
}

main.app {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  background: var(--panel);
  border-radius: 24px;
  padding: clamp(24px, 5vw, 48px);
  box-shadow: 0 0 80px rgba(16, 24, 40, 0.12);
}

.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-start;
}

.hero h1 {
  font-size: clamp(28px, 4vw, 40px);
  margin: 8px 0 12px;
}

.hero p {
  margin: 0;
  color: var(--fg-subtle);
}

.eyebrow {
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent);
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:active {
  transform: translateY(1px);
}

button:hover {
  box-shadow: 0 0 12px rgba(0, 122, 255, 0.2);
}

.icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.editor {
  margin-top: 32px;
}

.editor label {
  font-weight: 600;
  display: block;
  margin: 0;
}

.editor__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.editor__tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.editor__title {
  display: flex;
  gap: 16px;
  flex-direction: row;
}

.editor__canvas {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.editor__canvas:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.editor__canvas textarea {
  width: 100%;
  border: none;
  padding: 20px;
  font-size: 16px;
  min-height: 100px;
  resize: vertical;
  background: transparent;
  color: var(--fg);
}

.editor__canvas textarea:focus {
  outline: none;
}

.editor__action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 11px;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, #f9fbff, #eef2ff);
}


.editor__count {
  margin: 0;
  font-size: 14px;
  color: var(--fg-subtle);
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.editor__count-label {
  font-weight: 500;
}

.editor__count-number {
  font-size: 20px;
  font-weight: 700;
  color: var(--fg);
}

.editor__count-unit {
  font-size: 13px;
  color: var(--fg-subtle);
}

.editor__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid rgb(186, 186, 186);
  color: var(--fg);
  padding: 5px 14px;
  font-weight: 500;
  font-size: 14px;
  border-radius: 7px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.editor__action--accent {
  color: var(--accent);
}

.editor__action--clear {
  color: #b91c1c;
  border-color: rgba(239, 68, 68, 0.35);
  background: linear-gradient(135deg, #fff8f8, #ffe4e1);
}

.editor__action--clear:hover,
.editor__action--clear:focus-visible {
  color: #991b1b;
  border-color: rgba(185, 28, 28, 0.55);
}

.editor__action--clear:disabled {
  color: #9ca3af;
  border-color: rgba(148, 163, 184, 0.65);
  background: #f8fafc;
}

.editor__action-label {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.editor__action.is-animating .editor__action-label {
  opacity: 0;
  transform: translateY(45%);
}

.editor__action--paste {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ffffff, #eef4ff);
  isolation: isolate;
}

.editor__action--paste::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(71, 111, 255, 0.2), transparent 75%);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 0;
}

.editor__action--paste::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.4);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 2;
  pointer-events: none;
}

.editor__action--paste.is-success {
  color: #0b7149;
  border-color: rgba(20, 104, 71, 0.35);
}

.editor__action--paste.is-warning {
  color: #7c5600;
  border-color: rgba(239, 193, 92, 0.4);
  background: linear-gradient(130deg, #fff8e5, #ffe5b8);
  box-shadow: 0 0 26px rgba(239, 193, 92, 0.35);
}

.editor__action--paste.is-error {
  color: #9b1c0d;
  border-color: rgba(231, 113, 102, 0.65);
  background: linear-gradient(130deg, #ffecec, #ffd2ca);
  box-shadow: 0 0 30px rgba(231, 113, 102, 0.35);
  animation: copyIconShake 0.35s ease;
}

.editor__action--paste.is-warning::before {
  background: radial-gradient(circle at center, rgba(255, 198, 111, 0.35), transparent 70%);
  opacity: 1;
  transform: scale(1.05);
}

.editor__action--paste.is-error::before {
  background: radial-gradient(circle at center, rgba(255, 167, 142, 0.4), transparent 70%);
  opacity: 1;
  transform: scale(1.05);
}

.editor__action--paste.is-success::after {
  width: 13px;
  height: 8px;
  border-left: 3px solid #0b7149;
  border-bottom: 3px solid #0b7149;
  border-top: 1px solid transparent;
  border-right: 1px solid transparent;
  border-bottom-left-radius: 3px;
  opacity: 1;
  transform: translate(-50%, -70%) rotate(-45deg) scale(1);
  box-shadow: 0 1px 0 rgba(11, 113, 73, 0.35);
}

.editor__action--paste.is-warning::after {
  width: 10px;
  height: 22px;
  opacity: 1;
  transform: translate(-50%, -55%) scale(1);
  background:
    linear-gradient(#7c5600 0 14px, transparent 14px),
    radial-gradient(circle, #7c5600 36%, transparent 37%);
  background-size: 3px 13px, 8px 4px;
  background-position: center 0, center calc(100% - 2px);
  background-repeat: no-repeat;
  filter: drop-shadow(0 1px 0 rgba(124, 86, 0, 0.4));
}

.editor__action--paste.is-error::after {
  width: 18px;
  height: 18px;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  background:
    linear-gradient(45deg, transparent calc(50% - 1.6px), #9b1c0d calc(50% - 1.6px), #9b1c0d calc(50% + 1.6px), transparent calc(50% + 1.6px)),
    linear-gradient(-45deg, transparent calc(50% - 1.6px), #9b1c0d calc(50% - 1.6px), #9b1c0d calc(50% + 1.6px), transparent calc(50% + 1.6px));
  border-radius: 2px;
  filter: drop-shadow(0 1px 0 rgba(155, 28, 13, 0.35));
}

.editor__action--icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.editor__action--icon .icon {
  width: 18px;
  height: 18px;
}

.editor__action--history {
  background-color: #fff;
}

.editor__action--history .icon {
  width: 100%;
  height: 100%;
}

.icon--redo {
  transform: scaleX(-1);
}

.editor__action--icon::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 7px;
  border-left: 3px solid transparent;
  border-bottom: 3px solid transparent;
  border-right: 1px solid transparent;
  border-top: 1px solid transparent;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg) scale(0.5);
  transform-origin: center;
  opacity: 0;
  transition:
    border-color 0.25s ease,
    opacity 0.25s ease,
    transform 0.25s ease;
}

.editor__action--icon.is-copied {
  background: white;
  border-color: #2fb57d;
}

.editor__action--icon.is-copied .icon {
  opacity: 0;
  transform: scale(0.6);
}

.editor__action--icon.is-copied::before {
  border-left-color: #1b8c5f;
  border-bottom-color: #1b8c5f;
  opacity: 1;
  transform: translate(-50%, -70%) rotate(-45deg) scale(1);
}

.editor__action--icon.is-error {
  animation: copyIconShake 0.35s ease;
  background: #ffecec;
  border-color: #ffb4a8;
  color: #94150c;
}

.editor__action:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.editor__action--history:disabled {
  opacity: 0.45;
  box-shadow: none;
}

.settings {
  margin-top: 32px;
  padding: 20px;
  border-radius: 18px;
  border: 1px solid var(--char-main-border);
  background: #fafff8;
}

.settings__header h2 {
  margin: 0;
  font-size: 18px;
}

.settings__header p {
  margin: 6px 0 0;
  color: var(--fg-subtle);
  font-size: 14px;
}

.count-options {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.count-options__toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.count-options__toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  color: var(--fg);
}

.count-options__toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.count-options__inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.count-options__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--fg);
}

.count-options__field select {
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--fg) 50%),
    linear-gradient(135deg, var(--fg) 50%, transparent 50%),
    linear-gradient(to bottom, transparent calc(50% - 9px), var(--border) calc(50% - 9px), var(--border) calc(50% + 9px), transparent calc(50% + 9px));
 background-position:
    calc(100% - 20px) calc(50% - 1px),
    calc(100% - 14px) calc(50% - 1px),
    calc(100% - 32px) 50%;
  background-size: 7px 7px, 7px 7px, 2px 22px;
  background-repeat: no-repeat;
}

.count-options__hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--fg-subtle);
}

.exclusion {
  margin-top: 24px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff9f8;
}

.exclusion__header h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.exclusion__header p {
  margin: 0;
  color: var(--fg-subtle);
  font-size: 14px;
}

.exclusion__controls {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

.exclusion__controls .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.link-gray {
  color: var(--fg-subtle);
  text-decoration: none; 
  border-bottom: 1px dotted rgba(0, 0, 0, 0.28);
  text-underline-offset: 3px;
  transition: color 0.15s ease, border-bottom-color 0.15s ease;
}

a.link-gray:hover,
a.link-gray:focus {
  color: var(--fg); 
  border-bottom-color: var(--fg);
  text-decoration: none;
}

a.link-gray:focus-visible {
  outline: 2px solid rgba(0, 122, 255, 0.14);
  outline-offset: 3px;
  border-bottom-color: var(--accent);
}

.exclusion__controls input,
.exclusion__controls select {
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
  background: #fff;
  color: var(--fg);
}

.exclusion__controls select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--fg) 50%),
    linear-gradient(135deg, var(--fg) 50%, transparent 50%),
    linear-gradient(to bottom, transparent calc(50% - 9px), var(--border) calc(50% - 9px), var(--border) calc(50% + 9px), transparent calc(50% + 9px));
  background-position:
    calc(100% - 20px) calc(50% - 1px),
    calc(100% - 14px) calc(50% - 1px),
    calc(100% - 32px) 50%;
  background-size: 7px 7px, 7px 7px, 2px 22px;
  background-repeat: no-repeat;
}

.exclusion__controls button {
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.exclusion__hint {
  margin: 12px 0 0;
  color: var(--fg-subtle);
  font-size: 13px;
}

.exclusion__list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exclusion__item {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-radius: 12px;
  background: #f0f4ff;
  border: 1px dashed #cfd5ff;
}

.exclusion__item--live {
  background: #fff7ed;
  border-style: solid;
}

.exclusion__summary {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.exclusion__value {
  font-weight: 600;
  word-break: break-all;
}

.exclusion__item button {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 6px 12px;
  border-radius: 999px;
}

.exclusion__item button:hover {
  box-shadow: none;
}

.exclusion__live-note {
  font-size: 12px;
  color: var(--fg-subtle);
  margin-top: 4px;
}

.exclusion__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.exclusion__empty {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  color: var(--fg-subtle);
  font-size: 14px;
}

.stats {
  margin-top: 32px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.stats article {
  position: relative;
  background: #f8f9ff;
  border-radius: 9px;
  border: 1px solid #e9ebff;
  padding: 18px 18px 22px;
  cursor: pointer;
}

.stats__card--char-main {
  background: linear-gradient(135deg, #fbfff9, var(--char-cards)) !important;
  border-color: var(--char-main-border) !important;
}



.stats__card--char-main .label {
  color: #1e3a8a;
}

.stats__card--char-main .value__number {
  color: #0f1f4b;
}

.stats__label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stats .label {
  margin: 0;
  color: var(--fg-subtle);
  font-size: 14px;
}

.stats .value {
  margin: 8px 0 0;
  font-size: 30px;
  font-weight: 600;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  line-height: 1;
}

.value__number {
  line-height: 1;
}

.value__unit {
  font-size: 0.5em;
  color: var(--fg-subtle);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.history {
  margin-top: 32px;
  padding: 20px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #ffffff, #f5f8ff);
}

.history__header h2 {
  margin: 0;
  font-size: 18px;
}

.history__header p {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--fg-subtle);
}

.history__list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 8px; /* Keep scrollbar from covering entries */
  scrollbar-gutter: stable;
}

.history__list::-webkit-scrollbar {
  width: 8px;
}

.history__list::-webkit-scrollbar-track {
  background: transparent;
}

.history__list::-webkit-scrollbar-thumb {
  background: rgba(16, 24, 40, 0.15);
  border-radius: 999px;
}

.history__empty {
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px dashed var(--border);
  color: var(--fg-subtle);
  font-size: 14px;
  background: #fff;
}

.history__entry {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  border-radius: 5px;
  border: 1px solid #dfe4fb;
  background: #fff;
  display: flex;
  align-items: center;
  padding: 4px 16px;
  gap: 12px;
  font-size: 14px;
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  text-align: left;
}

.history__entry:hover {
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.08);
}

.history__entry:focus-visible {
  outline: 2px solid rgba(22, 106, 195, 0.25);
  outline-offset: 2px;
}

.history__entry-badge {
  flex-shrink: 0;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef2ff;
  color: var(--accent);
}

.history__entry-text {
  flex: 1;
  line-height: 1;
  overflow: hidden;
}

.history__entry--delete {
  background: #fff5f5;
  border-color: #ffd5d2;
}

.history__entry--delete .history__entry-badge {
  background: rgba(231, 113, 102, 0.14);
  color: var(--careful-red);
}

.history__entry--delete .history__entry-text {
  color: var(--careful-red);
}

.history__entry.is-copied {
  border-color: #1b8c5f;
  box-shadow: 0 0 0 2px rgba(47, 181, 125, 0.18);
}

.history__entry.is-error {
  border-color: #ffb4a8;
  box-shadow: 0 0 0 2px rgba(255, 180, 168, 0.3);
}

.history__entry-icon {
  margin-left: auto;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  color: var(--fg);
  overflow: hidden;
  transition:
    background 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease;
}

.history__entry-icon .icon {
  width: 18px;
  height: 18px;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

.history__entry-icon::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 10px;
  border-left: 3px solid transparent;
  border-bottom: 3px solid transparent;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg) scale(0.5);
  opacity: 0;
  transition:
    border-color 0.25s ease,
    opacity 0.25s ease,
    transform 0.25s ease;
}


.history__entry.is-copied .history__entry-icon .icon {
  opacity: 0;
  transform: scale(0.6);
}

.history__entry.is-copied .history__entry-icon::before {
  border-left-color: #1b8c5f;
  border-bottom-color: #1b8c5f;
  opacity: 1;
  transform: translate(-50%, -70%) rotate(-45deg) scale(1);
}

.history__entry.is-error .history__entry-icon {
  background: #ffecec;
  color: #94150c;
  animation: copyIconShake 0.35s ease;
}

.stats__copy-button {
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  overflow: hidden;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  position: absolute;
  right: 14px;
  bottom: 9px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 12px;
  background: transparent;
  border-radius: 50%;
}


.stats__copy-button .icon {
  width: 18px;
  height: 18px;
}

.stats__copy-button::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 10px;
  border-left: 3px solid transparent;
  border-bottom: 3px solid transparent;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg) scale(0.5);
  transform-origin: center;
  opacity: 0;
  transition:
    border-color 0.25s ease,
    opacity 0.25s ease,
    transform 0.25s ease;
}
.stats__copy-button:hover {
  box-shadow: none;
}


.stats__copy-button.is-copied .icon {
  opacity: 0;
  transform: scale(0.6);
}

.stats__copy-button.is-copied::before {
  border-left-color: #1b8c5f;
  border-bottom-color: #1b8c5f;
  opacity: 1;
  transform: translate(-50%, -70%) rotate(-45deg) scale(1);
}

.stats__copy-button.is-error {
  animation: copyIconShake 0.35s ease;
  background: #ffecec;
  border-color: #ffb4a8;
  color: #9b1c0d;
}


@keyframes copyIconShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-2px);
  }
  50% {
    transform: translateX(2px);
  }
  75% {
    transform: translateX(-2px);
  }
}

.highlight {
  margin-top: 32px;
  padding: 24px;
  border-radius: 20px;
}

.highlight h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.highlight p {
  margin: 0;
  color: var(--fg-subtle);
  line-height: 1.7;
}

.footer {
  max-width: 960px;
  margin: 24px auto;
  color: #4b5563;
  font-size: 14px;
  text-align: center;
}

@media (max-width: 640px) {
  body {
    padding: 16px;
  }
  .editor__tools {
    gap: 5px;
  }
  .editor__action--paste {
    font-size: 12px;
  }
  .editor__action--clear {
    font-size: 12px;
  }
}
