@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&family=Noto+Sans+JP:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #090d19;
  --surface: rgba(18, 24, 42, 0.88);
  --surface-strong: #151d34;
  --surface-soft: rgba(23, 32, 55, 0.7);
  --line: rgba(151, 169, 211, 0.16);
  --line-bright: rgba(151, 169, 211, 0.27);
  --text: #f3f6ff;
  --muted: #94a0bb;
  --muted-bright: #b5bfd5;
  --accent: #8cf0d2;
  --accent-strong: #63dfbd;
  --accent-ink: #09251e;
  --violet: #a19aff;
  --danger: #ff9f9f;
  --radius-lg: 24px;
  --radius-md: 15px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 77% 8%, rgba(115, 105, 255, 0.1), transparent 25rem),
    radial-gradient(circle at 8% 65%, rgba(74, 202, 168, 0.055), transparent 28rem),
    var(--bg);
  font-family: 'Manrope', 'Noto Sans JP', sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

.page-glow {
  position: fixed;
  z-index: -1;
  width: 22rem;
  height: 22rem;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(70px);
  opacity: 0.16;
}

.page-glow--top {
  top: -12rem;
  right: -5rem;
  background: var(--violet);
}

.page-glow--bottom {
  bottom: -16rem;
  left: -5rem;
  background: var(--accent-strong);
}

.app-shell {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 30px 0 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 1px solid rgba(140, 240, 210, 0.35);
  border-radius: 16px;
  color: var(--accent);
  background: linear-gradient(145deg, rgba(140, 240, 210, 0.13), rgba(140, 240, 210, 0.025));
  box-shadow: 0 0 24px rgba(140, 240, 210, 0.07);
  font-family: 'DM Mono', monospace;
  font-size: 17px;
  line-height: 1;
}

.brand-mark span:first-child {
  transform: translate(-7px, 6px);
}

.brand-mark span:last-child {
  transform: translate(7px, -6px);
}

.brand-copy {
  display: grid;
  gap: 2px;
}

.brand-copy strong {
  font-size: 15px;
  letter-spacing: 0.04em;
}

.brand-copy small,
.section-kicker,
.eyebrow {
  color: var(--muted);
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.15em;
}

.brand-copy small {
  font-size: 8px;
  letter-spacing: 0.18em;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted-bright);
  background: rgba(16, 22, 39, 0.55);
  font-size: 11px;
}

.mode-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.hero {
  max-width: 700px;
  padding: 76px 0 42px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 16px;
  color: var(--accent);
}

.hero h1 {
  max-width: 620px;
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 4.25rem);
  font-weight: 700;
  letter-spacing: -0.075em;
  line-height: 1.13;
}

.hero h1 em {
  color: var(--accent);
  font-style: normal;
  text-shadow: 0 0 26px rgba(140, 240, 210, 0.26);
}

.hero-lead {
  max-width: 600px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.9;
}

.content-grid,
.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: 18px;
}

.solver-card,
.answer-card,
.history-card,
.tip-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.16);
}

.solver-card,
.answer-card {
  min-height: 434px;
  padding: 30px;
}

.solver-card {
  position: relative;
  overflow: hidden;
}

.solver-card::after {
  position: absolute;
  right: -85px;
  bottom: -105px;
  width: 240px;
  height: 240px;
  border: 1px solid rgba(140, 240, 210, 0.1);
  border-radius: 50%;
  box-shadow: 0 0 0 24px rgba(140, 240, 210, 0.025), 0 0 0 48px rgba(140, 240, 210, 0.018);
  content: '';
  pointer-events: none;
}

.card-heading,
.answer-card-top,
.history-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.card-heading h2,
.answer-card h2,
.history-card h2,
.tip-card h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.04em;
}

.section-kicker {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 9px;
}

.keyboard-hint {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
  font-size: 10px;
}

.input-label {
  display: block;
  margin: 44px 0 10px;
  color: var(--muted-bright);
  font-size: 12px;
  font-weight: 600;
}

.expression-wrap {
  position: relative;
}

.expression-wrap input {
  width: 100%;
  height: 74px;
  padding: 0 90px 0 19px;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-md);
  outline: none;
  color: var(--text);
  background: rgba(8, 13, 28, 0.58);
  font-family: 'DM Mono', 'Noto Sans JP', monospace;
  font-size: clamp(20px, 3vw, 27px);
  letter-spacing: 0.01em;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.expression-wrap input::placeholder {
  color: #59657f;
}

.expression-wrap input:hover {
  border-color: rgba(151, 169, 211, 0.45);
}

.expression-wrap input:focus {
  border-color: var(--accent);
  background: rgba(8, 18, 31, 0.8);
  box-shadow: 0 0 0 4px rgba(140, 240, 210, 0.09), 0 0 30px rgba(140, 240, 210, 0.08);
}

.expression-wrap input[aria-invalid='true'] {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 159, 159, 0.08);
}

