* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: #7a5637;
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
}

h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

header button {
  min-width: 40px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

header button:active,
#more[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.2);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 6px 6px;
  min-height: 0;
}

.row {
  --icon: clamp(40px, 8dvh, 72px);
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr) minmax(var(--icon), 1.4fr) repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}

.bear     { --bg: #8b6b5e; --ink: #fff; }
.elk      { --bg: #dcb489; --ink: #3a2616; }
.fox      { --bg: #e08a45; --ink: #3a2616; }
.hawk     { --bg: #86bcd6; --ink: #1f3340; }
.salmon   { --bg: #e0647c; --ink: #fff; }
.pinecone { --bg: #c6d7af; --ink: #24391f; }

.step {
  width: 100%;
  max-width: 56px;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink);
  font: inherit;
  font-size: clamp(0.95rem, 4.2vw, 1.25rem);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s, background 0.08s;
}

.step:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.85);
}

/* The -6..-4 / +4..+6 line under the main buttons, shown by the header's + toggle */
.extra {
  display: none;
}

.expanded .extra {
  display: block;
}

/* Two lines of buttons per row: size them by height so all six rows still fit */
.expanded .step {
  max-width: clamp(30px, 6dvh, 56px);
}

.counter {
  grid-column: 4;
  grid-row: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.expanded .counter {
  grid-row: 1 / span 2;
}

.counter img {
  width: var(--icon);
  height: var(--icon);
  object-fit: contain;
  pointer-events: none;
}

.value {
  font-size: clamp(1.4rem, 4dvh, 2rem);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* Running total of the taps just made, e.g. +3 +3 +1 shows "+7" */
.delta {
  position: absolute;
  top: -2px;
  right: -8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.delta.show {
  opacity: 1;
  transition: none;
}

#history {
  width: calc(100% - 32px);
  max-width: 420px;
  max-height: 80dvh;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #f7f0e4;
  color: #3a2616;
}

#history[open] {
  display: flex;
  flex-direction: column;
}

#history::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(58, 38, 22, 0.2);
}

.history-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.history-head button {
  padding: 6px 14px;
  border: 1px solid rgba(58, 38, 22, 0.5);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

#history-empty {
  margin: 0;
  padding: 20px 14px;
  text-align: center;
}

#history-list {
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

#history-list li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 3ch 5ch auto;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-variant-numeric: tabular-nums;
}

#history-list li + li {
  border-top: 1px solid rgba(58, 38, 22, 0.1);
}

#history-list img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

#history-list .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#history-list .change {
  font-weight: 800;
  text-align: right;
}

#history-list .gain {
  color: #2c6a2f;
}

#history-list .loss {
  color: #a3262f;
}

#history-list .total {
  font-weight: 600;
}

#history-list time {
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0.7;
}
