:root {
  --tf-accent: #2c3e6b;
  --tf-accent-hover: #212f52;
  --tf-accent-wash: #edf1f8;
  --tf-accent-soft: #c4d1e8;
  --mwg-surface: var(--tf-surface, #ffffff);
  --mwg-line: var(--tf-rule, #ddd8d0);
  --mwg-text: var(--tf-ink, #12100e);
  --mwg-muted: var(--tf-ink-soft, #5c574f);
}

.mwg-main {
  max-width: 46rem;
  margin-inline: auto;
  padding-inline: 1.5rem;
  width: 100%;
  box-sizing: border-box;
}

.mwg-wrap {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.mwg-panel {
  background: var(--mwg-surface);
  border: 1px solid var(--mwg-line);
  border-radius: 2px;
  padding: 1.25rem 1.5rem;
  box-shadow: none;
}

.mwg-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.mwg-presets-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--mwg-muted);
}

.mwg-preset-btn {
  background: var(--tf-accent-wash);
  color: var(--tf-accent);
  border: 1px solid var(--tf-accent-soft);
  border-radius: 2px;
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mwg-preset-btn:hover {
  background: var(--tf-accent);
  color: #ffffff;
}

.mwg-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.mwg-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.mwg-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.mwg-field label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--mwg-muted);
}

.mwg-field input,
.mwg-field select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--mwg-text);
  background: var(--mwg-surface);
  border: 1px solid var(--mwg-line);
  border-radius: 2px;
  outline: none;
  box-sizing: border-box;
}

.mwg-field input:focus,
.mwg-field select:focus {
  border-color: var(--tf-accent);
  outline: 1px solid var(--tf-accent);
}

.mwg-options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--mwg-line);
}

.mwg-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.875rem;
  color: var(--mwg-text);
  cursor: pointer;
}

.mwg-checkbox-label input {
  cursor: pointer;
}

.mwg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.mwg-btn-primary {
  background: var(--tf-accent);
  color: #ffffff;
  border: 1px solid var(--tf-accent);
  border-radius: 2px;
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.mwg-btn-primary:hover {
  background: var(--tf-accent-hover);
}

.mwg-btn-secondary {
  background: transparent;
  color: var(--mwg-text);
  border: 1px solid var(--mwg-line);
  border-radius: 2px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mwg-btn-secondary:hover {
  background: var(--tf-accent-wash);
  border-color: var(--tf-accent);
}

/* Results section */
.mwg-results {
  background: var(--mwg-surface);
  border: 1px solid var(--mwg-line);
  border-radius: 2px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.mwg-results-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--mwg-line);
}

.mwg-results-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--mwg-text);
}

.mwg-results-tools {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mwg-tool-btn {
  background: var(--tf-accent-wash);
  color: var(--tf-accent);
  border: 1px solid var(--tf-accent-soft);
  border-radius: 2px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.mwg-tool-btn:hover {
  background: var(--tf-accent);
  color: #ffffff;
}

/* Worksheet Sheet Rendering */
.mwg-sheet {
  background: var(--mwg-surface);
  color: var(--mwg-text);
  border: 1px solid var(--mwg-line);
  border-radius: 2px;
  padding: 1.75rem 1.5rem;
  box-shadow: none;
}

.mwg-sheet-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--mwg-line);
}

.mwg-sheet-title-group h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
  color: var(--mwg-text);
}

.mwg-sheet-subtitle {
  font-size: 0.8125rem;
  color: #5c574f;
}

.mwg-sheet-meta {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  min-width: 180px;
}

.mwg-meta-line {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.mwg-meta-line span {
  border-bottom: 1px solid #999;
  flex-grow: 1;
  min-width: 100px;
}

/* Problem Grid */
.mwg-problem-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem 1rem;
}

@media (max-width: 650px) {
  .mwg-problem-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.mwg-problem-card {
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 0.5rem;
  background: var(--mwg-surface);
  border: 1px solid var(--mwg-line);
  border-radius: 2px;
}

.mwg-problem-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: #5c574f;
  margin-bottom: 0.35rem;
}

/* Vertical arithmetic layout */
.mwg-vertical-calc {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: var(--tf-font-mono, monospace);
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  width: 5.5rem;
  margin-inline: auto;
}

.mwg-operand-top {
  padding-right: 0.25rem;
}

.mwg-operand-bottom {
  display: flex;
  justify-content: space-between;
  width: 100%;
  border-bottom: 2px solid var(--mwg-line);
  padding-bottom: 0.2rem;
}

.mwg-op-sym {
  font-weight: 700;
  padding-left: 0.25rem;
}

.mwg-answer-box {
  width: 100%;
  text-align: right;
  height: 1.5rem;
  margin-top: 0.2rem;
  font-weight: 700;
  color: #2c3e6b;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.25rem;
}

.mwg-answer-hidden {
  visibility: hidden;
}

/* Horizontal arithmetic layout */
.mwg-horizontal-calc {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-family: var(--tf-font-mono, monospace);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  padding: 0.5rem 0;
}

.mwg-horiz-answer {
  border-bottom: 2px solid var(--mwg-line);
  min-width: 2.2rem;
  text-align: center;
  font-weight: 700;
  color: #2c3e6b;
}

/* Print Styles */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .tf-chrome-header,
  .tf-intro,
  .mwg-panel,
  .mwg-results-bar,
  .tf-guide,
  .tf-faq-section,
  .tf-related,
  footer {
    display: none !important;
  }
  .mwg-main {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .mwg-results {
    border: none !important;
    padding: 0 !important;
  }
  .mwg-sheet {
    border: none !important;
    padding: 0 !important;
    page-break-inside: avoid;
  }
  .mwg-problem-card {
    background: #ffffff !important;
    border: 1px solid #ccc !important;
    break-inside: avoid;
  }
}

/* tf:dark-palette — generated by migrate_chrome.py */
/* Neutrals inherit the shared chrome tokens so all tools share one
   ground; brand hues are kept and lightened, never inverted. */
[data-theme="dark"] {
  --tf-accent: #6d86c3;
  --tf-accent-hover: var(--tf-ink);
  --tf-accent-wash: var(--tf-surface);
  --tf-accent-soft: #8aa3d1;
}