.input-suffix {
  position: absolute;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  color: var(--accent);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  opacity: 0.72;
  pointer-events: none;
}

.input-help {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.help-icon {
  display: inline-grid;
  width: 15px;
  height: 15px;
  place-items: center;
  border: 1px solid rgba(148, 160, 187, 0.6);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 10px;
  font-style: italic;
}

.form-error {
  min-height: 19px;
  margin: 7px 0 0;
  color: var(--danger);
  font-size: 11px;
}

.keypad {
  margin-top: 4px;
  padding: 15px 13px 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(8, 13, 28, 0.3);
}

.keypad-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted-bright);
  font-size: 10px;
  font-weight: 600;
}

.keypad-note {
  color: #65718c;
  font-size: 9px;
  font-weight: 400;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.keypad-key {
  min-height: 44px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted-bright);
  background: rgba(35, 46, 75, 0.52);
  font-family: 'DM Mono', monospace;
  font-size: 16px;
  font-weight: 500;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
}

.keypad-key:hover,
.keypad-key:focus-visible {
  border-color: rgba(140, 240, 210, 0.52);
  color: var(--accent);
  background: rgba(140, 240, 210, 0.1);
  outline: none;
  transform: translateY(-1px);
}

.keypad-key:active {
  transform: translateY(1px);
}

.keypad-key--action {
  color: #aeb8cf;
  background: rgba(102, 115, 149, 0.16);
  font-size: 13px;
  font-weight: 700;
}

.keypad-key[data-action='backspace'] {
  font-size: 28px;
  line-height: 1;
}

.keypad-key--clear {
  border-color: rgba(255, 159, 159, 0.22);
  color: var(--danger);
  background: rgba(255, 159, 159, 0.08);
}

.keypad-key--operator {
  color: var(--violet);
  background: rgba(161, 154, 255, 0.1);
  font-size: 18px;
  font-weight: 600;
}

.keypad-key[data-key='+'],
.keypad-key[data-key='-'],
.keypad-key[data-key='*'],
.keypad-key[data-key='/'] {
  font-size: 24px;
}

.keypad-key--unknown {
  border-color: rgba(140, 240, 210, 0.3);
  color: var(--accent);
  background: rgba(140, 240, 210, 0.09);
  font-size: 18px;
  font-weight: 700;
}

.keypad-key--unknown[data-key='【】'] {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 14px;
}

.keypad-key--equals {
  border-color: rgba(140, 240, 210, 0.28);
  color: var(--accent);
  background: rgba(140, 240, 210, 0.08);
}

.keypad-key--submit {
  grid-column: 1 / -1;
  min-height: 44px;
  border-color: transparent;
  color: var(--accent-ink);
  background: var(--accent);
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 12px;
  font-weight: 800;
}

.keypad-key--submit:hover,
.keypad-key--submit:focus-visible {
  border-color: transparent;
  color: var(--accent-ink);
  background: #a4f6df;
}

.text-button,
.clear-history {
  padding: 7px 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  transition: color 160ms ease;
}

.text-button:hover,
.text-button:focus-visible,
.clear-history:hover,
.clear-history:focus-visible {
  color: var(--text);
  outline: none;
}

.supported-operators {
  position: absolute;
  bottom: 26px;
  left: 30px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #667390;
  font-family: 'DM Mono', monospace;
  font-size: 9px;
}

.supported-operators i {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  padding: 0 3px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted-bright);
  font-style: normal;
  font-size: 10px;
}

.answer-card {
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(150deg, rgba(30, 42, 70, 0.82), rgba(16, 23, 42, 0.93)),
    var(--surface);
}

.answer-status {
  padding: 6px 9px;
  border: 1px solid rgba(148, 160, 187, 0.22);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
}

.answer-status.is-success {
  border-color: rgba(140, 240, 210, 0.29);
  color: var(--accent);
  background: rgba(140, 240, 210, 0.07);
}

.answer-status.is-error {
  border-color: rgba(255, 159, 159, 0.3);
  color: var(--danger);
  background: rgba(255, 159, 159, 0.06);
}

.answer-display {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: auto 0 4px;
  padding-top: 44px;
  font-family: 'DM Mono', monospace;
}

.answer-symbol {
  color: var(--accent);
  font-size: clamp(37px, 5vw, 53px);
  font-weight: 500;
  line-height: 1;
  text-shadow: 0 0 24px rgba(140, 240, 210, 0.24);
}

.answer-equals {
  color: #7d8aa7;
  font-size: 25px;
}

.answer-value {
  color: var(--text);
  font-size: clamp(39px, 5vw, 57px);
  font-weight: 500;
  letter-spacing: -0.07em;
  line-height: 1;
}

.answer-value--fraction {
  font-size: clamp(34px, 4.5vw, 51px);
  letter-spacing: -0.05em;
}

.answer-value--placeholder {
  color: #5d6984;
}

