:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --panel: #ffffff;
  --ink: #233033;
  --muted: #617071;
  --line: #d8ded8;
  --line-strong: #bec9c4;
  --teal: #1f6f68;
  --teal-dark: #154f4a;
  --amber: #d99d2b;
  --red: #c85745;
  --green-soft: #e8f5ef;
  --amber-soft: #fbf1dd;
  --shadow: 0 18px 40px rgba(28, 43, 44, 0.08);
  --ad-height: 64px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: calc(var(--ad-height) + env(safe-area-inset-bottom));
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(31, 111, 104, 0.08), rgba(244, 246, 242, 0) 260px),
    var(--bg);
  font-family:
    "Segoe UI",
    "Yu Gothic UI",
    "Meiryo",
    sans-serif;
}

body.is-predicting {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(217, 157, 43, 0.45);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px 18px 34px;
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.site-footer a,
.info-page a {
  color: var(--teal-dark);
  text-underline-offset: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 2.55rem);
  line-height: 1.05;
}

h1 span {
  display: inline;
}

.page-lede {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

h2 {
  margin-bottom: 0;
  font-size: 1.12rem;
  line-height: 1.2;
}

.save-pill,
.estimate-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.82);
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--teal);
}

.main-content {
  display: grid;
  gap: 16px;
}

.result-band {
  display: grid;
  grid-template-columns: minmax(220px, 1.7fr) repeat(3, minmax(130px, 1fr));
  gap: 12px;
  align-items: stretch;
  order: 1;
}

.rank-hero,
.metric-tile,
.tool-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.rank-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  align-items: center;
  min-height: 116px;
  padding: 18px;
  border-color: rgba(31, 111, 104, 0.28);
  background: linear-gradient(135deg, #ffffff, #eaf4ef);
}

.rank-hero span,
.metric-tile span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.rank-hero strong {
  grid-row: 1 / span 2;
  grid-column: 2;
  justify-self: end;
  color: var(--teal-dark);
  font-size: clamp(2.25rem, 7vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.rank-hero small {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.metric-tile {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 116px;
  padding: 16px;
}

.metric-tile strong {
  margin-top: 8px;
  font-size: clamp(1.45rem, 3.4vw, 2.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.workspace-grid,
.insight-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.74fr) minmax(0, 1.26fr);
  gap: 16px;
  align-items: start;
}

.workspace-grid {
  order: 3;
}

.insight-grid {
  grid-template-columns: 1fr;
  order: 2;
}

.tool-panel {
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-heading.compact {
  margin-bottom: 10px;
}

.ghost-button,
.preset-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 800;
}

.ghost-button {
  gap: 8px;
  padding: 0 12px;
}

.ghost-button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
}

.ghost-button:hover,
.preset-button:hover,
.icon-button:hover,
.predict-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field,
.subject-input,
.step-field {
  display: grid;
  gap: 6px;
}

.field span,
.subject-input span,
.step-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.field input,
.subject-input input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #fbfcfb;
  font-weight: 800;
}

.field input:focus,
.subject-input input:focus {
  border-color: var(--teal);
  background: #ffffff;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.preset-button {
  padding: 0 8px;
}

.preset-button.active {
  border-color: var(--teal);
  color: #ffffff;
  background: var(--teal);
}

.advanced-box {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.advanced-box summary {
  color: var(--ink);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 900;
}

.subjects-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

.subjects-summary::-webkit-details-marker {
  display: none;
}

.subjects-summary strong {
  display: block;
  font-size: 1.12rem;
  line-height: 1.2;
}

.subjects-summary svg {
  width: 22px;
  height: 22px;
  transition: transform 180ms ease;
}

.subjects-panel[open] .subjects-summary svg {
  transform: rotate(180deg);
}

.subjects-tools {
  margin-top: 16px;
}

.step-field {
  margin-top: 12px;
}

.step-control {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.step-button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-size: 0.86rem;
  font-weight: 900;
}

.step-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.step-button.active {
  border-color: var(--teal);
  color: #ffffff;
  background: var(--teal);
}

.subjects-panel {
  min-width: 0;
}

.icon-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
}

.subject-header,
.subject-row {
  display: grid;
  grid-template-columns: minmax(112px, 1.2fr) repeat(3, minmax(78px, 0.8fr)) 40px;
  gap: 10px;
  align-items: end;
}

.subject-header {
  margin-bottom: 8px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.subject-list {
  display: grid;
  gap: 8px;
}

.subject-add-footer {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.add-subject-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--teal-dark);
  background: #fbfcfb;
  font-weight: 900;
}

.add-subject-button:hover {
  border-color: var(--teal);
  background: var(--green-soft);
}

.add-subject-button svg {
  width: 20px;
  height: 20px;
}

.subject-row {
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.subject-row .remove-button {
  align-self: center;
  margin-top: 20px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}

.subject-row .remove-button:hover {
  border-color: rgba(200, 87, 69, 0.34);
  color: var(--red);
  background: #fff7f5;
}

.predict-action {
  display: flex;
  justify-content: center;
  order: 4;
}

.predict-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(420px, 100%);
  min-height: 56px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  color: #ffffff;
  background: var(--teal);
  box-shadow: var(--shadow);
  font-size: 1.05rem;
  font-weight: 900;
}

.predict-button:hover {
  color: #ffffff;
  background: var(--teal-dark);
}

.predict-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.predict-button svg {
  width: 20px;
  height: 20px;
}

.chart-panel {
  min-width: 0;
}

#rankChart {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.breakdown-list {
  display: grid;
  gap: 8px;
}

