:root {
  --orange: #ff951b;
  --orange-light: #ffb13b;
  --ink: #111217;
  --white: #f4f4f0;
  --panel: #d7d7d7;
  --panel-dark: #bdbdbd;
  --line: #08090d;
  --gold: #ffd328;
  --blue: #5bb9ff;
  --green: #75d66f;
  --red: #ff5c4d;
  --shadow: 0 10px 0 rgba(0, 0, 0, 0.18);
  --font: Arial, Helvetica, sans-serif;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #05060a;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.game {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 28%);
  width: min(100vw, 177.78vh);
  height: min(100vh, 56.25vw);
  min-width: 320px;
  min-height: 220px;
  overflow: hidden;
  border: 8px solid var(--line);
  border-radius: 12px;
  background: var(--line);
}

.playfield {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background-color: var(--orange);
  background-image:
    linear-gradient(45deg, var(--orange-light) 25%, transparent 25%),
    linear-gradient(-45deg, var(--orange-light) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--orange-light) 75%),
    linear-gradient(-45deg, transparent 75%, var(--orange-light) 75%);
  background-position: 0 0, 0 52px, 52px -52px, -52px 0;
  background-size: 104px 104px;
}

.shop {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100%;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
  padding: 14px 10px 12px;
  border-left: 6px solid var(--line);
  background: var(--panel);
}

.shop-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  overflow-y: scroll;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 8px;
  scrollbar-color: var(--line) #eeeeee;
  scrollbar-gutter: stable;
  scrollbar-width: auto;
  touch-action: pan-y;
}

.shop-list::-webkit-scrollbar {
  width: 14px;
}

.shop-list::-webkit-scrollbar-track {
  border: 3px solid var(--line);
  border-radius: 999px;
  background: #eeeeee;
}

.shop-list::-webkit-scrollbar-thumb {
  border: 3px solid #eeeeee;
  background: var(--line);
  border-radius: 999px;
}

.upgrade {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 6px 8px;
  border: 4px solid var(--line);
  border-radius: 4px;
  background: #c9c9c9;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
}

.upgrade:not(:disabled):active {
  transform: translateY(3px);
}

.upgrade:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  filter: grayscale(0.55);
}

.upgrade-icon svg {
  display: block;
  width: 42px;
  height: 42px;
  fill: #ffbd31;
  stroke: var(--line);
  stroke-width: 2px;
}

.upgrade-copy {
  min-width: 0;
  text-align: left;
  text-transform: uppercase;
  line-height: 1.02;
}

.upgrade-name,
.upgrade-value,
.upgrade-cost,
.upgrade-count,
.shop-footer,
.stat,
.tap-label,
.toast,
.settings-card {
  text-shadow:
    2px 0 #fff,
    -2px 0 #fff,
    0 2px #fff,
    0 -2px #fff,
    2px 2px #fff,
    -2px 2px #fff,
    2px -2px #fff,
    -2px -2px #fff;
}

.upgrade-name {
  display: block;
  overflow: hidden;
  font-size: 0.74rem;
  font-weight: 900;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.upgrade-value,
.upgrade-cost {
  display: block;
  font-size: 0.72rem;
  font-weight: 900;
}

.upgrade-count {
  min-width: 24px;
  font-size: 0.9rem;
  font-weight: 900;
  text-align: right;
}

.shop-footer {
  flex: 0 0 auto;
  padding-top: 4px;
  border-top: 4px solid var(--line);
  font-size: 0.76rem;
  font-weight: 900;
  text-align: center;
}

.top-tools,
.closet {
  position: absolute;
  left: 12px;
  z-index: 6;
  display: grid;
  gap: 8px;
}

.top-tools {
  top: 12px;
}

.closet {
  bottom: 12px;
  grid-template-columns: repeat(2, 44px);
}

.tool-button,
.closet-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 4px solid var(--line);
  border-radius: 5px;
  background: var(--white);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
}

.tool-button svg,
.closet-button svg {
  width: 28px;
  height: 28px;
  fill: var(--blue);
  stroke: var(--line);
  stroke-width: 1px;
}

.trophy-button {
  height: 54px;
  grid-template-rows: 28px auto;
  gap: 0;
}

.trophy-button svg {
  fill: #ffae25;
}

.trophy-button span {
  font-size: 0.58rem;
  font-weight: 900;
}

.closet-button:nth-child(1) svg {
  fill: var(--red);
}

.closet-button:nth-child(2) svg {
  fill: #f2f2f2;
}