.answer-percent {
  align-self: flex-start;
  margin: 14px 0 0;
  padding: 6px 9px;
  border: 1px solid rgba(140, 240, 210, 0.23);
  border-radius: 7px;
  color: var(--accent);
  background: rgba(140, 240, 210, 0.07);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
}

.answer-note {
  min-height: 23px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.new-expression-button {
  align-self: flex-start;
  margin-top: 12px;
  padding: 7px 10px;
  border: 1px solid rgba(140, 240, 210, 0.25);
  border-radius: 7px;
  color: var(--accent);
  background: rgba(140, 240, 210, 0.06);
  font-size: 10px;
  transition: border-color 160ms ease, background 160ms ease;
}

.new-expression-button:hover,
.new-expression-button:focus-visible {
  border-color: rgba(140, 240, 210, 0.6);
  background: rgba(140, 240, 210, 0.12);
  outline: none;
}

.steps {
  margin-top: 39px;
  padding-top: 19px;
  border-top: 1px solid var(--line);
}

.steps-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted-bright);
  font-size: 11px;
  font-weight: 600;
}

.steps-line {
  height: 1px;
  flex: 1;
  background: var(--line);
}

.steps-list {
  display: grid;
  gap: 11px;
  margin: 17px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps-list li {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 11px;
}

.steps-list li::before {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 7px;
  color: var(--accent);
  background: rgba(140, 240, 210, 0.09);
  content: counter(step);
  counter-increment: step;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
}

.step-label {
  display: block;
  margin-bottom: 2px;
  color: #6d7994;
  font-size: 9px;
}

.step-equation {
  color: var(--muted-bright);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
}

.step-equation strong {
  color: var(--text);
  font-weight: 500;
}

.lower-grid {
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  margin-top: 18px;
}

.tip-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 15px;
  min-height: 158px;
  padding: 25px 27px;
  background: rgba(18, 24, 42, 0.68);
}

.tip-icon {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1px solid rgba(161, 154, 255, 0.33);
  border-radius: 10px;
  color: var(--violet);
  background: rgba(161, 154, 255, 0.08);
  font-family: Georgia, serif;
  font-size: 17px;
  font-style: italic;
}

.tip-card p:not(.section-kicker) {
  max-width: 430px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.8;
}

.tip-example {
  display: flex;
  grid-column: 2;
  align-items: center;
  gap: 10px;
  margin-top: -1px;
  color: var(--muted);
  font-size: 10px;
}

.tip-example span {
  color: #6d7994;
}

.tip-example code,
.tip-example strong {
  color: var(--muted-bright);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 400;
}

.tip-example b {
  color: var(--accent);
  font-weight: 400;
}

.tip-example strong {
  color: var(--accent);
}

.history-card {
  min-height: 158px;
  padding: 25px 27px;
  background: rgba(18, 24, 42, 0.68);
}

.clear-history {
  color: #77829d;
  font-size: 10px;
}

.history-list {
  margin-top: 19px;
}

.empty-history {
  margin: 0;
  color: #68748e;
  font-size: 11px;
}

.history-items {
  display: grid;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 0;
  border: 0;
  color: var(--muted-bright);
  background: transparent;
  text-align: left;
}

.history-item:hover .history-expression,
.history-item:focus-visible .history-expression {
  color: var(--accent);
}

.history-expression {
  overflow: hidden;
  color: var(--muted-bright);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 160ms ease;
}

.history-result {
  flex: 0 0 auto;
  color: var(--accent);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
}

.history-item:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 4px;
}

.footer {
  display: flex;
  gap: 9px;
  padding: 36px 0 30px;
  color: #5f6b84;
  font-size: 10px;
}

.footer-separator {
  color: var(--accent);
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 32px, 620px);
  }

  .hero {
    padding-top: 58px;
  }

  .content-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .answer-card {
    order: -1;
  }

  .solver-card,
  .answer-card {
    min-height: auto;
  }

  .solver-card {
    min-height: 430px;
  }

  .answer-card {
    min-height: 350px;
  }

  .answer-display {
    margin-top: 39px;
  }
}

@media (max-width: 480px) {
  .app-shell {
    width: min(100% - 24px, 620px);
  }

  .topbar {
    padding-top: 20px;
  }

  .mode-pill {
    padding: 7px 8px;
    font-size: 10px;
  }

  .hero {
    padding: 49px 0 30px;
  }

  .hero h1 {
    font-size: 2.25rem;
  }

  .hero-lead {
    font-size: 12px;
  }

  .solver-card,
  .answer-card {
    padding: 22px 20px;
  }

  .input-label {
    margin-top: 34px;
  }

  .expression-wrap input {
    height: 64px;
    padding-left: 14px;
    font-size: 20px;
  }

  .input-suffix {
    right: 13px;
    font-size: 11px;
  }

  .keypad-key {
    min-height: 48px;
  }

  .supported-operators {
    bottom: 22px;
    left: 20px;
  }

  .tip-card,
  .history-card {
    padding: 21px 20px;
  }

  .tip-example {
    flex-wrap: wrap;
    gap: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

