:root {
  color-scheme: light;
  --screen-w: min(100vw, 430px);
  --bone-size: clamp(58px, calc((var(--screen-w) - 72px) / 4), 76px);
  --gap: clamp(8px, 2.7vw, 13px);
  --ink: #111;
  --display-bg: #e6ffdf;
  --panel-bg: rgba(246, 246, 240, 0.96);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.08)),
    url("assets/background@2x.png") center / cover fixed,
    #1f1b17;
  color: var(--ink);
  font-family: Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
input,
a {
  font: inherit;
}

.app {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.counter {
  width: min(100%, 360px);
  min-height: min(100svh - 36px, 620px);
  display: grid;
  grid-template-rows: auto auto 1fr;
  align-content: center;
  gap: clamp(12px, 3svh, 20px);
  padding: clamp(14px, 3svh, 22px) 16px;
}

.topbar {
  height: 28px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.info-button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: radial-gradient(circle at 34% 28%, #f9fbff 0 12%, #82a3d5 13% 45%, #244c8f 46% 100%);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.8), 0 1px 2px rgba(0, 0, 0, 0.35);
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.45);
}

.display {
  width: 100%;
  min-height: 58px;
  display: block;
  padding: 3px 12px 0;
  overflow: hidden;
  border: 2px inset #d8d8d8;
  border-radius: 7px;
  background: var(--display-bg);
  color: #000;
  font-size: clamp(38px, 13vw, 54px);
  line-height: 1;
  text-align: right;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.22), 0 1px 1px rgba(255, 255, 255, 0.45);
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, var(--bone-size));
  grid-auto-rows: var(--bone-size);
  justify-content: center;
  align-content: end;
  gap: var(--gap);
}

.bone-button {
  position: relative;
  width: var(--bone-size);
  height: var(--bone-size);
  padding: 0;
  border: 0;
  background: transparent;
  color: #000;
  font-weight: 700;
  font-size: clamp(23px, 7.8vw, 33px);
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.33));
}

.bone-button img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.bone-button span {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.bone-button:active {
  transform: translateY(1px) scale(0.975);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.clear-button span {
  color: #000;
}

.settings {
  width: min(90vw, 340px);
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.42);
  border-radius: 8px;
  background: transparent;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}

.settings::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.settings-panel {
  display: grid;
  gap: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel-bg);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 8px 10px 8px 16px;
  background: linear-gradient(#f8f8f8, #cfcfcf);
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}

.settings-header h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.close-button,
.settings-actions button,
.settings-actions a {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid rgba(0, 0, 0, 0.28);
  border-radius: 6px;
  background: linear-gradient(#ffffff, #d9d9d9);
  color: #153d77;
  text-decoration: none;
  font-weight: 700;
}

.setting-row {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.14);
  font-size: 17px;
}

.setting-row input[type="checkbox"] {
  width: 46px;
  height: 28px;
  accent-color: #4274c5;
}

.text-row input {
  width: 74px;
  min-height: 34px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  background: #fff;
  text-align: right;
  padding: 4px 8px;
}

.settings-actions {
  display: flex;
  gap: 10px;
  padding: 14px 16px 8px;
}

.about {
  margin: 0;
  padding: 6px 16px 16px;
  color: #555;
  font-size: 12px;
  line-height: 1.35;
}

@media (orientation: landscape) and (max-height: 520px) {
  .app {
    place-items: start center;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .counter {
    min-height: auto;
    width: min(100%, 620px);
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr auto;
    column-gap: 18px;
    padding: 8px 12px;
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .display {
    align-self: start;
  }

  .grid {
    --bone-size: clamp(42px, 10.5svh, 56px);
    grid-column: 2;
    grid-row: 2 / 4;
  }

}
