/*
 * ==========================================================
 * Util
 * ==========================================================
 */

:root {
  --bg-color: #0e1621;
  --alt-color: #17212b;
  --fore-color: #182533;
  --accent-color: #2b5278;
  --text-color: #ffffff;
}

.no-select {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/*
 * ==========================================================
 * Base
 * ==========================================================
 */

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  position: fixed;
  touch-action: none;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-color);
  color: var(--text-color);
}

#fps {
  display: inline;
}

#canvas {
  width: 960px;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 3 / 2;
}

#controls {
  height: 100%;
  display: none;
  grid-template-rows: auto 1fr auto;
}

@media (pointer: coarse) {
  #controls {
    display: grid;
  }
}

#lr,
#select-start {
  display: flex;
  justify-content: space-evenly;
  gap: 9px;
  margin: 9px;
}

#lr > div,
#select-start > div {
  width: 100%;
  height: 50px;
  border: 1px solid var(--accent-color);
}

#lr,
#select-start {
  text-align: center;
  text-transform: uppercase;
  line-height: 50px;
  color: var(--accent-color);
}

#ab {
  text-align: center;
  text-transform: uppercase;
  color: var(--accent-color);
}

#main-controls {
  container-type: size;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 9px;
  min-height: 0;
}

#dpad {
  --dpad-size: min(50cqi, 300px, 100cqb);
  width: var(--dpad-size);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

#dpad > #up,
#dpad > #left,
#dpad > #right,
#dpad > #down {
  border: 1px solid var(--accent-color);
}

#dpad > #upleft {
  grid-area: 1 / 1;
}

#dpad > #up {
  grid-area: 1 / 2;
  border-bottom: none;
}

#dpad > #upright {
  grid-area: 1 / 3;
}

#dpad > #left {
  grid-area: 2 / 1;
  border-right: none;
}

#dpad > #right {
  grid-area: 2 / 3;
  border-left: none;
}

#dpad > #downleft {
  grid-area: 3 / 1;
}

#dpad > #down {
  grid-area: 3 / 2;
  border-top: none;
}

#dpad > #downright {
  grid-area: 3 / 3;
}

#ab {
  --btn-size: min(calc(50cqi / 3), 100px, calc(100cqb / 3));
  width: calc(var(--btn-size) * 2.4);
  height: min(50cqi, 300px, 100cqb);
  position: relative;
}

#a,
#b {
  width: var(--btn-size);
  height: var(--btn-size);
  border-radius: 50%;
  border: 1px solid var(--accent-color);
  position: absolute;
  line-height: var(--btn-size);
}

#a {
  top: 22%;
  left: 50%;
}

#b {
  top: 44%;
  left: 0%;
}

#log {
  position: absolute;
  height: 250px;
  width: 100vw;
  top: 21px;
  left: 0;
  overflow: scroll;
  line-height: 0;
  color: black;
  background-color: rgba(255, 255, 255, 0.5);
}

.button {
  background-color: var(--alt-color);
  color: var(--text-color);
  border: 1px solid var(--accent-color);
  padding: 4px 10px;
  cursor: pointer;
}

.button:hover {
  background-color: var(--accent-color);
}

.segmented {
  display: inline-flex;
}

.seg-btn {
  background-color: var(--alt-color);
  color: var(--text-color);
  border: 1px solid var(--accent-color);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.seg-btn:not(:first-child) {
  border-left: none;
}

.seg-btn:first-child {
  border-radius: 4px 0 0 4px;
}

.seg-btn:last-child {
  border-radius: 0 4px 4px 0;
}

.seg-btn:hover {
  background-color: var(--accent-color);
}

.seg-btn.active {
  background-color: var(--accent-color);
}

.seg-vol-input {
  width: 40px;
  text-align: center;
  background-color: var(--alt-color);
  color: var(--text-color);
  border: 1px solid var(--accent-color);
  border-left: none;
  border-right: none;
  padding: 4px 2px;
  font-size: 14px;
  line-height: 1;
  -moz-appearance: textfield;
  appearance: textfield;
}

#external {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background-color: var(--alt-color);
}

#menu-container {
  position: relative;
}

#menu-btn {
  font-size: 18px;
  line-height: 1;
  padding: 2px 8px;
}

#menu-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  background-color: var(--alt-color);
  border: 1px solid var(--accent-color);
  min-width: 140px;
  margin-top: 2px;
}

.menu-item {
  display: block;
  width: 100%;
  background: none;
  color: var(--text-color);
  border: none;
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}

.menu-item:hover {
  background-color: var(--accent-color);
}

.menu-sep {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin: 4px 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  position: relative;
  background-color: var(--fore-color);
  border: 1px solid var(--accent-color);
  padding: 16px 20px;
  min-width: 280px;
  max-width: 90vw;
}

.modal h3 {
  margin: 0 0 12px;
}

.modal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.modal-row span:first-child {
  min-width: 100px;
}

.modal-row span:nth-child(2) {
  flex: 1;
  opacity: 0.7;
  font-size: 13px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.recent-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--accent-color);
  cursor: pointer;
}

.recent-entry:hover {
  background-color: var(--accent-color);
}

.recent-entry-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

.recent-delete {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  opacity: 0.5;
  font-size: 16px;
  padding: 2px 6px;
}

.recent-delete:hover {
  opacity: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

#storage-info {
  opacity: 0.5;
  font-size: 12px;
}

#recent-list:empty::after {
  content: "No recent ROMs";
  display: block;
  opacity: 0.5;
  padding: 12px 0;
}

#update-btn {
  background: linear-gradient(135deg, #2980d9, #1a6bbf);
  color: #fff;
  border: 1px solid #3a9aef;
  padding: 4px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: 0 0 8px rgba(41, 128, 217, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: update-glow 2s ease-in-out infinite;
}

#update-btn:hover {
  background: linear-gradient(135deg, #3a9aef, #2980d9);
  box-shadow: 0 0 14px rgba(41, 128, 217, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

@keyframes update-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(41, 128, 217, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
  50% { box-shadow: 0 0 16px rgba(41, 128, 217, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 20px;
  cursor: pointer;
  opacity: 0.6;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  opacity: 1;
}

.button-primary {
  background-color: #2980d9;
  border-color: #3a9aef;
}

.button-primary:hover {
  background-color: #3a9aef;
}

.kb-select {
  background-color: var(--alt-color);
  color: var(--text-color);
  border: 1px solid var(--accent-color);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
}

.kb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.kb-row span {
  min-width: 60px;
  font-size: 14px;
}

.kb-btn {
  min-width: 80px;
  text-align: center;
  background-color: var(--alt-color);
  color: var(--text-color);
  border: 1px solid var(--accent-color);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
}

.kb-btn:hover {
  background-color: var(--accent-color);
}

.kb-btn.active {
  background-color: var(--accent-color);
}

#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(14, 22, 33, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text-color);
  border: 3px dashed var(--accent-color);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

#drop-overlay.visible {
  opacity: 1;
}