.closet-button:nth-child(3) svg {
  fill: #1b1b1b;
}

.closet-button:nth-child(4) svg {
  fill: #ffffff;
}

.hud {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 4;
  display: grid;
  gap: 2px;
  min-width: 230px;
  transform: translateX(-50%);
}

.stat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 24px;
  font-size: 0.88rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.stat svg {
  width: 25px;
  height: 25px;
  fill: #ffbf2f;
  stroke: var(--line);
  stroke-width: 2px;
}

.primary-stat {
  font-size: 1.02rem;
}

.duck-stage {
  position: absolute;
  left: 53%;
  top: 55%;
  z-index: 3;
  width: 260px;
  height: 210px;
  transform: translate(-50%, -50%);
}

.tap-label {
  position: absolute;
  top: 46px;
  left: -104px;
  z-index: 3;
  margin: 0;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
  transform: rotate(-6deg);
  pointer-events: none;
}

.duck-button {
  position: absolute;
  inset: 0;
  width: 260px;
  height: 210px;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 120ms ease;
  touch-action: manipulation;
}

.duck-button:active {
  transform: scale(0.94);
}

.duck-shadow {
  position: absolute;
  left: 58px;
  right: 42px;
  bottom: 30px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
  filter: blur(1px);
}

.duck {
  position: absolute;
  left: 20px;
  top: 18px;
  width: 220px;
  height: 170px;
  pointer-events: none;
}

.duck-body {
  position: absolute;
  left: 28px;
  bottom: 28px;
  width: 132px;
  height: 86px;
  border: 5px solid var(--line);
  border-radius: 58% 48% 46% 54%;
  background: #eeeeec;
}

.duck-head {
  position: absolute;
  right: 36px;
  top: 12px;
  width: 74px;
  height: 74px;
  border: 5px solid var(--line);
  border-radius: 50%;
  background: #eeeeec;
}

.duck-wing {
  position: absolute;
  left: 34px;
  bottom: 51px;
  width: 58px;
  height: 50px;
  border: 5px solid var(--line);
  border-top: 0;
  border-right: 0;
  border-radius: 0 0 0 58px;
  background: #f9f9f8;
}

.duck-tail {
  position: absolute;
  left: 20px;
  bottom: 70px;
  width: 44px;
  height: 44px;
  border: 5px solid var(--line);
  border-right: 0;
  border-bottom: 0;
  border-radius: 40px 0 0 0;
  background: #f8f8f6;
  transform: rotate(-22deg);
}

.duck-eye {
  position: absolute;
  right: 60px;
  top: 37px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #101010;
}

.duck-beak {
  position: absolute;
  right: 5px;
  top: 55px;
  width: 52px;
  height: 24px;
  border: 5px solid var(--line);
  border-radius: 12px 22px 22px 10px;
  background: #f36b20;
  transform: rotate(12deg);
}

.duck-leg {
  position: absolute;
  bottom: 13px;
  width: 28px;
  height: 30px;
  border-left: 5px solid var(--line);
  border-bottom: 5px solid var(--line);
  transform: rotate(20deg);
}

.leg-one {
  left: 76px;
}

.leg-two {
  left: 112px;
}

.float-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.float-text {
  position: absolute;
  font-size: 1rem;
  font-weight: 900;
  color: var(--line);
  text-shadow:
    2px 0 #fff,
    -2px 0 #fff,
    0 2px #fff,
    0 -2px #fff;
  animation: float-up 900ms ease forwards;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(-50%, 10px) scale(0.9);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -70px) scale(1.08);
  }
}

.golden-duck {
  position: absolute;
  z-index: 7;
  width: 70px;
  height: 58px;
  border: 0;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.16));
  animation: bob 850ms ease-in-out infinite alternate;
}

.golden-duck svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: var(--gold);
  stroke: var(--line);
  stroke-width: 2px;
}

@keyframes bob {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-10px);
  }
}

.settings-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 6, 10, 0.58);
}

.settings-panel[hidden] {
  display: none;
}

.settings-card {
  display: grid;
  width: min(360px, 100%);
  gap: 14px;
  padding: 18px;
  border: 5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 900;
}

.settings-card h2,
.settings-card p {
  margin: 0;
}

.settings-card p {
  margin-top: 4px;
  font-size: 0.82rem;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
}

.switch-row input {
  width: 22px;
  height: 22px;
}

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