.breakdown-card {
  display: grid;
  grid-template-columns: minmax(84px, 1fr) repeat(3, minmax(64px, auto));
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.breakdown-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  line-height: 1.2;
}

.breakdown-card span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.breakdown-card strong {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
  line-height: 1.1;
  white-space: nowrap;
}

.tone-plus {
  color: var(--teal-dark);
}

.tone-minus {
  color: var(--red);
}

.empty-result {
  min-height: 76px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfb;
  font-weight: 900;
}

.predict-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(244, 246, 242, 0.92);
  backdrop-filter: blur(8px);
}

.predict-overlay[hidden] {
  display: none;
}

.predict-dialog {
  width: min(520px, 100%);
  border: 1px solid rgba(31, 111, 104, 0.28);
  border-radius: 8px;
  padding: 18px;
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 28px 70px rgba(28, 43, 44, 0.2);
}

.loading-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.loading-head h2 {
  font-size: 1.35rem;
}

#loadingCountdown {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  min-width: 92px;
  border-radius: 999px;
  color: var(--teal-dark);
  background: var(--green-soft);
  font-size: 0.9rem;
  font-weight: 900;
  white-space: nowrap;
}

.loading-track {
  width: 100%;
  height: 16px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #eef2ef;
}

.loading-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--amber));
  transition: width 180ms ease-out;
}

.loading-ad {
  display: grid;
  place-items: center;
  min-height: 250px;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(31, 111, 104, 0.08), rgba(217, 157, 43, 0.12)),
    #fbfcfb;
  text-align: center;
}

.ad-placeholder {
  display: grid;
  place-items: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  min-height: inherit;
}

.ad-placeholder-horizontal {
  display: flex;
  min-height: 50px;
}

.ad-placeholder strong {
  font-size: 1.5rem;
  line-height: 1;
}

.ad-placeholder span:last-child {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 900;
}

.ad-slot[data-ad-state="live"] {
  background: #ffffff;
}

.loading-ad .adsbygoogle {
  width: 100%;
  min-height: 250px;
}

.ad-banner {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: calc(var(--ad-height) + env(safe-area-inset-bottom));
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid #c9d0cc;
  color: #344043;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -10px 24px rgba(28, 43, 44, 0.08);
}

.ad-banner .adsbygoogle {
  width: min(970px, 100%);
  min-height: 50px;
}

.ad-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 24px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--amber);
  font-size: 0.76rem;
  font-weight: 900;
}

.ad-banner .ad-placeholder strong {
  font-size: 0.95rem;
}

.ad-banner .ad-placeholder span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.info-page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.info-header {
  margin-bottom: 18px;
}

.info-header a {
  display: inline-block;
  margin-bottom: 14px;
  font-weight: 800;
}

.info-header h1 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
}

.info-content {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.info-content h2 {
  margin: 28px 0 10px;
}

.info-content h3 {
  margin: 22px 0 6px;
  font-size: 1rem;
}

.info-content h2:first-child {
  margin-top: 0;
}

.info-content p {
  margin-bottom: 14px;
  line-height: 1.8;
}

.info-updated {
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.86rem;
}

.info-cta {
  margin-top: 30px;
}

.info-cta a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--teal);
  font-weight: 900;
  text-decoration: none;
}

@media (max-width: 920px) {
  .result-band,
  .workspace-grid,
  .insight-grid {
    grid-template-columns: 1fr;
  }

  .result-band {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .rank-hero {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  :root {
    --ad-height: 58px;
  }

  .app-shell {
    padding: 16px 12px 26px;
  }

  .site-footer {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 span {
    display: block;
  }

  .save-pill {
    min-height: 32px;
    padding-inline: 10px;
    font-size: 0.78rem;
  }

  .result-band,
  .form-grid,
  .preset-row,
  .step-control {
    grid-template-columns: 1fr;
  }

  .metric-tile {
    min-height: 82px;
  }

  .rank-hero {
    min-height: 100px;
    padding: 16px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .subjects-tools {
    display: none;
  }

  .subject-header {
    display: none;
  }

  .subject-row {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 34px;
    gap: 6px;
    align-items: end;
    padding: 8px;
  }

  .subject-row .name-input {
    grid-column: 1 / 4;
    grid-row: 1;
  }

  .subject-row .score-input {
    grid-column: 1;
    grid-row: 2;
  }

  .subject-row .avg-input {
    grid-column: 2;
    grid-row: 2;
  }

  .subject-row .max-input {
    grid-column: 3;
    grid-row: 2;
  }

  .subject-row .remove-button {
    grid-column: 4;
    grid-row: 1;
    width: 34px;
    height: 38px;
    margin-top: 0;
  }

  .subject-input {
    gap: 4px;
  }

  .subject-input input {
    height: 38px;
    padding: 0 8px;
    font-size: 0.95rem;
  }

  .subject-list {
    gap: 6px;
  }

  .breakdown-card {
    grid-template-columns: 1fr 1fr;
  }

  .breakdown-card h3 {
    grid-column: 1 / -1;
  }

  #rankChart {
    height: 220px;
  }

  .predict-dialog {
    padding: 16px;
  }

  .loading-head {
    align-items: flex-start;
  }

  .loading-ad {
    min-height: 220px;
  }

  .loading-ad .adsbygoogle {
    min-height: 220px;
  }

  .info-content {
    padding: 18px;
  }
}

@media (max-width: 390px) {
  .rank-hero {
    grid-template-columns: 1fr;
  }

  .rank-hero strong {
    grid-row: auto;
    grid-column: auto;
    justify-self: start;
  }

  .subject-row {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 32px;
    gap: 5px;
  }
}
