:root {
  --alg-plum: #200e31;
  --alg-purple: #5e3489;
  --alg-lilac: #d2b6f2;
  --alg-coral: #ff806b;
  --alg-ink: #251834;
  --alg-muted: #64566e;
  --alg-line: #e4dbea;
  --alg-paper: #fff;
  --alg-background: #f7f4fa;
  --alg-radius: 16px;
  --alg-gutter: clamp(12px, 3.2vw, 40px);
}

.alg-analysis, .alg-auth, .alg-admin {
  margin: 0;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--alg-background);
  color: var(--alg-ink);
  font: 400 1rem/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.alg-header *, .alg-analysis *, .alg-admin * { box-sizing: border-box; }
.alg-header a, .alg-analysis a, .alg-admin a { color: var(--alg-purple); }
:is(.alg-header, .alg-analysis, .alg-admin) :focus-visible {
  outline: 3px solid #8956bf;
  outline-offset: 3px;
}

header.alg-header {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0;
  background: var(--alg-plum);
  color: #fff;
  text-align: left;
  border-bottom: 3px solid var(--alg-coral);
}

.alg-header-inner {
  position: relative;
  width: 100%;
  max-width: 1440px;
  margin-inline: auto;
  padding: 12px var(--alg-gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
  flex-wrap: wrap;
}

.alg-brand { display: flex; align-items: center; gap: 12px; min-width: 0; text-decoration: none; }
.alg-brand img { display: block; flex: 0 0 auto; width: 52px; height: 52px; border-radius: 12px; }
.alg-header .alg-brand strong { display: block; color: #fff; font-size: 1.05rem; font-weight: 750; }
.alg-header .alg-brand small { display: block; color: var(--alg-lilac); font-size: .82rem; }
.alg-nav { display: flex; gap: 5px; flex-wrap: wrap; }
.alg-header .alg-menu-toggle { display: none; }
.alg-header .alg-nav a { color: #f0e6fc; text-decoration: none; padding: 9px 12px; min-height: 44px; border-radius: 9px; font-size: .9rem; }
.alg-header .alg-nav a:hover, .alg-header .alg-nav a[aria-current] { background: #422957; color: #fff; }
.alg-language:not([hidden]) { display: flex; align-items: center; gap: 8px; padding: 0 8px; color: #f0e6fc; font-size: .9rem; }
.alg-language select { min-height: 44px; max-width: 100%; padding: 4px 8px; color: #fff; background: #422957; border: 1px solid #ffffff55; border-radius: 9px; font: inherit; }
.alg-auth .main { margin-top: 24px; }
.alg-auth .container { width: min(660px, calc(100% - 2 * var(--alg-gutter))); }
.alg-auth .signup-content { padding: clamp(20px, 5vw, 50px); }
.alg-auth .form-submit { background: var(--alg-purple); }

.alg-analysis #content {
  position: static;
  width: 100%;
  max-width: 1440px;
  margin-inline: auto;
  padding: clamp(16px, 4vw, 40px) var(--alg-gutter);
  overflow: visible;
  min-height: 70vh;
}

.alg-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
  padding: clamp(20px, 4vw, 42px);
  margin-bottom: 20px;
  border-radius: 22px;
  background: linear-gradient(115deg, var(--alg-plum), #462650);
  color: #fff;
}
.alg-eyebrow { color: var(--alg-lilac); font-size: .78rem; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
.alg-hero h1 { margin-block: 4px 8px; font-size: clamp(1.65rem, 4vw, 3rem); line-height: 1.12; letter-spacing: -.04em; }
.alg-hero p:last-child { color: #eadcf5; max-width: 49ch; }
.alg-latest { min-width: 164px; padding: 12px 18px; border: 1px solid #ffffff40; border-radius: 14px; background: #ffffff0c; }
.alg-latest span, .alg-latest time { display: block; color: #eadcf5; font-size: .82rem; }
.alg-latest strong { display: block; color: var(--alg-coral); font-size: 1.7rem; letter-spacing: .1em; font-variant-numeric: tabular-nums; }

.alg-dashboard { display: grid; grid-template-columns: minmax(220px, 272px) minmax(0, 1fr); gap: 20px; align-items: start; }
.alg-workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.alg-card {
  min-width: 0;
  padding: clamp(14px, 2.6vw, 24px);
  border: 1px solid var(--alg-line);
  border-radius: var(--alg-radius);
  background: var(--alg-paper);
  box-shadow: 0 3px 12px #200e3107;
}
.alg-card > h2, .alg-card > h3 { margin-bottom: 12px; font-size: 1.12rem; font-weight: 750; }
.alg-filter-group { margin-bottom: 14px; }
.alg-filter-group > legend, .alg-field-label { display: block; margin-bottom: 6px; font-weight: 650; }
.alg-filter-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.alg-filter-choices label { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 5px 6px; border: 1px solid var(--alg-line); border-radius: 8px; font-size: .83rem; }
.alg-filter-choices label:has(input:checked) { border-color: #a279c8; background: #f4ebfc; }
.alg-filter-choices input { flex: 0 0 auto; }
.alg-analysis .main-filter form > label:has(input[type=checkbox]) { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; margin-right: 8px; }
.alg-analysis input, .alg-analysis select { font: inherit; max-width: 100%; margin: 0; }
.alg-analysis :is(input[type=radio], input[type=checkbox]) { accent-color: var(--alg-purple); }
.alg-analysis :is(input[type=text], input[type=number], input[type=date], select) {
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid #cdbed9;
  border-radius: 8px;
  background: #fff;
  color: var(--alg-ink);
}
.alg-analysis .main-filter :is(input[type=text], input[type=date], select) { width: 100%; min-width: 0; }
.alg-analysis .main-filter select[multiple] { min-height: 84px; }
.alg-analysis .main-filter :is(#ip3, #vip4) input { margin-bottom: 8px; }
.alg-filter-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.alg-filter-actions #fapply { flex: 1 1 auto; }

.alg-weekdays { min-width: 0; margin: 10px 0 16px; }
.alg-weekdays legend { font-weight: 700; }
.alg-weekdays p { margin: 4px 0 8px; color: var(--alg-muted); font-size: .83rem; }
.alg-weekday-options { display: flex; flex-wrap: wrap; gap: 6px; }
.alg-analysis .alg-weekday-options .alg-weekday-option { position: relative; display: block; margin: 0; font-size: .88rem; }
.alg-weekday-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.alg-weekday-option span { display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 4px 8px; border: 1px solid #cdbed9; border-radius: 999px; color: #472267; font-weight: 650; cursor: pointer; }
.alg-weekday-option input:checked + span { background: var(--alg-purple); border-color: var(--alg-purple); color: #fff; }
.alg-weekday-option input:focus-visible + span { outline: 3px solid #8956bf; outline-offset: 2px; }
.alg-tools-link { display: inline-flex; align-items: center; min-height: 44px; font-weight: 650; }
.alg-analysis .main-filter summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 9px;
  background: #f2e8fa;
  color: #45275f;
  font-weight: 750;
  list-style: none;
  cursor: pointer;
}
.alg-analysis .main-filter summary::-webkit-details-marker { display: none; }
.alg-analysis .main-filter summary::after {
  content: '';
  width: 8px;
  height: 8px;
  margin: 0 3px 4px 0;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}
.alg-analysis .main-filter details[open] > summary { margin-bottom: 12px; }
.alg-analysis .main-filter details[open] > summary::after { margin-bottom: 0; transform: rotate(225deg); }
.alg-filter-note { margin-bottom: 12px; color: var(--alg-muted); }

.alg-analysis :is(button, input[type=submit]), .alg-admin button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--alg-purple);
  color: #fff;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.alg-analysis :is(button, input[type=submit]):hover, .alg-admin button:hover { background: #4c2971; }
.alg-analysis #freset { border-color: var(--alg-line); background: #f4ecfa; color: var(--alg-purple); }
.alg-analysis #freset:hover { background: #e8d8f5; }
.alg-tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); gap: 8px; }
.alg-analysis .alg-tool-grid button { margin: 0; border-color: #dfccec; background: #f4ecfa; color: #472267; font-size: .9rem; }
.alg-analysis .alg-tool-grid button:is(:hover, [aria-expanded=true]) { background: var(--alg-purple); color: #fff; }
.alg-analysis .alg-tool > form { position: static; padding: 0; border: 0; background: transparent; }
.alg-analysis .alg-tool label { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 7px; margin: 4px 10px 8px 0; font-size: .94rem; }
.alg-analysis .alg-tool :is(input[type=text], input[type=number]) { width: min(100%, 150px); }
.alg-analysis .alg-tool button, .alg-analysis #combination button { margin: 4px 4px 4px 0; }
.alg-analysis .alg-tool .marginLeft20 { margin-left: 0; }

.alg-analysis .alg-report { overflow-x: auto; }
.alg-analysis :is(#summary, #reports):empty { display: none; }
.alg-analysis :is(#output, #reports, #summary, .alg-table-scroll) { max-width: 100%; overflow-wrap: anywhere; }
.alg-analysis .alg-table-scroll { overflow-x: auto; }
.alg-analysis .alg-table-scroll:empty { display: none; }
.alg-analysis :is(#output, #reports, #summary) .content { padding-inline: 0; overflow-x: auto; }
.alg-analysis .collapsible { display: block; width: 100%; margin-top: 6px; text-align: left; background: #f2e8fa; color: #45275f; }
.alg-analysis .collapsible:is(:hover, .active) { background: #e8d8f5; }
.alg-analysis .collapsible::after { color: currentColor; }
.alg-analysis :is(.content, .alg-table-scroll) table { font-size: .85rem; }
.alg-analysis :is(.content, .alg-table-scroll) :is(td, th) { padding: 7px 9px; min-width: 54px; }
.alg-analysis th { background: #eee4f6; }
.alg-analysis td { overflow-wrap: normal; }
.alg-analysis .recentTable td:first-child { white-space: nowrap; }
.alg-analysis .alg-results { min-width: 0; }
.alg-analysis .alg-results .content table { table-layout: fixed; }
.alg-analysis .alg-results .content :is(th, td) { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
.alg-analysis .alg-results .collapsible.active + .content { max-height: none !important; }
.alg-guess-summary { margin-top: 16px; }
.alg-guess-summary h3 { margin: 12px 0 6px; font-size: .95rem; }
.alg-guess-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 8px; }
.alg-guess-card { min-width: 0; padding: 8px 10px; border: 1px solid var(--alg-line); border-radius: 9px; background: var(--alg-background); }
.alg-guess-card h4 { color: var(--alg-purple); font-size: .85rem; }
.alg-guess-card :is(ol, .alg-combo-list) { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 0; list-style: none; }
.alg-guess-card li { display: grid; min-width: 36px; padding: 2px 5px; border-radius: 5px; background: var(--alg-paper); text-align: center; }
.alg-guess-card small, .alg-guess-card p { color: var(--alg-muted); font-size: .72rem; }
.alg-guess-card .alg-combo-list li { padding: 4px 8px; font-weight: 700; font-variant-numeric: tabular-nums; }
.alg-combo-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.alg-analysis .alg-combo-copy { display: grid; place-items: center; flex: 0 0 44px; padding: 0; }
.alg-guess-note { margin-bottom: 8px; color: var(--alg-muted); font-size: .83rem; }
.alg-guess-card li.alg-guess-match { background: #ffe4de; box-shadow: inset 0 0 0 1px #b85242; }
.alg-detailed-analysis { margin-top: 16px; }
.alg-detailed-analysis > summary {
  display: list-item;
  width: fit-content;
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 9px;
  background: var(--alg-purple);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  line-height: 20px;
}
.alg-draw-history form { margin-bottom: 12px; }
.alg-draw-history select { width: min(100%, 260px); }
.alg-draw-range:not([hidden]) { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-top: 12px; }
.alg-draw-range label { display: grid; gap: 4px; min-width: 0; }
.alg-draw-history table { table-layout: fixed; margin-top: 8px; }
.alg-draw-history :is(th, td) { padding: 8px 4px; font-size: clamp(.75rem, 2.8vw, .94rem); overflow-wrap: anywhere; }
.alg-draw-history td:last-child { font-variant-numeric: tabular-nums; font-weight: 700; }

@media (max-width: 600px), (min-width: 901px) and (max-width: 1000px) {
  .alg-analysis .alg-results .alg-stacked-results,
  .alg-analysis .alg-results .alg-stacked-results tbody { display: block; }
  .alg-analysis .alg-results .alg-stacked-results .alg-result-heading {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 8px 0;
  }
  .alg-analysis .alg-results .alg-stacked-results th {
    width: auto !important;
    padding: 5px 7px;
    border-radius: 5px;
    font-size: .75rem;
  }
  .alg-analysis .alg-results .alg-stacked-results .alg-result-data {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
    padding: 9px;
    border: 1px solid var(--alg-line);
    border-radius: 8px;
    background: var(--alg-background);
  }
  .alg-analysis .alg-results .alg-stacked-results td { padding: 0; border: 0; font-variant-numeric: tabular-nums; }
  .alg-analysis .alg-results .alg-stacked-results td:first-child { grid-column: 1 / -1; width: auto; font-weight: 700; }
  .alg-analysis .alg-results .alg-stacked-results td::before {
    display: block;
    color: var(--alg-muted);
    content: attr(data-column);
    font-size: .72rem;
    font-weight: 650;
  }
}

.alg-analysis .more_info .title { left: 12px; right: 12px; bottom: 12px; max-width: 420px; border-radius: 10px; border-color: var(--alg-lilac); }
.alg-analysis #combination { margin: 0; }
.alg-analysis #combination button, .alg-analysis #boxWrapper .boxRow button { color: #fff; }
.alg-analysis .boxRow { gap: 8px; margin-top: 8px; }
.alg-analysis .boxRow input { width: 52px; height: 44px; }
.alg-analysis #boxWrapper .boxRow button { width: 44px; height: 44px; }
.alg-analysis :is(#realResult, #combiResult) { overflow-wrap: anywhere; }

.alg-analysis footer { position: static; width: 100%; height: auto; padding: 14px var(--alg-gutter); align-items: center; flex-wrap: wrap; background: var(--alg-plum); color: #eadcf5; }
.alg-analysis footer .terms { font-size: .83rem; }
.alg-analysis footer .add-button { color: #fff; }
.alg-analysis footer .add-button[hidden] { display: none; }
#alg-install-help { flex-basis: 100%; font-size: .9rem; }
#alg-install-help p + p { margin-top: 6px; }

.alg-admin { padding: var(--alg-gutter); }
.alg-admin main { margin: 0 auto; padding: clamp(15px, 4vw, 30px); border: 1px solid var(--alg-line); overflow-wrap: anywhere; }
.alg-admin .alg-brand { padding: 12px; margin-bottom: 20px; border-radius: 12px; background: var(--alg-plum); color: #fff; }
.alg-admin .alg-brand strong { color: #fff; }
.alg-admin .alg-table-scroll { overflow-x: auto; }

.alg-box-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.alg-box-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.alg-box-position { margin-top: 12px; }
.alg-box-position legend { font-weight: 650; }
.alg-analysis .alg-box-position .boxRow { display: flex; flex-wrap: wrap; align-items: center; margin-top: 3px; }
.alg-box-position .boxRow button { min-width: 44px; }
.alg-box-position .boxRow button:disabled { opacity: .55; cursor: default; }
.alg-box-result:not(:empty) { display: block; padding: 12px; margin-top: 14px; border-radius: 9px; background: #f4ecfa; overflow-wrap: anywhere; }
.alg-box-result p { margin-top: 5px; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .alg-header-inner.alg-menu-ready { flex-wrap: nowrap; gap: 10px; }
  .alg-header .alg-brand { flex: 1 1 auto; }
  .alg-header .alg-brand span { min-width: 0; overflow-wrap: anywhere; }
  .alg-header .alg-brand img { width: 44px; height: 44px; }
  .alg-header .alg-menu-ready .alg-menu-toggle {
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid #ffffff55;
    border-radius: 9px;
    background: #422957;
    color: #fff;
    cursor: pointer;
  }
  .alg-header .alg-menu-ready .alg-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: var(--alg-gutter);
    right: var(--alg-gutter);
    z-index: 4;
    padding: 8px;
    border: 1px solid #624675;
    border-radius: 0 0 12px 12px;
    background: var(--alg-plum);
    box-shadow: 0 8px 20px #200e3133;
  }
  .alg-header .alg-menu-open .alg-nav { display: grid; }
  .alg-dashboard { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .alg-box-grid { grid-template-columns: minmax(0, 1fr); }
  .alg-workspace { gap: 14px; }
  .alg-analysis .alg-tool label { max-width: 100%; }
  .alg-analysis #patResult table td, .alg-analysis #speednext table td { letter-spacing: normal; }
  .alg-analysis .alg-hero > div { min-width: 0; max-width: 100%; }
  .alg-analysis .alg-hero .alg-latest { flex-basis: 100%; }
}