.settings-actions button {
  min-height: 38px;
  flex: 1;
  border: 4px solid var(--line);
  border-radius: 5px;
  background: var(--white);
  font-weight: 900;
  cursor: pointer;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 25;
  max-width: min(420px, calc(100% - 28px));
  padding: 9px 14px;
  border: 4px solid var(--line);
  border-radius: 999px;
  background: var(--white);
  font-size: 0.88rem;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px), (max-height: 420px) {
  .game {
    border-width: 5px;
    grid-template-columns: minmax(0, 1fr) minmax(178px, 31%);
    border-radius: 8px;
    min-width: 0;
    min-height: 0;
  }

  .playfield {
    background-size: 78px 78px;
    background-position: 0 0, 0 39px, 39px -39px, -39px 0;
  }

  .shop {
    padding: 8px 5px;
    border-left-width: 4px;
  }

  .shop-list {
    gap: 5px;
    padding-right: 4px;
  }

  .shop-list::-webkit-scrollbar {
    width: 10px;
  }

  .upgrade {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    min-height: 45px;
    padding: 4px;
    border-width: 3px;
  }

  .upgrade-icon svg {
    width: 30px;
    height: 30px;
  }

  .upgrade-name,
  .upgrade-value,
  .upgrade-cost {
    font-size: 0.56rem;
  }

  .upgrade-count {
    font-size: 0.68rem;
  }

  .shop-footer {
    font-size: 0.58rem;
    border-top-width: 3px;
  }

  .top-tools {
    top: 7px;
    left: 7px;
    gap: 5px;
  }

  .tool-button,
  .closet-button {
    width: 34px;
    height: 34px;
    border-width: 3px;
    border-radius: 4px;
  }

  .tool-button svg,
  .closet-button svg {
    width: 21px;
    height: 21px;
  }

  .trophy-button {
    height: 42px;
  }

  .trophy-button span {
    font-size: 0.48rem;
  }

  .closet {
    left: 7px;
    bottom: 7px;
    grid-template-columns: repeat(2, 34px);
    gap: 5px;
  }

  .hud {
    top: 6px;
    min-width: 170px;
  }

  .stat {
    gap: 4px;
    min-height: 17px;
    font-size: 0.62rem;
  }

  .primary-stat {
    font-size: 0.72rem;
  }

  .stat svg {
    width: 18px;
    height: 18px;
  }

  .duck-stage {
    left: 54%;
    top: 56%;
    width: 174px;
    height: 138px;
    transform: translate(-50%, -50%);
  }

  .duck-button {
    width: 174px;
    height: 138px;
  }

  .duck {
    left: 12px;
    top: 10px;
    width: 150px;
    height: 118px;
  }

  .duck-shadow {
    left: 34px;
    right: 24px;
    bottom: 16px;
    height: 16px;
  }

  .duck-body {
    left: 18px;
    bottom: 21px;
    width: 92px;
    height: 58px;
    border-width: 4px;
  }

  .duck-head {
    right: 25px;
    top: 10px;
    width: 50px;
    height: 50px;
    border-width: 4px;
  }

  .duck-wing {
    left: 22px;
    bottom: 37px;
    width: 40px;
    height: 34px;
    border-width: 4px;
  }

  .duck-tail {
    left: 13px;
    bottom: 49px;
    width: 30px;
    height: 30px;
    border-width: 4px;
  }

  .duck-eye {
    right: 41px;
    top: 28px;
    width: 7px;
    height: 7px;
  }

  .duck-beak {
    right: 4px;
    top: 40px;
    width: 36px;
    height: 18px;
    border-width: 4px;
  }

  .duck-leg {
    bottom: 12px;
    width: 20px;
    height: 22px;
    border-left-width: 4px;
    border-bottom-width: 4px;
  }

  .leg-one {
    left: 52px;
  }

  .leg-two {
    left: 77px;
  }

  .tap-label {
    top: 28px;
    left: -70px;
    font-size: 0.68rem;
  }

  .golden-duck {
    width: 48px;
    height: 40px;
  }
}

@media (max-width: 480px) and (orientation: portrait) {
  .game {
    grid-template-columns: minmax(0, 1fr) minmax(112px, 33%);
    grid-template-rows: none;
  }

  .shop {
    border-left: 4px solid var(--line);
    border-top: 0;
  }

  .shop-list {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  .hud {
    left: auto;
    right: 8px;
    transform: none;
  }

  .duck-stage {
    left: 56%;
    top: 58%;
  }
}
