*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background: radial-gradient(1100px 480px at 50% -8%, #f8f4ed 0%, #e7e1d6 58%);
  color: #1e1a16;
  font-family: "Malgun Gothic", "Segoe UI", sans-serif;
  line-height: 1.6;
}

a {
  color: inherit;
}

.wrap {
  width: min(680px, calc(100% - 32px));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0 6px;
}

.brand,
.brand a,
a.brand {
  margin: 0;
  color: inherit;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: flex-end;
}

.site-nav a {
  color: #5e564c;
  font-size: 0.95rem;
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: #1e1a16;
  font-weight: 700;
}

.lede {
  margin: 12px 0 16px;
  color: #5e564c;
}

.stage {
  display: block;
}

.calculator,
.tool {
  width: min(100%, 360px);
  margin-inline: auto;
  padding: 18px;
  border-radius: 28px;
  background: #23262b;
  box-shadow: 0 22px 50px rgba(48, 36, 22, 0.16);
}

.screen {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  min-height: 96px;
  margin-bottom: 14px;
  padding: 14px 16px 12px;
  border-radius: 16px;
  background: #1a1d21;
}

.expr,
.value {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  font-variant-numeric: tabular-nums;
}

.expr {
  min-height: 1.3em;
  color: #a8a196;
  font-size: 0.95rem;
}

.value {
  max-width: 100%;
  overflow: hidden;
  color: #f6f3ee;
  font-size: 2.7rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.value[data-length="lg"] {
  font-size: 2.05rem;
}

.value[data-length="xl"] {
  font-size: 1.4rem;
}

.value[data-error="true"] {
  color: #ffb4a2;
}

.history-keys {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.key {
  min-height: 58px;
  border: 0;
  border-radius: 14px;
  background: #f3efe8;
  color: #23262b;
  font: 600 1.2rem/1 "Segoe UI", "Malgun Gothic", sans-serif;
  cursor: pointer;
}

.key-fn {
  background: #3a3f46;
  color: #f6f3ee;
}

.key-history {
  min-height: 44px;
  font-size: 0.98rem;
}

.key:disabled {
  opacity: 0.38;
  cursor: default;
}

.key-op {
  background: #d9cfc3;
}

.key-eq {
  background: #e15a2a;
  color: #fffaf6;
}

.key:focus-visible,
.site-nav a:focus-visible,
.brand:focus-visible,
.site-footer a:focus-visible {
  outline: 2px solid #e15a2a;
  outline-offset: 2px;
}

.ad {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #c4b8a6;
  background: rgba(255, 255, 255, 0.35);
  color: #8a7f72;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
}

.ad-top {
  display: none;
  min-height: 90px;
  margin-bottom: 16px;
}

.ad-side {
  display: none;
  min-height: 250px;
}

.ad-bottom {
  min-height: 100px;
  margin: 16px auto;
}

.guide {
  margin-top: 28px;
}

.guide h2 {
  margin: 28px 0 8px;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
}

.guide p,
.guide li {
  color: #3a342e;
}

.examples {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  padding: 0;
  list-style: none;
}

.example {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid #e0d6c8;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
}

.example strong {
  display: block;
  margin-bottom: 4px;
}

kbd {
  display: inline-block;
  min-width: 1.35em;
  padding: 0 0.35em;
  border: 1px solid #d5cbbd;
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fff;
  font-family: inherit;
  font-size: 0.92em;
  text-align: center;
}

.page h1 {
  margin: 18px 0 8px;
  font-size: 1.8rem;
  letter-spacing: -0.04em;
}

.page h2 {
  margin: 26px 0 8px;
  font-size: 1.1rem;
}

.site-footer {
  padding: 8px 0 36px;
  color: #6d645b;
  font-size: 0.92rem;
}

.site-footer a {
  color: #3a342e;
}

@media (max-width: 720px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .site-nav {
    justify-content: flex-start;
  }
}

.tool-page h1 {
  margin: 12px 0 4px;
  font-size: 1.5rem;
  letter-spacing: -0.04em;
}

.tool {
  padding: 18px;
  border-radius: 28px;
  background: #23262b;
  box-shadow: 0 22px 50px rgba(48, 36, 22, 0.16);
  color: #f6f3ee;
}

.modes {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.modes button {
  flex: 1;
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: #3a3f46;
  color: #f6f3ee;
  font: 600 0.95rem/1 "Malgun Gothic", "Segoe UI", sans-serif;
  cursor: pointer;
}

.modes button[aria-pressed="true"] {
  background: #e15a2a;
  color: #fffaf6;
}

.field {
  margin-bottom: 12px;
}

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

.field-label {
  display: block;
  margin-bottom: 6px;
  color: #a8a196;
  font-size: 0.85rem;
}

.period-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field label,
.check {
  display: block;
  margin-bottom: 6px;
  color: #a8a196;
  font-size: 0.85rem;
}

.field input,
.person input {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: #1a1d21;
  color: #f6f3ee;
  font: 600 1.05rem/1.2 "Segoe UI", "Malgun Gothic", sans-serif;
}

.field input:focus-visible,
.person input:focus-visible,
.modes button:focus-visible,
.text-btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid #e15a2a;
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  color: #f6f3ee;
}

.check input {
  width: 1rem;
  height: 1rem;
  accent-color: #e15a2a;
}

.person {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) 42px;
  gap: 8px;
  margin-bottom: 8px;
}

.icon-btn,
.text-btn {
  border: 0;
  border-radius: 12px;
  background: #3a3f46;
  color: #f6f3ee;
  font: 600 0.95rem/1 "Malgun Gothic", "Segoe UI", sans-serif;
  cursor: pointer;
}

.icon-btn {
  min-height: 44px;
}

.icon-btn:disabled,
.text-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.text-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
}

.result {
  margin-top: 14px;
  padding: 14px 16px 12px;
  border-radius: 16px;
  background: #1a1d21;
}

.result-label {
  margin: 0;
  color: #a8a196;
  font-size: 0.9rem;
  text-align: right;
}

.result-value {
  margin: 2px 0 0;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  text-align: right;
  overflow-wrap: anywhere;
}

.result-value.is-error {
  color: #ffb4a2;
  font-size: 1.15rem;
}

.breakdown {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.breakdown li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid #2e3238;
  color: #d9d3c8;
  font-size: 0.92rem;
}

.breakdown strong {
  color: #f6f3ee;
  font-weight: 600;
}

.guide a {
  color: #9a4318;
}

@media (hover: hover) {
  .key:hover:not(:disabled) {
    filter: brightness(1.05);
  }

  .site-nav a:hover,
  .site-footer a:hover {
    color: #1e1a16;
  }
}

.key:active:not(:disabled),
.key.is-pressed {
  transform: translateY(1px);
}

@media (prefers-reduced-motion: reduce) {
  .key:active,
  .key.is-pressed {
    transform: none;
  }
}

@media (min-width: 960px) {
  .ad-top,
  .ad-side {
    display: flex;
  }

  .ad-bottom {
    display: none;
  }

  .stage {
    display: grid;
    grid-template-columns: 360px 300px;
    gap: 20px;
    align-items: start;
    justify-content: center;
  }

  .calculator,
  .tool {
    margin: 0;
  }

  .ad-side {
    position: sticky;
    top: 20px;
  }

  .examples {
    grid-template-columns: repeat(3, 1fr);
  }
}
